From a4e6709c46bb0974d2c78defaefeef0999fe524f Mon Sep 17 00:00:00 2001 From: Innei Date: Sat, 6 Jul 2024 19:10:29 +0800 Subject: [PATCH] fix: collection bug Signed-off-by: Innei --- src/renderer/src/components/ui/kbd/Kbd.tsx | 4 +- src/renderer/src/lib/utils.ts | 16 ++- .../src/modules/entry-column/index.tsx | 126 +++++++++--------- src/renderer/src/store/subscription.ts | 10 +- 4 files changed, 82 insertions(+), 74 deletions(-) diff --git a/src/renderer/src/components/ui/kbd/Kbd.tsx b/src/renderer/src/components/ui/kbd/Kbd.tsx index 5f7d8550a..a43e5fc8f 100644 --- a/src/renderer/src/components/ui/kbd/Kbd.tsx +++ b/src/renderer/src/components/ui/kbd/Kbd.tsx @@ -1,5 +1,4 @@ import { getOS } from "@renderer/lib/utils" -import { memoize } from "lodash-es" import type { FC } from "react" const SpecialKeys = { @@ -23,11 +22,10 @@ const SpecialKeys = { }, } -const os = memoize(getOS) export const Kbd: FC<{ children: string }> = ({ children }) => { - const specialKeys = SpecialKeys[os()] + const specialKeys = SpecialKeys[getOS()] let key = children if (children.toLowerCase() in specialKeys) { key = specialKeys[children.toLowerCase()] diff --git a/src/renderer/src/lib/utils.ts b/src/renderer/src/lib/utils.ts index bae252505..ad02aa767 100644 --- a/src/renderer/src/lib/utils.ts +++ b/src/renderer/src/lib/utils.ts @@ -1,5 +1,6 @@ import type { ClassValue } from "clsx" import { clsx } from "clsx" +import { memoize } from "lodash-es" import { twMerge } from "tailwind-merge" import { FEED_COLLECTION_LIST, levels } from "./constants" @@ -42,7 +43,7 @@ export function getEntriesParams({ } export type OS = "macOS" | "iOS" | "Windows" | "Android" | "Linux" | "" -export function getOS(): OS { +export const getOS = memoize((): OS => { const { userAgent } = window.navigator, { platform } = window.navigator, macosPlatforms = ["Macintosh", "MacIntel", "MacPPC", "Mac68K"], @@ -63,7 +64,7 @@ export function getOS(): OS { } return os as OS -} +}) // eslint-disable-next-line no-control-regex export const isASCII = (str) => /^[\u0000-\u007F]*$/.test(str) @@ -74,7 +75,13 @@ export const isBizId = (id) => { // id is uuid or snowflake // 0. check is uuid - if (id.length === 36 && id[8] === "-" && id[13] === "-" && id[18] === "-" && id[23] === "-") { + if ( + id.length === 36 && + id[8] === "-" && + id[13] === "-" && + id[18] === "-" && + id[23] === "-" + ) { return true } @@ -112,7 +119,8 @@ export function formatXml(xml: string, indent = 4) { return formatted.trim() } -export const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)) +export const sleep = (ms: number) => + new Promise((resolve) => setTimeout(resolve, ms)) export const capitalizeFirstLetter = (string: string) => string.charAt(0).toUpperCase() + string.slice(1) diff --git a/src/renderer/src/modules/entry-column/index.tsx b/src/renderer/src/modules/entry-column/index.tsx index f4aa81e8b..c7b184efb 100644 --- a/src/renderer/src/modules/entry-column/index.tsx +++ b/src/renderer/src/modules/entry-column/index.tsx @@ -48,7 +48,6 @@ import { useCallback, useEffect, useLayoutEffect, - useMemo, useRef, useState, } from "react" @@ -184,7 +183,7 @@ const ListHeader: FC<{ }, [feedId, folderIds, routerParams]) const headerTitle = useFeedHeaderTitle() - const os = useMemo(getOS, []) + const os = getOS() const titleAtBottom = window.electron && os === "macOS" const titleInfo = ( @@ -222,70 +221,71 @@ const ListHeader: FC<{ )} > {!titleAtBottom && titleInfo} - {!isInCollectionList && ( -
e.stopPropagation()} - > - {views[view].wideMode && - entryId && - entryId !== ROUTE_ENTRY_PENDING && ( - <> - - - - )} - {feed?.ownerUserId === user?.id && isBizId(routerParams.feedId) && ( - { - refreshFeed() - }} - > - - - )} + +
e.stopPropagation()} + > + {views[view].wideMode && + entryId && + entryId !== ROUTE_ENTRY_PENDING && ( + <> + + + + )} + {feed?.ownerUserId === user?.id && isBizId(routerParams.feedId) && ( setGeneralSetting("unreadOnly", !unreadOnly)} + tooltip="Refresh" + // shortcut={shortcuts.entries.toggleUnreadOnly.key} + onClick={() => { + refreshFeed() + }} > - {unreadOnly ? ( - - ) : ( - - )} + - - - - - - - -
Mark all as read?
-
- - Cancel - - {/* TODO */} - - Confirm - -
-
-
-
- )} + )} + setGeneralSetting("unreadOnly", !unreadOnly)} + > + {unreadOnly ? ( + + ) : ( + + )} + + + + + + + + +
Mark all as read?
+
+ + Cancel + + {/* TODO */} + + Confirm + +
+
+
+
{titleAtBottom && titleInfo} diff --git a/src/renderer/src/store/subscription.ts b/src/renderer/src/store/subscription.ts index 92f14473f..36115df43 100644 --- a/src/renderer/src/store/subscription.ts +++ b/src/renderer/src/store/subscription.ts @@ -1,5 +1,5 @@ import { apiClient } from "@renderer/lib/api-fetch" -import { ROUTE_FEED_IN_FOLDER } from "@renderer/lib/constants" +import { FEED_COLLECTION_LIST, ROUTE_FEED_IN_FOLDER } from "@renderer/lib/constants" import { FeedViewType } from "@renderer/lib/enum" import { capitalizeFirstLetter } from "@renderer/lib/utils" import type { SubscriptionModel } from "@renderer/models" @@ -156,12 +156,14 @@ export const useSubscriptionByFeedId = (feedId: FeedId) => useSubscriptionStore((state) => state.data[feedId]) export const useFolderFeedsByFeedId = (feedId?: string) => - useSubscriptionStore((state) => { - if (typeof feedId !== "string") return + useSubscriptionStore((state): string[] => { + if (typeof feedId !== "string") return [] + if (feedId === FEED_COLLECTION_LIST) { return [feedId] } if (!feedId.startsWith(ROUTE_FEED_IN_FOLDER)) { - return + return [] } + const folderName = feedId.replace(ROUTE_FEED_IN_FOLDER, "") const feedIds: string[] = [] for (const feedId in state.data) {