From ab059fcb2be4050a657e43d88bb09c503e1d9904 Mon Sep 17 00:00:00 2001 From: DiamondThree <857159145@qq.com> Date: Tue, 7 Feb 2023 16:45:16 +0800 Subject: [PATCH] fix: logout status error --- .../app/src/components/logout-modal/index.tsx | 10 ++++++++-- .../src/providers/app-state-provider/Provider.tsx | 15 ++++++++++++++- .../src/providers/app-state-provider/interface.ts | 1 + 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/packages/app/src/components/logout-modal/index.tsx b/packages/app/src/components/logout-modal/index.tsx index b317f1183..19b6b04d9 100644 --- a/packages/app/src/components/logout-modal/index.tsx +++ b/packages/app/src/components/logout-modal/index.tsx @@ -4,13 +4,15 @@ import { Button } from '@/ui/button'; import { Check, UnCheck } from './icon'; import { useState } from 'react'; import { useTranslation } from '@affine/i18n'; +import { useAppState } from '@/providers/app-state-provider'; interface LoginModalProps { open: boolean; onClose: (wait: boolean) => void; } export const LogoutModal = ({ open, onClose }: LoginModalProps) => { - const [localCache, setLocalCache] = useState(false); + const [localCache, setLocalCache] = useState(true); + const { blobDataSynced } = useAppState(); const { t } = useTranslation(); return ( @@ -24,7 +26,11 @@ export const LogoutModal = ({ open, onClose }: LoginModalProps) => { {t('Sign out')}? - {t('Set up an AFFiNE account to sync data')} + + {blobDataSynced + ? t('Set up an AFFiNE account to sync data') + : 'All data has been stored in the cloud'} + {localCache ? ( >; export const AppState = createContext({} as AppStateContext); export const useAppState = () => useContext(AppState); - +let syncChangeDisposable: Disposable | undefined = undefined; export const AppStateProvider = ({ children, }: PropsWithChildren) => { @@ -92,6 +96,7 @@ export const AppStateProvider = ({ const loadWorkspace = useRef(); loadWorkspace.current = async (workspaceId: string) => { + syncChangeDisposable && syncChangeDisposable.dispose(); const { dataCenter, workspaceList, currentWorkspace, user } = appState; if (!workspaceList.find(v => v.id.toString() === workspaceId)) { return null; @@ -108,6 +113,13 @@ export const AppStateProvider = ({ // We must ensure workspace.owner exists, then ensure id same. isOwner = workspace?.owner && user?.id === workspace.owner.id; } + const blobStorage = await workspace?.blocksuiteWorkspace?.blobs; + syncChangeDisposable = blobStorage?.signals.onBlobSyncStateChange.on(() => { + setAppState({ + ...appState, + synced: blobStorage?.uploading, + }); + }); const pageList = (workspace?.blocksuiteWorkspace?.meta.pageMetas as PageMeta[]) ?? []; setAppState({ @@ -117,6 +129,7 @@ export const AppStateProvider = ({ currentPage: null, editor: null, isOwner, + blobDataSynced: blobStorage?.uploading, }); return workspace; diff --git a/packages/app/src/providers/app-state-provider/interface.ts b/packages/app/src/providers/app-state-provider/interface.ts index c76b2993c..356795e96 100644 --- a/packages/app/src/providers/app-state-provider/interface.ts +++ b/packages/app/src/providers/app-state-provider/interface.ts @@ -24,6 +24,7 @@ export type AppStateValue = { editor?: EditorContainer | null; synced: boolean; isOwner?: boolean; + blobDataSynced?: boolean; }; export type AppStateFunction = {