mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-23 13:29:02 +08:00
feat: fix load
This commit is contained in:
@@ -34,9 +34,7 @@ export const GeneralPage = ({
|
||||
const [showDelete, setShowDelete] = useState<boolean>(false);
|
||||
const [workspaceName, setWorkspaceName] = useState<string>(
|
||||
workspaces[workspace.id]?.meta.name ||
|
||||
(workspace.type === WorkspaceType.Private && user
|
||||
? user.name
|
||||
: `workspace-${workspace?.id}`)
|
||||
(workspace.type === WorkspaceType.Private && user ? user.name : '')
|
||||
);
|
||||
const debouncedRefreshWorkspacesMeta = debounce(() => {
|
||||
refreshWorkspacesMeta();
|
||||
|
||||
+2
-1
@@ -81,7 +81,8 @@ export const SelectorPopperContent = ({
|
||||
refreshWorkspacesMeta();
|
||||
refreshDetails();
|
||||
}
|
||||
}, [isShow, refreshDetails, refreshWorkspacesMeta]);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [isShow]);
|
||||
|
||||
return !user ? (
|
||||
<SelectorPopperContainer placement="bottom-start">
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ export const WorkspaceSelector = () => {
|
||||
{currentWorkspace?.meta.name ||
|
||||
(workspaceMeta?.type === WorkspaceType.Private && user
|
||||
? user.name
|
||||
: `workspace-${workspaceMeta?.id}`)}
|
||||
: 'AFFINE')}
|
||||
</WorkspaceName>
|
||||
</SelectorWrapper>
|
||||
</Popper>
|
||||
|
||||
@@ -8,7 +8,8 @@ import type {
|
||||
import type { EditorContainer } from '@blocksuite/editor';
|
||||
export type LoadWorkspaceHandler = (
|
||||
workspaceId: string,
|
||||
websocket?: boolean
|
||||
websocket?: boolean,
|
||||
user?: AccessTokenMessage | null
|
||||
) => Promise<StoreWorkspace | null> | null;
|
||||
export type CreateEditorHandler = (page: StorePage) => EditorContainer | null;
|
||||
|
||||
|
||||
@@ -27,7 +27,8 @@ const DynamicBlocksuite = ({
|
||||
useEffect(() => {
|
||||
const openWorkspace: LoadWorkspaceHandler = (
|
||||
workspaceId: string,
|
||||
websocket = false
|
||||
websocket = false,
|
||||
user
|
||||
) =>
|
||||
// eslint-disable-next-line no-async-promise-executor
|
||||
new Promise(async resolve => {
|
||||
@@ -35,7 +36,6 @@ const DynamicBlocksuite = ({
|
||||
room: workspaceId,
|
||||
providers: [],
|
||||
}).register(BlockSchema);
|
||||
|
||||
if (websocket && token.refresh) {
|
||||
// FIXME: if add websocket provider, the first page will be blank
|
||||
const ws = new WebsocketProvider(
|
||||
@@ -64,11 +64,16 @@ const DynamicBlocksuite = ({
|
||||
const indexDBProvider = workspace.providers.find(
|
||||
p => p instanceof IndexedDBDocProvider
|
||||
);
|
||||
const updates = await downloadWorkspace({ workspaceId });
|
||||
updates &&
|
||||
StoreWorkspace.Y.applyUpdate(workspace.doc, new Uint8Array(updates));
|
||||
// if after update, the space:meta is empty, then we need to get map with doc
|
||||
workspace.doc.getMap('space:meta');
|
||||
if (user) {
|
||||
const updates = await downloadWorkspace({ workspaceId });
|
||||
updates &&
|
||||
StoreWorkspace.Y.applyUpdate(
|
||||
workspace.doc,
|
||||
new Uint8Array(updates)
|
||||
);
|
||||
// if after update, the space:meta is empty, then we need to get map with doc
|
||||
workspace.doc.getMap('space:meta');
|
||||
}
|
||||
if (indexDBProvider) {
|
||||
(indexDBProvider as IndexedDBDocProvider).on('synced', async () => {
|
||||
resolve(workspace);
|
||||
|
||||
@@ -64,7 +64,8 @@ export const AppStateProvider = ({ children }: { children?: ReactNode }) => {
|
||||
(async () => {
|
||||
const workspacesList = await Promise.all(
|
||||
state.workspacesMeta.map(async ({ id }) => {
|
||||
const workspace = (await loadWorkspaceHandler?.(id)) || null;
|
||||
const workspace =
|
||||
(await loadWorkspaceHandler?.(id, false, state.user)) || null;
|
||||
return { id, workspace };
|
||||
})
|
||||
);
|
||||
@@ -108,7 +109,8 @@ export const AppStateProvider = ({ children }: { children?: ReactNode }) => {
|
||||
return state.currentWorkspace;
|
||||
}
|
||||
|
||||
const workspace = (await loadWorkspaceHandler?.(workspaceId, true)) || null;
|
||||
const workspace =
|
||||
(await loadWorkspaceHandler?.(workspaceId, true, state.user)) || null;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-expect-error
|
||||
|
||||
Reference in New Issue
Block a user