diff --git a/apps/desktop/layer/renderer/src/modules/settings/tabs/feeds.tsx b/apps/desktop/layer/renderer/src/modules/settings/tabs/feeds.tsx index 6b877bab4..cc35679c4 100644 --- a/apps/desktop/layer/renderer/src/modules/settings/tabs/feeds.tsx +++ b/apps/desktop/layer/renderer/src/modules/settings/tabs/feeds.tsx @@ -14,6 +14,7 @@ import { } from "@follow/components/ui/table/index.jsx" import { EllipsisHorizontalTextWithTooltip } from "@follow/components/ui/typography/index.js" import { views } from "@follow/constants" +import { sortByAlphabet } from "@follow/utils/utils" import clsx from "clsx" import { AnimatePresence, m } from "motion/react" import type { FC } from "react" @@ -36,8 +37,11 @@ import { FeedIcon } from "~/modules/feed/feed-icon" import { useConfirmUnsubscribeSubscriptionModal } from "~/modules/modal/hooks/useConfirmUnsubscribeSubscriptionModal" import { Balance } from "~/modules/wallet/balance" import { Queries } from "~/queries" -import { useFeedById } from "~/store/feed" -import { useAllFeeds, useSubscriptionByFeedId } from "~/store/subscription" +import { getFeedById, useFeedById } from "~/store/feed" +import { getSubscriptionByFeedId, useAllFeeds, useSubscriptionByFeedId } from "~/store/subscription" + +type SortField = "name" | "view" | "date" +type SortDirection = "asc" | "desc" export const SettingFeeds = () => { const inMas = useIsInMASReview() @@ -53,18 +57,32 @@ const GRID_COLS_CLASSNAME = tw`grid-cols-[30px_auto_150px_100px]` const SubscriptionFeedsSection = () => { const { t } = useTranslation("settings") - const feedList = useAllFeeds() + const allFeeds = useAllFeeds() const [selectedFeeds, setSelectedFeeds] = useState>(() => new Set()) + const [sortField, setSortField] = useState("name") + const [sortDirection, setSortDirection] = useState("asc") + + const handleSort = useCallback( + (field: SortField) => { + if (sortField === field) { + setSortDirection(sortDirection === "asc" ? "desc" : "asc") + } else { + setSortField(field) + setSortDirection("asc") + } + }, + [sortField, sortDirection], + ) const handleSelectAll = useCallback( (checked: boolean) => { if (checked) { - setSelectedFeeds(new Set(feedList.map((feed) => feed.id))) + setSelectedFeeds(new Set(allFeeds.map((feed) => feed.id))) } else { setSelectedFeeds(new Set()) } }, - [feedList], + [allFeeds], ) const handleSelectFeed = useCallback((feedId: string, checked: boolean) => { @@ -79,7 +97,7 @@ const SubscriptionFeedsSection = () => { }) }, []) - const isAllSelected = feedList.length > 0 && selectedFeeds.size === feedList.length + const isAllSelected = allFeeds.length > 0 && selectedFeeds.size === allFeeds.length const presentDeleteSubscription = useConfirmUnsubscribeSubscriptionModal() const handleBatchUnsubscribe = useCallback(() => { @@ -91,7 +109,7 @@ const SubscriptionFeedsSection = () => {

{t("feeds.subscription")}

- {feedList.length > 0 && ( + {allFeeds.length > 0 && (
{/* Header - Sticky */}
{
-
{t("feeds.tableHeaders.name")}
-
View
-
Date
+ + +
{/* Feed List */} - {feedList.map((item) => { - return ( - - ) - })} + {/* Sticky Action Bar at bottom when scrolled */} @@ -194,6 +236,71 @@ const SubscriptionFeedsSection = () => { ) } +const SortedFeedsList: FC<{ + feeds: Array<{ id: string }> + sortField: SortField + sortDirection: SortDirection + selectedFeeds: Set + onSelect: (feedId: string, checked: boolean) => void +}> = ({ feeds, sortField, sortDirection, selectedFeeds, onSelect }) => { + const sortedFeedIds = useMemo(() => { + switch (sortField) { + case "date": { + return feeds + .sort((a, b) => { + const aSubscription = getSubscriptionByFeedId(a.id) + const bSubscription = getSubscriptionByFeedId(b.id) + if (!aSubscription || !bSubscription) return 0 + const aDate = new Date(aSubscription.createdAt) + const bDate = new Date(bSubscription.createdAt) + return sortDirection === "asc" + ? aDate.getTime() - bDate.getTime() + : bDate.getTime() - aDate.getTime() + }) + .map((f) => f.id) + } + case "view": { + return feeds + .sort((a, b) => { + const aSubscription = getSubscriptionByFeedId(a.id) + const bSubscription = getSubscriptionByFeedId(b.id) + if (!aSubscription || !bSubscription) return 0 + return sortDirection === "asc" + ? aSubscription.view - bSubscription.view + : bSubscription.view - aSubscription.view + }) + .map((f) => f.id) + } + case "name": { + return feeds + .sort((a, b) => { + const aSubscription = getSubscriptionByFeedId(a.id) + const bSubscription = getSubscriptionByFeedId(b.id) + if (!aSubscription || !bSubscription) return 0 + const aFeed = getFeedById(a.id) + const bFeed = getFeedById(b.id) + if (!aFeed || !bFeed) return 0 + const aCompareTitle = aSubscription.title || aFeed.title || "" + const bCompareTitle = bSubscription.title || bFeed.title || "" + return sortDirection === "asc" + ? sortByAlphabet(aCompareTitle, bCompareTitle) + : sortByAlphabet(bCompareTitle, aCompareTitle) + }) + .map((f) => f.id) + } + } + }, [feeds, sortDirection, sortField]) + + return sortedFeedIds.map((feedId) => ( + + )) +} + const ViewSelector: FC<{ selectedFeeds: Set }> = ({ selectedFeeds }) => { const { t: tCommon } = useTranslation("common") const { mutate: batchUpdateSubscription } = useBatchUpdateSubscription() @@ -245,6 +352,7 @@ const FeedListItem = memo( tabIndex={-1} className={clsx( "hover:bg-material-medium grid h-10 w-full items-center gap-4 rounded px-1", + "content-visibility-auto contain-intrinsic-size-[auto_2.5rem]", GRID_COLS_CLASSNAME, )} onClick={() => onSelect(id, !selected)} @@ -267,7 +375,7 @@ const FeedListItem = memo(
- {views[subscription.view]!.icon} + {views[subscription.view]!.icon} {tCommon(views[subscription.view]!.name)}
diff --git a/apps/desktop/package.json b/apps/desktop/package.json index 4dd36df86..85b968dcc 100644 --- a/apps/desktop/package.json +++ b/apps/desktop/package.json @@ -82,6 +82,7 @@ "nbump": "2.1.2", "react": "19.0.0", "react-dom": "19.0.0", + "tailwindcss-content-visibility": "1.0.2", "tailwindcss-multi": "0.4.6", "tar": "7.4.3", "tsup": "8.4.0", diff --git a/apps/desktop/tailwind.config.ts b/apps/desktop/tailwind.config.ts index 0599bf8e9..20cc134b9 100644 --- a/apps/desktop/tailwind.config.ts +++ b/apps/desktop/tailwind.config.ts @@ -100,6 +100,7 @@ export default extendConfig({ addVariant("windows", ":where(html[data-os='Windows']) &") }), require("tailwindcss-multi"), + require("tailwindcss-content-visibility"), plugin(({ addUtilities, matchUtilities, theme }) => { addUtilities({ ".safe-inset-top": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 347cf3de4..84c7c2e5d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -297,6 +297,9 @@ importers: react-dom: specifier: 19.0.0 version: 19.0.0(react@19.0.0) + tailwindcss-content-visibility: + specifier: 1.0.2 + version: 1.0.2(tailwindcss@3.4.17(ts-node@10.9.2(@types/node@22.15.3)(typescript@5.8.3))) tailwindcss-multi: specifier: 0.4.6 version: 0.4.6 @@ -14046,6 +14049,11 @@ packages: peerDependencies: tailwindcss: '>=3.0.0 || insiders' + tailwindcss-content-visibility@1.0.2: + resolution: {integrity: sha512-Sch6hzEstDxFIDdMrI7tdUhYCUiFLS9FjJM5RfMFbRt5y0q24UwaXRGNvepoAzoHj60IqAwoysN+274XFzT01A==} + peerDependencies: + tailwindcss: ^3.0.0 + tailwindcss-motion@1.1.0: resolution: {integrity: sha512-0lK6rA4+367ffJdi1TtB72GlMCxJi2TP/xRiHc6An5pZSlU6WfIHhSvLxpcGilGZfBrOqc2q4woH1DEP/lCNbQ==} peerDependencies: @@ -30574,6 +30582,10 @@ snapshots: dependencies: tailwindcss: 3.4.17(ts-node@10.9.2(@types/node@22.15.3)(typescript@5.8.3)) + tailwindcss-content-visibility@1.0.2(tailwindcss@3.4.17(ts-node@10.9.2(@types/node@22.15.3)(typescript@5.8.3))): + dependencies: + tailwindcss: 3.4.17(ts-node@10.9.2(@types/node@22.15.3)(typescript@5.8.3)) + tailwindcss-motion@1.1.0(tailwindcss@3.4.17(ts-node@10.9.2(@types/node@22.15.3)(typescript@5.8.3))): dependencies: tailwindcss: 3.4.17(ts-node@10.9.2(@types/node@22.15.3)(typescript@5.8.3))