mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
fix: logout status error
This commit is contained in:
@@ -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 (
|
||||
<Modal open={open} onClose={onClose} data-testid="logout-modal">
|
||||
@@ -24,7 +26,11 @@ export const LogoutModal = ({ open, onClose }: LoginModalProps) => {
|
||||
</Header>
|
||||
<Content>
|
||||
<ContentTitle>{t('Sign out')}?</ContentTitle>
|
||||
<SignDes>{t('Set up an AFFiNE account to sync data')}</SignDes>
|
||||
<SignDes>
|
||||
{blobDataSynced
|
||||
? t('Set up an AFFiNE account to sync data')
|
||||
: 'All data has been stored in the cloud'}
|
||||
</SignDes>
|
||||
<StyleTips>
|
||||
{localCache ? (
|
||||
<StyleCheck
|
||||
|
||||
@@ -10,12 +10,16 @@ import {
|
||||
import { createDefaultWorkspace } from './utils';
|
||||
import { User } from '@affine/datacenter';
|
||||
|
||||
export interface Disposable {
|
||||
dispose(): void;
|
||||
}
|
||||
|
||||
type AppStateContextProps = PropsWithChildren<Record<string, unknown>>;
|
||||
|
||||
export const AppState = createContext<AppStateContext>({} as AppStateContext);
|
||||
|
||||
export const useAppState = () => useContext(AppState);
|
||||
|
||||
let syncChangeDisposable: Disposable | undefined = undefined;
|
||||
export const AppStateProvider = ({
|
||||
children,
|
||||
}: PropsWithChildren<AppStateContextProps>) => {
|
||||
@@ -92,6 +96,7 @@ export const AppStateProvider = ({
|
||||
|
||||
const loadWorkspace = useRef<AppStateFunction['loadWorkspace']>();
|
||||
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;
|
||||
|
||||
@@ -24,6 +24,7 @@ export type AppStateValue = {
|
||||
editor?: EditorContainer | null;
|
||||
synced: boolean;
|
||||
isOwner?: boolean;
|
||||
blobDataSynced?: boolean;
|
||||
};
|
||||
|
||||
export type AppStateFunction = {
|
||||
|
||||
Reference in New Issue
Block a user