fix: cleanup data when logout (#1443)

This commit is contained in:
Himself65 2023-03-09 00:38:16 -06:00 committed by GitHub
parent a7a8ac0882
commit ce8539b414
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 3 deletions

View File

@ -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(

View File

@ -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>;

View File

@ -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])}