From 23fd9368baea10b15b89baf27a422e5695a08f7b Mon Sep 17 00:00:00 2001 From: Stephen Zhou <38493346+hyoban@users.noreply.github.com> Date: Fri, 15 Nov 2024 14:20:21 +0800 Subject: [PATCH] feat: allow disable auto group behavior close #1602 --- apps/renderer/src/atoms/settings/general.ts | 2 ++ apps/renderer/src/modules/feed-column/category.tsx | 5 ++++- apps/renderer/src/modules/feed-column/list.tsx | 9 +++++++-- apps/renderer/src/modules/settings/tabs/general.tsx | 10 ++++++++++ locales/settings/en.json | 3 +++ packages/shared/src/interface/settings.ts | 1 + 6 files changed, 27 insertions(+), 3 deletions(-) diff --git a/apps/renderer/src/atoms/settings/general.ts b/apps/renderer/src/atoms/settings/general.ts index 79a2d6a478..96322c7823 100644 --- a/apps/renderer/src/atoms/settings/general.ts +++ b/apps/renderer/src/atoms/settings/general.ts @@ -12,6 +12,8 @@ const createDefaultSettings = (): GeneralSettings => ({ sendAnonymousData: true, reduceRefetch: true, + autoGroup: true, + // view unreadOnly: true, // mark unread diff --git a/apps/renderer/src/modules/feed-column/category.tsx b/apps/renderer/src/modules/feed-column/category.tsx index f054767576..783fce81e0 100644 --- a/apps/renderer/src/modules/feed-column/category.tsx +++ b/apps/renderer/src/modules/feed-column/category.tsx @@ -17,6 +17,7 @@ import { useOnClickOutside } from "usehooks-ts" import type { MenuItemInput } from "~/atoms/context-menu" import { useShowContextMenu } from "~/atoms/context-menu" +import { useGeneralSettingSelector } from "~/atoms/settings/general" import { ROUTE_FEED_IN_FOLDER } from "~/constants" import { useAddFeedToFeedList } from "~/hooks/biz/useFeedActions" import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry" @@ -56,7 +57,9 @@ function FeedCategoryImpl({ data: ids, view, categoryOpenStateData }: FeedCatego const navigate = useNavigateEntry() const subscription = useSubscriptionByFeedId(ids[0]) - const folderName = subscription?.category || subscription.defaultCategory + const autoGroup = useGeneralSettingSelector((state) => state.autoGroup) + const folderName = + subscription?.category || (autoGroup ? subscription.defaultCategory : subscription.feedId) const showCollapse = sortByUnreadFeedList.length > 1 || !!subscription?.category diff --git a/apps/renderer/src/modules/feed-column/list.tsx b/apps/renderer/src/modules/feed-column/list.tsx index 1a1f1a3fca..b83494e25e 100644 --- a/apps/renderer/src/modules/feed-column/list.tsx +++ b/apps/renderer/src/modules/feed-column/list.tsx @@ -12,6 +12,7 @@ import { Link } from "react-router-dom" import Selecto from "react-selecto" import { useEventListener } from "usehooks-ts" +import { useGeneralSettingSelector } from "~/atoms/settings/general" import { IconOpacityTransition } from "~/components/ux/transition/icon" import { FEED_COLLECTION_LIST } from "~/constants" import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry" @@ -44,13 +45,17 @@ const useFeedsGroupedData = (view: FeedViewType) => { const data = useSubscriptionByView(view) || remoteData + const autoGroup = useGeneralSettingSelector((state) => state.autoGroup) + return useMemo(() => { if (!data || data.length === 0) return {} const groupFolder = {} as Record for (const subscription of data) { - const category = subscription.category || subscription.defaultCategory + const category = + subscription.category || (autoGroup ? subscription.defaultCategory : subscription.feedId) + if (category) { if (!groupFolder[category]) { groupFolder[category] = [] @@ -60,7 +65,7 @@ const useFeedsGroupedData = (view: FeedViewType) => { } return groupFolder - }, [data]) + }, [autoGroup, data]) } const useListsGroupedData = (view: FeedViewType) => { diff --git a/apps/renderer/src/modules/settings/tabs/general.tsx b/apps/renderer/src/modules/settings/tabs/general.tsx index 141918ee59..0b3c0a6f97 100644 --- a/apps/renderer/src/modules/settings/tabs/general.tsx +++ b/apps/renderer/src/modules/settings/tabs/general.tsx @@ -67,6 +67,16 @@ export const SettingGeneral = () => { }), IN_ELECTRON && MinimizeToTraySetting, LanguageSelector, + + { + type: "title", + value: t("general.sidebar"), + }, + defineSettingItem("autoGroup", { + label: t("general.auto_group.label"), + description: t("general.auto_group.description"), + }), + { type: "title", value: t("general.timeline"), diff --git a/locales/settings/en.json b/locales/settings/en.json index 7e572ea18f..c68707fb82 100644 --- a/locales/settings/en.json +++ b/locales/settings/en.json @@ -105,6 +105,8 @@ "feeds.tableHeaders.subscriptionCount": "Subs", "feeds.tableHeaders.tipAmount": "Tips", "general.app": "App", + "general.auto_group.description": "Automatically group feeds by site domain.", + "general.auto_group.label": "Auto Group", "general.cache": "Cache", "general.data": "Data", "general.data_persist.description": "Persist data locally to enable offline access and local search.", @@ -143,6 +145,7 @@ "general.send_anonymous_data.label": "Send anonymous data", "general.show_unread_on_launch.description": "Show unread content on launch", "general.show_unread_on_launch.label": "Show unread content on launch", + "general.sidebar": "Sidebar", "general.sidebar_title": "General", "general.timeline": "Timeline", "general.unread": "Unread", diff --git a/packages/shared/src/interface/settings.ts b/packages/shared/src/interface/settings.ts index 5063e9bf28..f54a759e56 100644 --- a/packages/shared/src/interface/settings.ts +++ b/packages/shared/src/interface/settings.ts @@ -12,6 +12,7 @@ export interface GeneralSettings { // TTS voice: string reduceRefetch: boolean + autoGroup: boolean } export interface UISettings {