Skip to content

Commit

Permalink
feat: allow disable auto group behavior
Browse files Browse the repository at this point in the history
close #1602
  • Loading branch information
hyoban committed Nov 15, 2024
1 parent 24017df commit 23fd936
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 3 deletions.
2 changes: 2 additions & 0 deletions apps/renderer/src/atoms/settings/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const createDefaultSettings = (): GeneralSettings => ({
sendAnonymousData: true,
reduceRefetch: true,

autoGroup: true,

// view
unreadOnly: true,
// mark unread
Expand Down
5 changes: 4 additions & 1 deletion apps/renderer/src/modules/feed-column/category.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down
9 changes: 7 additions & 2 deletions apps/renderer/src/modules/feed-column/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<string, string[]>

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] = []
Expand All @@ -60,7 +65,7 @@ const useFeedsGroupedData = (view: FeedViewType) => {
}

return groupFolder
}, [data])
}, [autoGroup, data])
}

const useListsGroupedData = (view: FeedViewType) => {
Expand Down
10 changes: 10 additions & 0 deletions apps/renderer/src/modules/settings/tabs/general.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
3 changes: 3 additions & 0 deletions locales/settings/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/interface/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface GeneralSettings {
// TTS
voice: string
reduceRefetch: boolean
autoGroup: boolean
}

export interface UISettings {
Expand Down

0 comments on commit 23fd936

Please sign in to comment.