From 2e84c95ef4213bb8fd9d2047c0e370b688b9372a Mon Sep 17 00:00:00 2001 From: Shuaige1234567 Date: Wed, 13 Dec 2023 20:06:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BAfeedcai=E5=8A=A8=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/utils/useAuth.tsx | 35 ++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/frontend/src/utils/useAuth.tsx b/frontend/src/utils/useAuth.tsx index 651532a..ae78b27 100644 --- a/frontend/src/utils/useAuth.tsx +++ b/frontend/src/utils/useAuth.tsx @@ -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; @@ -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(undefined); const [isAuthClientReady, setAuthClientReady] = useState(false); const [principal, setPrincipal] = useState(undefined); @@ -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: + }) + try { + cai = await rootFeedApi.createFeedCanister() + api.success({ + message: 'Create Successful !', + key: 'createFeed', + description: '', + icon: + }); + } catch (e) { + api.error({ + message: 'Create Failed !', + key: 'createFeed', + description: '', + icon: + }) + } } setUserFeedCai(cai) } @@ -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 ( + {contextHolder} {children} );