Skip to content

Commit

Permalink
创建feedcai动画
Browse files Browse the repository at this point in the history
  • Loading branch information
Shuaige1234567 committed Dec 13, 2023
1 parent d2338ff commit 2e84c95
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions frontend/src/utils/useAuth.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import {createContext, useContext, useEffect, useState} from "react";
import React, {createContext, useContext, useEffect, useState} from "react";
import {authClient, IIForIdentity} from "./IIForIdentity";
import {DelegationIdentity} from "@dfinity/identity";
import {Principal} from "@dfinity/principal";
import {rootFeedApi} from "../actors/rootFeed";
import {notification} from "antd";
import {NotificationInstance} from "antd/es/notification/interface";
import {CheckOutlined, CloseOutlined, LoadingOutlined} from "@ant-design/icons";

export interface Props {
readonly identity: DelegationIdentity | undefined;
Expand All @@ -14,7 +17,7 @@ export interface Props {
readonly isAuth: boolean;
}

export const useProvideAuth = (authClient: IIForIdentity): Props => {
export const useProvideAuth = (api: NotificationInstance, authClient: IIForIdentity): Props => {
const [_identity, _setIdentity] = useState<DelegationIdentity | undefined>(undefined);
const [isAuthClientReady, setAuthClientReady] = useState(false);
const [principal, setPrincipal] = useState<Principal | undefined>(undefined);
Expand Down Expand Up @@ -44,7 +47,29 @@ export const useProvideAuth = (authClient: IIForIdentity): Props => {
const e = await rootFeedApi.getUserFeedCanister(principal)
let cai = e
if (!e) {
cai = await rootFeedApi.createFeedCanister()
api.info({
message: 'Creating Feed Canister ...',
key: 'createFeed',
duration: null,
description: '',
icon: <LoadingOutlined/>
})
try {
cai = await rootFeedApi.createFeedCanister()
api.success({
message: 'Create Successful !',
key: 'createFeed',
description: '',
icon: <CheckOutlined/>
});
} catch (e) {
api.error({
message: 'Create Failed !',
key: 'createFeed',
description: '',
icon: <CloseOutlined/>
})
}
}
setUserFeedCai(cai)
}
Expand Down Expand Up @@ -101,9 +126,11 @@ const props: Props = {
const authContext = createContext(props);

export function ProvideAuth({children}: any) {
const auth = useProvideAuth(authClient);
const [api, contextHolder] = notification.useNotification();
const auth = useProvideAuth(api, authClient);
return (
<authContext.Provider value={Object.assign(auth)}>
{contextHolder}
{children}
</authContext.Provider>
);
Expand Down

0 comments on commit 2e84c95

Please sign in to comment.