mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-27 18:32:29 +03:00
fix: cleanup data when logout (#1443)
This commit is contained in:
parent
a7a8ac0882
commit
ce8539b414
@ -59,6 +59,9 @@ const getPersistenceAllWorkspace = () => {
|
||||
export const AffinePlugin: WorkspacePlugin<RemWorkspaceFlavour.AFFINE> = {
|
||||
flavour: RemWorkspaceFlavour.AFFINE,
|
||||
loadPriority: LoadPriority.HIGH,
|
||||
cleanup: () => {
|
||||
storage.removeItem(kAffineLocal);
|
||||
},
|
||||
CRUD: {
|
||||
create: async blockSuiteWorkspace => {
|
||||
const binary = BlockSuiteWorkspace.Y.encodeStateAsUpdate(
|
||||
|
@ -48,6 +48,8 @@ export interface WorkspacePlugin<Flavour extends RemWorkspaceFlavour> {
|
||||
flavour: Flavour;
|
||||
// Plugin will be loaded according to the priority
|
||||
loadPriority: LoadPriority;
|
||||
// fixme: this is a hack
|
||||
cleanup?: () => void;
|
||||
// Fetch necessary data for the first render
|
||||
CRUD: {
|
||||
create: (blockSuiteWorkspace: BlockSuiteWorkspace) => Promise<string>;
|
||||
|
@ -1,10 +1,11 @@
|
||||
import { useAtom, useAtomValue } from 'jotai';
|
||||
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
|
||||
import dynamic from 'next/dynamic';
|
||||
import { useRouter } from 'next/router';
|
||||
import React, { useCallback } from 'react';
|
||||
|
||||
import {
|
||||
currentWorkspaceIdAtom,
|
||||
jotaiWorkspacesAtom,
|
||||
openCreateWorkspaceModalAtom,
|
||||
openWorkspacesModalAtom,
|
||||
} from '../atoms';
|
||||
@ -12,7 +13,8 @@ import { useCurrentUser } from '../hooks/current/use-current-user';
|
||||
import { useCurrentWorkspace } from '../hooks/current/use-current-workspace';
|
||||
import { useRouterHelper } from '../hooks/use-router-helper';
|
||||
import { useWorkspaces, useWorkspacesHelper } from '../hooks/use-workspaces';
|
||||
import { WorkspaceSubPath } from '../shared';
|
||||
import { WorkspacePlugins } from '../plugins';
|
||||
import { RemWorkspaceFlavour, WorkspaceSubPath } from '../shared';
|
||||
import { apis } from '../shared/apis';
|
||||
|
||||
const WorkspaceListModal = dynamic(
|
||||
@ -40,6 +42,7 @@ export function Modals() {
|
||||
const currentWorkspaceId = useAtomValue(currentWorkspaceIdAtom);
|
||||
const [, setCurrentWorkspace] = useCurrentWorkspace();
|
||||
const { createLocalWorkspace } = useWorkspacesHelper();
|
||||
const set = useSetAtom(jotaiWorkspacesAtom);
|
||||
|
||||
return (
|
||||
<>
|
||||
@ -66,8 +69,14 @@ export function Modals() {
|
||||
}, [router])}
|
||||
onClickLogout={useCallback(() => {
|
||||
apis.auth.clear();
|
||||
set(workspaces =>
|
||||
workspaces.filter(
|
||||
workspace => workspace.flavour !== RemWorkspaceFlavour.AFFINE
|
||||
)
|
||||
);
|
||||
WorkspacePlugins[RemWorkspaceFlavour.AFFINE].cleanup?.();
|
||||
router.reload();
|
||||
}, [router])}
|
||||
}, [router, set])}
|
||||
onCreateWorkspace={useCallback(() => {
|
||||
setOpenCreateWorkspaceModal(true);
|
||||
}, [setOpenCreateWorkspaceModal])}
|
||||
|
Loading…
Reference in New Issue
Block a user