feat(core): remove mode and pages field from Collection (#4817)

This commit is contained in:
3720
2023-11-02 18:47:43 +08:00
committed by GitHub
parent bf17b4789b
commit 7068d5f38a
20 changed files with 1085 additions and 983 deletions

View File

@@ -116,10 +116,8 @@ export const pageCollectionBaseAtom =
return {
id: v.id,
name: v.name,
mode: 'rule',
filterList: v.filterList,
allowList: v.allowList ?? [],
pages: [],
};
});
};
@@ -140,10 +138,8 @@ export const pageCollectionBaseAtom =
return {
id: v.id,
name: v.name,
mode: 'rule',
filterList: v.filterList,
allowList: v.allowList ?? [],
pages: [],
};
});
}

View File

@@ -1,4 +1,4 @@
import { AnimatedCollectionsIcon } from '@affine/component';
import { AnimatedCollectionsIcon, toast } from '@affine/component';
import {
MenuItem as SidebarMenuItem,
MenuLinkItem as SidebarMenuLinkItem,
@@ -54,10 +54,17 @@ const CollectionRenderer = ({
}) => {
const [collapsed, setCollapsed] = useState(true);
const setting = useCollectionManager(collectionsCRUDAtom);
const t = useAFFiNEI18N();
const { setNodeRef, isOver } = useDroppable({
id: `${Collections_DROP_AREA_PREFIX}${collection.id}`,
data: {
addToCollection: (id: string) => {
if (collection.allowList.includes(id)) {
toast(t['com.affine.collection.addPage.alreadyExists']());
return;
} else {
toast(t['com.affine.collection.addPage.success']());
}
setting.addPage(collection.id, id).catch(err => {
console.error(err);
});

View File

@@ -36,10 +36,8 @@ const FilterContainer = ({ workspaceId }: { workspaceId: string }) => {
const setting = useCollectionManager(collectionsCRUDAtom);
const saveToCollection = useCallback(
async (collection: Collection) => {
console.log(setting.currentCollection.filterList);
await setting.createCollection({
...collection,
mode: 'rule',
filterList: setting.currentCollection.filterList,
});
navigateHelper.jumpToCollection(workspaceId, collection.id);

View File

@@ -93,10 +93,10 @@ const Placeholder = ({ collection }: { collection: Collection }) => {
const { updateCollection } = useCollectionManager(collectionsCRUDAtom);
const { node, open } = useEditCollection(useAllPageListConfig());
const openPageEdit = useCallback(() => {
open({ ...collection, mode: 'page' }).then(updateCollection);
open({ ...collection }, 'page').then(updateCollection);
}, [open, collection, updateCollection]);
const openRuleEdit = useCallback(() => {
open({ ...collection, mode: 'rule' }).then(updateCollection);
open({ ...collection }, 'rule').then(updateCollection);
}, [collection, open, updateCollection]);
const [showTips, setShowTips] = useState(false);
useEffect(() => {
@@ -277,9 +277,6 @@ const Placeholder = ({ collection }: { collection: Collection }) => {
const isEmpty = (collection: Collection) => {
return (
(collection.mode === 'page' && collection.pages.length === 0) ||
(collection.mode === 'rule' &&
collection.allowList.length === 0 &&
collection.filterList.length === 0)
collection.allowList.length === 0 && collection.filterList.length === 0
);
};

View File

@@ -1,4 +1,8 @@
import { filterPage, useCollectionManager } from '@affine/component/page-list';
import {
filterPage,
filterPageByRules,
useCollectionManager,
} from '@affine/component/page-list';
import type { PageMeta } from '@blocksuite/store';
import { useAtomValue } from 'jotai';
import { useMemo } from 'react';
@@ -15,7 +19,8 @@ export const useFilteredPageMetas = (
) => {
const { isPreferredEdgeless } = usePageHelper(workspace);
const pageMode = useAtomValue(allPageModeSelectAtom);
const { currentCollection } = useCollectionManager(collectionsCRUDAtom);
const { currentCollection, isDefault } =
useCollectionManager(collectionsCRUDAtom);
const filteredPageMetas = useMemo(
() =>
@@ -43,9 +48,22 @@ export const useFilteredPageMetas = (
if (!currentCollection) {
return true;
}
return filterPage(currentCollection, pageMeta);
return isDefault
? filterPageByRules(
currentCollection.filterList,
currentCollection.allowList,
pageMeta
)
: filterPage(currentCollection, pageMeta);
}),
[pageMetas, pageMode, isPreferredEdgeless, route, currentCollection]
[
currentCollection,
isDefault,
isPreferredEdgeless,
pageMetas,
pageMode,
route,
]
);
return filteredPageMetas;

View File

@@ -95,16 +95,11 @@ export class WorkspaceSetting {
deletePagesFromCollection(collection: Collection, idSet: Set<string>) {
const newAllowList = collection.allowList.filter(id => !idSet.has(id));
const newPages = collection.pages.filter(id => !idSet.has(id));
if (
newAllowList.length !== collection.allowList.length ||
newPages.length !== collection.pages.length
) {
if (newAllowList.length !== collection.allowList.length) {
this.updateCollection(collection.id, old => {
return {
...old,
allowList: newAllowList,
pages: newPages,
};
});
}