mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-16 05:47:09 +08: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 { Check, UnCheck } from './icon';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useTranslation } from '@affine/i18n';
|
import { useTranslation } from '@affine/i18n';
|
||||||
|
import { useAppState } from '@/providers/app-state-provider';
|
||||||
interface LoginModalProps {
|
interface LoginModalProps {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
onClose: (wait: boolean) => void;
|
onClose: (wait: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const LogoutModal = ({ open, onClose }: LoginModalProps) => {
|
export const LogoutModal = ({ open, onClose }: LoginModalProps) => {
|
||||||
const [localCache, setLocalCache] = useState(false);
|
const [localCache, setLocalCache] = useState(true);
|
||||||
|
const { blobDataSynced } = useAppState();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
return (
|
return (
|
||||||
<Modal open={open} onClose={onClose} data-testid="logout-modal">
|
<Modal open={open} onClose={onClose} data-testid="logout-modal">
|
||||||
@@ -24,7 +26,11 @@ export const LogoutModal = ({ open, onClose }: LoginModalProps) => {
|
|||||||
</Header>
|
</Header>
|
||||||
<Content>
|
<Content>
|
||||||
<ContentTitle>{t('Sign out')}?</ContentTitle>
|
<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>
|
<StyleTips>
|
||||||
{localCache ? (
|
{localCache ? (
|
||||||
<StyleCheck
|
<StyleCheck
|
||||||
|
|||||||
@@ -10,12 +10,16 @@ import {
|
|||||||
import { createDefaultWorkspace } from './utils';
|
import { createDefaultWorkspace } from './utils';
|
||||||
import { User } from '@affine/datacenter';
|
import { User } from '@affine/datacenter';
|
||||||
|
|
||||||
|
export interface Disposable {
|
||||||
|
dispose(): void;
|
||||||
|
}
|
||||||
|
|
||||||
type AppStateContextProps = PropsWithChildren<Record<string, unknown>>;
|
type AppStateContextProps = PropsWithChildren<Record<string, unknown>>;
|
||||||
|
|
||||||
export const AppState = createContext<AppStateContext>({} as AppStateContext);
|
export const AppState = createContext<AppStateContext>({} as AppStateContext);
|
||||||
|
|
||||||
export const useAppState = () => useContext(AppState);
|
export const useAppState = () => useContext(AppState);
|
||||||
|
let syncChangeDisposable: Disposable | undefined = undefined;
|
||||||
export const AppStateProvider = ({
|
export const AppStateProvider = ({
|
||||||
children,
|
children,
|
||||||
}: PropsWithChildren<AppStateContextProps>) => {
|
}: PropsWithChildren<AppStateContextProps>) => {
|
||||||
@@ -92,6 +96,7 @@ export const AppStateProvider = ({
|
|||||||
|
|
||||||
const loadWorkspace = useRef<AppStateFunction['loadWorkspace']>();
|
const loadWorkspace = useRef<AppStateFunction['loadWorkspace']>();
|
||||||
loadWorkspace.current = async (workspaceId: string) => {
|
loadWorkspace.current = async (workspaceId: string) => {
|
||||||
|
syncChangeDisposable && syncChangeDisposable.dispose();
|
||||||
const { dataCenter, workspaceList, currentWorkspace, user } = appState;
|
const { dataCenter, workspaceList, currentWorkspace, user } = appState;
|
||||||
if (!workspaceList.find(v => v.id.toString() === workspaceId)) {
|
if (!workspaceList.find(v => v.id.toString() === workspaceId)) {
|
||||||
return null;
|
return null;
|
||||||
@@ -108,6 +113,13 @@ export const AppStateProvider = ({
|
|||||||
// We must ensure workspace.owner exists, then ensure id same.
|
// We must ensure workspace.owner exists, then ensure id same.
|
||||||
isOwner = workspace?.owner && user?.id === workspace.owner.id;
|
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 =
|
const pageList =
|
||||||
(workspace?.blocksuiteWorkspace?.meta.pageMetas as PageMeta[]) ?? [];
|
(workspace?.blocksuiteWorkspace?.meta.pageMetas as PageMeta[]) ?? [];
|
||||||
setAppState({
|
setAppState({
|
||||||
@@ -117,6 +129,7 @@ export const AppStateProvider = ({
|
|||||||
currentPage: null,
|
currentPage: null,
|
||||||
editor: null,
|
editor: null,
|
||||||
isOwner,
|
isOwner,
|
||||||
|
blobDataSynced: blobStorage?.uploading,
|
||||||
});
|
});
|
||||||
|
|
||||||
return workspace;
|
return workspace;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ export type AppStateValue = {
|
|||||||
editor?: EditorContainer | null;
|
editor?: EditorContainer | null;
|
||||||
synced: boolean;
|
synced: boolean;
|
||||||
isOwner?: boolean;
|
isOwner?: boolean;
|
||||||
|
blobDataSynced?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AppStateFunction = {
|
export type AppStateFunction = {
|
||||||
|
|||||||
Reference in New Issue
Block a user