From 0c306bc34ac351ad36617e07769df8dc647d24b5 Mon Sep 17 00:00:00 2001 From: Innei Date: Thu, 10 Oct 2024 23:32:56 +0800 Subject: [PATCH] fix: only can add feed to owned lists, fixed #863 Signed-off-by: Innei --- .../src/components/ui/context-menu/context-menu.tsx | 2 +- apps/renderer/src/hooks/biz/useFeedActions.tsx | 4 ++-- apps/renderer/src/modules/feed-column/category.tsx | 4 ++-- apps/renderer/src/store/list/hooks.ts | 12 ++++++++++++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/apps/renderer/src/components/ui/context-menu/context-menu.tsx b/apps/renderer/src/components/ui/context-menu/context-menu.tsx index d96396edf..1cec540a9 100644 --- a/apps/renderer/src/components/ui/context-menu/context-menu.tsx +++ b/apps/renderer/src/components/ui/context-menu/context-menu.tsx @@ -99,7 +99,7 @@ const ContextMenuCheckboxItem = React.forwardRef< { if (!feed) return [] diff --git a/apps/renderer/src/modules/feed-column/category.tsx b/apps/renderer/src/modules/feed-column/category.tsx index 10ba1c023..34e90892e 100644 --- a/apps/renderer/src/modules/feed-column/category.tsx +++ b/apps/renderer/src/modules/feed-column/category.tsx @@ -16,7 +16,7 @@ import type { FeedViewType } from "~/lib/enum" import { showNativeMenu } from "~/lib/native-menu" import { cn, sortByAlphabet } from "~/lib/utils" import { getPreferredTitle, useAddFeedToFeedList, useFeedStore } from "~/store/feed" -import { useListByView } from "~/store/list" +import { useOwnedList } from "~/store/list" import { subscriptionActions, useSubscriptionByFeedId } from "~/store/subscription" import { useFeedUnreadStore } from "~/store/unread" @@ -131,7 +131,7 @@ function FeedCategoryImpl({ data: ids, view, categoryOpenStateData }: FeedCatego const addMutation = useAddFeedToFeedList() - const listList = useListByView(view!) + const listList = useOwnedList(view!) return (
diff --git a/apps/renderer/src/store/list/hooks.ts b/apps/renderer/src/store/list/hooks.ts index 05e75e90d..6c24c5ba9 100644 --- a/apps/renderer/src/store/list/hooks.ts +++ b/apps/renderer/src/store/list/hooks.ts @@ -1,3 +1,6 @@ +import { useMemo } from "react" + +import { useWhoami } from "~/atoms/user" import type { FeedViewType } from "~/lib/enum" import type { ListModel } from "~/models" @@ -9,3 +12,12 @@ export const useListById = (listId: Nullable): ListModel | null => export const useListByView = (view: FeedViewType) => { return useListStore((state) => Object.values(state.lists).filter((list) => list.view === view)) } + +export const useOwnedList = (view: FeedViewType) => { + const whoami = useWhoami() + const viewLists = useListByView(view) + return useMemo( + () => viewLists.filter((list) => list.ownerUserId === whoami?.id), + [viewLists, whoami], + ) +}