From f94306703abb64409ec9be97ea4ac90789d4d71f Mon Sep 17 00:00:00 2001
From: JimmFly <447268514@qq.com>
Date: Mon, 13 May 2024 03:48:17 +0000
Subject: [PATCH] feat(core): tag groups sorted alphabetically (#6865)
feat(core): tag groups sorted alphabetically
feat(core): add display group to collection page and tag page
---
.../page-list/group-definitions.tsx | 14 +++++++++--
.../src/pages/workspace/collection/header.tsx | 24 +++++++++++--------
.../core/src/pages/workspace/tag/header.tsx | 8 ++++++-
3 files changed, 33 insertions(+), 13 deletions(-)
diff --git a/packages/frontend/core/src/components/page-list/group-definitions.tsx b/packages/frontend/core/src/components/page-list/group-definitions.tsx
index d33e2d56c6330..6d30fdb69808b 100644
--- a/packages/frontend/core/src/components/page-list/group-definitions.tsx
+++ b/packages/frontend/core/src/components/page-list/group-definitions.tsx
@@ -4,7 +4,7 @@ import { TagService } from '@affine/core/modules/tag';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { FavoritedIcon, FavoriteIcon } from '@blocksuite/icons';
import type { DocMeta } from '@blocksuite/store';
-import { useLiveData, useService } from '@toeverything/infra';
+import { LiveData, useLiveData, useService } from '@toeverything/infra';
import { type ReactNode, useMemo } from 'react';
import * as styles from './group-definitions.css';
@@ -128,7 +128,17 @@ const GroupTagLabel = ({ tag, count }: { tag: Tag; count: number }) => {
};
export const useTagGroupDefinitions = (): ItemGroupDefinition[] => {
const tagList = useService(TagService).tagList;
- const tags = useLiveData(tagList.tags$);
+ const sortedTagsLiveData$ = useMemo(
+ () =>
+ LiveData.computed(get =>
+ get(tagList.tags$).sort((a, b) =>
+ get(a.value$).localeCompare(get(b.value$))
+ )
+ ),
+ [tagList.tags$]
+ );
+ const tags = useLiveData(sortedTagsLiveData$);
+
const t = useAFFiNEI18N();
const untagged = useMemo(
diff --git a/packages/frontend/core/src/pages/workspace/collection/header.tsx b/packages/frontend/core/src/pages/workspace/collection/header.tsx
index f462f9a056a4d..01f6cfc36cbf3 100644
--- a/packages/frontend/core/src/pages/workspace/collection/header.tsx
+++ b/packages/frontend/core/src/pages/workspace/collection/header.tsx
@@ -1,4 +1,5 @@
import { IconButton } from '@affine/component';
+import { PageDisplayMenu } from '@affine/core/components/page-list';
import { Header } from '@affine/core/components/pure/header';
import { WorkspaceModeFilterTab } from '@affine/core/components/pure/workspace-mode-filter-tab';
import { PlusIcon } from '@blocksuite/icons';
@@ -16,16 +17,19 @@ export const CollectionDetailHeader = ({
return (
}
- onClick={onCreate}
- className={clsx(
- styles.headerCreateNewButton,
- styles.headerCreateNewCollectionIconButton,
- !showCreateNew && styles.headerCreateNewButtonHidden
- )}
- />
+ <>
+ }
+ onClick={onCreate}
+ className={clsx(
+ styles.headerCreateNewButton,
+ styles.headerCreateNewCollectionIconButton,
+ !showCreateNew && styles.headerCreateNewButtonHidden
+ )}
+ />
+
+ >
}
center={}
/>
diff --git a/packages/frontend/core/src/pages/workspace/tag/header.tsx b/packages/frontend/core/src/pages/workspace/tag/header.tsx
index d46818a6363c7..a1c6212dd7930 100644
--- a/packages/frontend/core/src/pages/workspace/tag/header.tsx
+++ b/packages/frontend/core/src/pages/workspace/tag/header.tsx
@@ -1,6 +1,12 @@
+import { PageDisplayMenu } from '@affine/core/components/page-list';
import { Header } from '@affine/core/components/pure/header';
import { WorkspaceModeFilterTab } from '@affine/core/components/pure/workspace-mode-filter-tab';
export const TagDetailHeader = () => {
- return } />;
+ return (
+ }
+ right={}
+ />
+ );
};