From 1041b9aa9e4d647d869253bef256b5669fd2325a Mon Sep 17 00:00:00 2001 From: lawvs <18554747+lawvs@users.noreply.github.com> Date: Wed, 22 Jan 2025 17:41:56 +0800 Subject: [PATCH] refactor: update feed selection logic --- .../src/modules/entry-list/entry-list.tsx | 19 ++++++++++++++----- apps/mobile/src/modules/feed-drawer/atoms.ts | 14 +++++++++----- .../src/modules/feed-drawer/feed-panel.tsx | 4 +++- .../subscription/SubscriptionLists.tsx | 5 ++++- .../modules/subscription/items/InboxItem.tsx | 10 +++++++++- 5 files changed, 39 insertions(+), 13 deletions(-) diff --git a/apps/mobile/src/modules/entry-list/entry-list.tsx b/apps/mobile/src/modules/entry-list/entry-list.tsx index 45aabd92f..0ea79e808 100644 --- a/apps/mobile/src/modules/entry-list/entry-list.tsx +++ b/apps/mobile/src/modules/entry-list/entry-list.tsx @@ -16,9 +16,12 @@ import { useEntry, useEntryIdsByCategory, useEntryIdsByFeedId, + useEntryIdsByInboxId, useEntryIdsByView, } from "@/src/store/entry/hooks" +import { FEED_COLLECTION_LIST } from "@/src/store/entry/utils" import { useFeed } from "@/src/store/feed/hooks" +import { useInbox } from "@/src/store/inbox/hooks" import { useList } from "@/src/store/list/hooks" import { LeftAction, RightAction } from "./action" @@ -49,9 +52,9 @@ export function EntryList() { case "list": { return } - // case "inbox": { - // return - // } + case "inbox": { + return + } // No default } } @@ -65,7 +68,8 @@ function ViewEntryList({ viewId }: { viewId: FeedViewType }) { function FeedEntryList({ feedId }: { feedId: string }) { const feed = useFeed(feedId) const entryIds = useEntryIdsByFeedId(feedId) - return + const title = feedId === FEED_COLLECTION_LIST ? "Collections" : (feed?.title ?? "") + return } function CategoryEntryList({ categoryName }: { categoryName: string }) { @@ -76,10 +80,15 @@ function CategoryEntryList({ categoryName }: { categoryName: string }) { function ListEntryList({ listId }: { listId: string }) { const list = useList(listId) if (!list) return null - return } +function InboxEntryList({ inboxId }: { inboxId: string }) { + const inbox = useInbox(inboxId) + const entryIds = useEntryIdsByInboxId(inboxId) + return +} + function EntryListScreen({ title, entryIds }: { title: string; entryIds: string[] }) { return ( <> diff --git a/apps/mobile/src/modules/feed-drawer/atoms.ts b/apps/mobile/src/modules/feed-drawer/atoms.ts index ccc058e7f..00bb5536e 100644 --- a/apps/mobile/src/modules/feed-drawer/atoms.ts +++ b/apps/mobile/src/modules/feed-drawer/atoms.ts @@ -59,7 +59,7 @@ export function useSelectedCollection() { } export const selectCollection = (state: CollectionPanelState) => { jotaiStore.set(collectionPanelStateAtom, state) - if (state.type === "view") { + if (state.type === "view" || state.type === "list") { jotaiStore.set(selectedFeedAtom, state) } } @@ -83,6 +83,10 @@ export type SelectedFeed = type: "list" listId: string } + | { + type: "inbox" + inboxId: string + } const selectedFeedAtom = atom({ type: "view", @@ -109,10 +113,10 @@ export function useSelectedFeed() { payload = { listId: selectedFeed.listId } break } - // case "inbox": { - // payload = { inboxId: selectedFeed.inboxId } - // break - // } + case "inbox": { + payload = { inboxId: selectedFeed.inboxId } + break + } // No default } usePrefetchEntries(payload) diff --git a/apps/mobile/src/modules/feed-drawer/feed-panel.tsx b/apps/mobile/src/modules/feed-drawer/feed-panel.tsx index fbd93ac76..d00948c70 100644 --- a/apps/mobile/src/modules/feed-drawer/feed-panel.tsx +++ b/apps/mobile/src/modules/feed-drawer/feed-panel.tsx @@ -32,7 +32,7 @@ import { import { useCurrentView, useFeedListSortMethod, useFeedListSortOrder } from "../subscription/atoms" import { ViewPageCurrentViewProvider } from "../subscription/ctx" import { SubscriptionList } from "../subscription/SubscriptionLists" -import { selectFeed, useSelectedCollection } from "./atoms" +import { closeDrawer, selectFeed, useSelectedCollection } from "./atoms" import { ListHeaderComponent, ViewHeaderComponent } from "./header" export const FeedPanel = () => { @@ -153,6 +153,7 @@ const CategoryGrouped = memo( type: "category", categoryName: category, }) + closeDrawer() }} className="h-12 flex-row items-center px-3" > @@ -229,6 +230,7 @@ const SubscriptionItem = memo(({ id, className }: { id: string; className?: stri type: "feed", feedId: id, }) + closeDrawer() }} > diff --git a/apps/mobile/src/modules/subscription/SubscriptionLists.tsx b/apps/mobile/src/modules/subscription/SubscriptionLists.tsx index de9f24ad5..fd727614c 100644 --- a/apps/mobile/src/modules/subscription/SubscriptionLists.tsx +++ b/apps/mobile/src/modules/subscription/SubscriptionLists.tsx @@ -11,6 +11,7 @@ import { useEventCallback } from "usehooks-ts" import { ItemPressable } from "@/src/components/ui/pressable/item-pressable" import { StarCuteFiIcon } from "@/src/icons/star_cute_fi" +import { FEED_COLLECTION_LIST } from "@/src/store/entry/utils" import { useGroupedSubscription, useInboxSubscription, @@ -22,6 +23,7 @@ import { } from "@/src/store/subscription/hooks" import { subscriptionSyncService } from "@/src/store/subscription/store" +import { closeDrawer, selectFeed } from "../feed-drawer/atoms" import { useFeedListSortMethod, useFeedListSortOrder, viewAtom } from "./atoms" import { CategoryGrouped } from "./CategoryGrouped" import { ViewTabHeight } from "./constants" @@ -200,7 +202,8 @@ const StarItem = () => { return ( { - // TODO + selectFeed({ type: "feed", feedId: FEED_COLLECTION_LIST }) + closeDrawer() }} className="mt-4 h-12 w-full flex-row items-center px-3" > diff --git a/apps/mobile/src/modules/subscription/items/InboxItem.tsx b/apps/mobile/src/modules/subscription/items/InboxItem.tsx index e8edbb4fb..a65fd52eb 100644 --- a/apps/mobile/src/modules/subscription/items/InboxItem.tsx +++ b/apps/mobile/src/modules/subscription/items/InboxItem.tsx @@ -9,6 +9,8 @@ import { useSubscription } from "@/src/store/subscription/hooks" import { getInboxStoreId } from "@/src/store/subscription/utils" import { useUnreadCount } from "@/src/store/unread/hooks" +import { closeDrawer, selectFeed } from "../../feed-drawer/atoms" + export const InboxItem = memo(({ id }: { id: string }) => { const subscription = useSubscription(getInboxStoreId(id)) const unreadCount = useUnreadCount(id) @@ -16,7 +18,13 @@ export const InboxItem = memo(({ id }: { id: string }) => { if (!subscription) return null return ( - + { + selectFeed({ type: "inbox", inboxId: id }) + closeDrawer() + }} + >