From a084c2bc7d6d4e6f83ad0250edd0911cc02f5da2 Mon Sep 17 00:00:00 2001 From: lawvs <18554747+lawvs@users.noreply.github.com> Date: Thu, 23 Jan 2025 18:05:19 +0800 Subject: [PATCH] refactor: separate EntryList component --- .../src/modules/entry-list/entry-list.tsx | 77 +------------------ apps/mobile/src/modules/entry-list/index.tsx | 74 ++++++++++++++++++ .../src/screens/(stack)/(tabs)/index.tsx | 2 +- 3 files changed, 79 insertions(+), 74 deletions(-) create mode 100644 apps/mobile/src/modules/entry-list/index.tsx diff --git a/apps/mobile/src/modules/entry-list/entry-list.tsx b/apps/mobile/src/modules/entry-list/entry-list.tsx index 782c96922..461466c6b 100644 --- a/apps/mobile/src/modules/entry-list/entry-list.tsx +++ b/apps/mobile/src/modules/entry-list/entry-list.tsx @@ -2,11 +2,10 @@ import { FeedViewType } from "@follow/constants" import { useTypeScriptHappyCallback } from "@follow/hooks" import { useBottomTabBarHeight } from "@react-navigation/bottom-tabs" import { useHeaderHeight } from "@react-navigation/elements" -import { useIsFocused } from "@react-navigation/native" import { FlashList } from "@shopify/flash-list" import { Image } from "expo-image" import { router } from "expo-router" -import { useCallback, useContext, useEffect, useMemo } from "react" +import { useCallback, useContext, useMemo } from "react" import { StyleSheet, Text, useAnimatedValue, View } from "react-native" import { useSafeAreaInsets } from "react-native-safe-area-context" @@ -15,82 +14,14 @@ import { NavigationContext, } from "@/src/components/common/SafeNavigationScrollView" import { ItemPressable } from "@/src/components/ui/pressable/item-pressable" -import { useSelectedFeed, useSetDrawerSwipeDisabled } from "@/src/modules/feed-drawer/atoms" -import { - useEntry, - useEntryIdsByCategory, - useEntryIdsByFeedId, - useEntryIdsByInboxId, - useEntryIdsByView, -} from "@/src/store/entry/hooks" -import { useList } from "@/src/store/list/hooks" +import { useSelectedFeed } from "@/src/modules/feed-drawer/atoms" +import { useEntry } from "@/src/store/entry/hooks" import { ViewSelector } from "../feed-drawer/view-selector" import { LeftAction, RightAction } from "./action" import { EntryListContentGrid } from "./entry-list-gird" -export function EntryList() { - const setDrawerSwipeDisabled = useSetDrawerSwipeDisabled() - const isFocused = useIsFocused() - useEffect(() => { - if (isFocused) { - setDrawerSwipeDisabled(false) - } else { - setDrawerSwipeDisabled(true) - } - }, [setDrawerSwipeDisabled, isFocused]) - - const selectedFeed = useSelectedFeed() - - switch (selectedFeed.type) { - case "view": { - return - } - case "feed": { - return - } - case "category": { - return - } - case "list": { - return - } - case "inbox": { - return - } - // No default - } -} - -function ViewEntryList({ viewId }: { viewId: FeedViewType }) { - const entryIds = useEntryIdsByView(viewId) - - return -} - -function FeedEntryList({ feedId }: { feedId: string }) { - const entryIds = useEntryIdsByFeedId(feedId) - return -} - -function CategoryEntryList({ categoryName }: { categoryName: string }) { - const entryIds = useEntryIdsByCategory(categoryName) - return -} - -function ListEntryList({ listId }: { listId: string }) { - const list = useList(listId) - if (!list) return null - - return -} - -function InboxEntryList({ inboxId }: { inboxId: string }) { - const entryIds = useEntryIdsByInboxId(inboxId) - return -} - -function EntryListScreen({ entryIds }: { entryIds: string[] }) { +export function EntryListScreen({ entryIds }: { entryIds: string[] }) { const scrollY = useAnimatedValue(0) const selectedFeed = useSelectedFeed() const view = selectedFeed.type === "view" ? selectedFeed.viewId : null diff --git a/apps/mobile/src/modules/entry-list/index.tsx b/apps/mobile/src/modules/entry-list/index.tsx new file mode 100644 index 000000000..eb29a68b7 --- /dev/null +++ b/apps/mobile/src/modules/entry-list/index.tsx @@ -0,0 +1,74 @@ +import type { FeedViewType } from "@follow/constants" +import { useIsFocused } from "@react-navigation/native" +import { useEffect } from "react" + +import { useSelectedFeed, useSetDrawerSwipeDisabled } from "@/src/modules/feed-drawer/atoms" +import { + useEntryIdsByCategory, + useEntryIdsByFeedId, + useEntryIdsByInboxId, + useEntryIdsByView, +} from "@/src/store/entry/hooks" +import { useList } from "@/src/store/list/hooks" + +import { EntryListScreen } from "./entry-list" + +export function EntryList() { + const setDrawerSwipeDisabled = useSetDrawerSwipeDisabled() + const isFocused = useIsFocused() + useEffect(() => { + if (isFocused) { + setDrawerSwipeDisabled(false) + } else { + setDrawerSwipeDisabled(true) + } + }, [setDrawerSwipeDisabled, isFocused]) + + const selectedFeed = useSelectedFeed() + + switch (selectedFeed.type) { + case "view": { + return + } + case "feed": { + return + } + case "category": { + return + } + case "list": { + return + } + case "inbox": { + return + } + // No default + } +} + +function ViewEntryList({ viewId }: { viewId: FeedViewType }) { + const entryIds = useEntryIdsByView(viewId) + return +} + +function FeedEntryList({ feedId }: { feedId: string }) { + const entryIds = useEntryIdsByFeedId(feedId) + return +} + +function CategoryEntryList({ categoryName }: { categoryName: string }) { + const entryIds = useEntryIdsByCategory(categoryName) + return +} + +function ListEntryList({ listId }: { listId: string }) { + const list = useList(listId) + if (!list) return null + + return +} + +function InboxEntryList({ inboxId }: { inboxId: string }) { + const entryIds = useEntryIdsByInboxId(inboxId) + return +} diff --git a/apps/mobile/src/screens/(stack)/(tabs)/index.tsx b/apps/mobile/src/screens/(stack)/(tabs)/index.tsx index d0c13866e..751f036b3 100644 --- a/apps/mobile/src/screens/(stack)/(tabs)/index.tsx +++ b/apps/mobile/src/screens/(stack)/(tabs)/index.tsx @@ -1,4 +1,4 @@ -import { EntryList } from "@/src/modules/entry-list/entry-list" +import { EntryList } from "@/src/modules/entry-list" export default function Index() { return