Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix(workspace): remove item not in the adapter (#3922)

Alex Yang834771878e00
diff --git a/packages/workspace/src/atom.ts b/packages/workspace/src/atom.ts
index 403a0d86ec..f8b785222e 100644
--- a/packages/workspace/src/atom.ts
+++ b/packages/workspace/src/atom.ts
@@ -120,13 +120,27 @@ const rootWorkspacesMetadataPromiseAtom = atom<
}
// step 2: fetch from adapters
{
- const lists = Object.values(WorkspaceAdapters)
- .sort((a, b) => a.loadPriority - b.loadPriority)
- .map(({ CRUD }) => CRUD.list);
+ const Adapters = Object.values(WorkspaceAdapters).sort(
+ (a, b) => a.loadPriority - b.loadPriority
+ );
- for (const list of lists) {
+ for (const Adapter of Adapters) {
+ const { CRUD, flavour: currentFlavour } = Adapter;
try {
- const item = await list();
+ const item = await CRUD.list();
+ // remove the metadata that is not in the list
+ // because we treat the workspace adapter as the source of truth
+ {
+ const removed = metadata.filter(
+ meta =>
+ meta.flavour === currentFlavour &&
+ !item.some(x => x.id === meta.id)
+ );
+ removed.forEach(meta => {
+ metadata.splice(metadata.indexOf(meta), 1);
+ });
+ }
+ // sort the metadata by the order of the list
if (metadata.length) {
item.sort((a, b) => {
return (