mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 04:48:53 +00:00
fix(core): properties adapter reactivitiy issue (#5661)
This commit is contained in:
@@ -1,16 +1,21 @@
|
||||
import type { Workspace } from '@affine/workspace/workspace';
|
||||
import { atomWithObservable } from 'jotai/utils';
|
||||
import { filter, map, of } from 'rxjs';
|
||||
import type { Workspace as BlockSuiteWorkspace } from '@blocksuite/store';
|
||||
import { atom } from 'jotai';
|
||||
import { atomFamily } from 'jotai/utils';
|
||||
|
||||
import { currentWorkspaceAtom } from '../atoms';
|
||||
import { waitForCurrentWorkspaceAtom } from '../atoms';
|
||||
import { WorkspacePropertiesAdapter } from './adapter';
|
||||
|
||||
export const currentWorkspacePropertiesAdapterAtom =
|
||||
atomWithObservable<WorkspacePropertiesAdapter>(get => {
|
||||
return of(get(currentWorkspaceAtom)).pipe(
|
||||
filter((workspace): workspace is Workspace => !!workspace),
|
||||
map(workspace => {
|
||||
return new WorkspacePropertiesAdapter(workspace.blockSuiteWorkspace);
|
||||
})
|
||||
);
|
||||
});
|
||||
// todo: remove the inner atom when workspace is closed by using workspaceAdapterAtomFamily.remove
|
||||
export const workspaceAdapterAtomFamily = atomFamily(
|
||||
(workspace: BlockSuiteWorkspace) => {
|
||||
return atom(async () => {
|
||||
await workspace.doc.whenLoaded;
|
||||
return new WorkspacePropertiesAdapter(workspace);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
export const currentWorkspacePropertiesAdapterAtom = atom(async get => {
|
||||
const workspace = await get(waitForCurrentWorkspaceAtom);
|
||||
return get(workspaceAdapterAtomFamily(workspace.blockSuiteWorkspace));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user