feat(mobile): entry list by feed or category; pagination (#2717)
* feat(mobile): entry list pagination support, remove deprecated views * feat: entry list by feed * feat: support category * back title
This commit is contained in:
@@ -2,8 +2,6 @@ import { FeedViewType } from "@follow/constants"
|
||||
import type * as React from "react"
|
||||
import colors from "tailwindcss/colors"
|
||||
|
||||
import { AnnouncementCuteFiIcon } from "../icons/announcement_cute_fi"
|
||||
import { MicCuteFiIcon } from "../icons/mic_cute_fi"
|
||||
import { PaperCuteFiIcon } from "../icons/paper_cute_fi"
|
||||
import { PicCuteFiIcon } from "../icons/pic_cute_fi"
|
||||
import { TwitterCuteFiIcon } from "../icons/twitter_cute_fi"
|
||||
@@ -48,18 +46,4 @@ export const views: ViewDefinition[] = [
|
||||
translation: "title",
|
||||
view: FeedViewType.Videos,
|
||||
},
|
||||
{
|
||||
name: "Audios",
|
||||
icon: MicCuteFiIcon,
|
||||
activeColor: colors.purple[500],
|
||||
translation: "title",
|
||||
view: FeedViewType.Audios,
|
||||
},
|
||||
{
|
||||
name: "Notifications",
|
||||
icon: AnnouncementCuteFiIcon,
|
||||
activeColor: colors.yellow[500],
|
||||
translation: "title",
|
||||
view: FeedViewType.Notifications,
|
||||
},
|
||||
]
|
||||
|
||||
@@ -16,7 +16,7 @@ import { ItemPressable } from "@/src/components/ui/pressable/item-pressable"
|
||||
import { useEntry } from "@/src/store/entry/hooks"
|
||||
import { debouncedFetchEntryContentByStream } from "@/src/store/entry/store"
|
||||
|
||||
import { useSelectedFeed } from "../feed-drawer/atoms"
|
||||
import { useFetchEntriesControls, useSelectedView } from "../feed-drawer/atoms"
|
||||
|
||||
export function EntryListContentGrid({
|
||||
entryIds,
|
||||
@@ -28,6 +28,9 @@ export function EntryListContentGrid({
|
||||
const tabBarHeight = useBottomTabBarHeight()
|
||||
const headerHeight = useHeaderHeight()
|
||||
const { scrollY } = useContext(NavigationContext)!
|
||||
|
||||
const { fetchNextPage } = useFetchEntriesControls()
|
||||
|
||||
return (
|
||||
<MasonryFlashList
|
||||
data={entryIds}
|
||||
@@ -38,6 +41,9 @@ export function EntryListContentGrid({
|
||||
onViewableItemsChanged={({ viewableItems }) => {
|
||||
debouncedFetchEntryContentByStream(viewableItems.map((item) => item.key))
|
||||
}}
|
||||
onEndReached={() => {
|
||||
fetchNextPage()
|
||||
}}
|
||||
numColumns={2}
|
||||
onScroll={useTypeScriptHappyCallback(
|
||||
(e) => {
|
||||
@@ -60,8 +66,7 @@ export function EntryListContentGrid({
|
||||
}
|
||||
|
||||
function RenderEntryItem({ id }: { id: string }) {
|
||||
const selectedFeed = useSelectedFeed()
|
||||
const view = selectedFeed.type === "view" ? selectedFeed.viewId : null
|
||||
const view = useSelectedView()
|
||||
const item = useEntry(id)
|
||||
if (!item) {
|
||||
return null
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { FeedViewType } from "@follow/constants"
|
||||
import { useTypeScriptHappyCallback } from "@follow/hooks"
|
||||
import { useBottomTabBarHeight } from "@react-navigation/bottom-tabs"
|
||||
import { BottomTabBarHeightContext } from "@react-navigation/bottom-tabs"
|
||||
import type { ListRenderItemInfo } from "@shopify/flash-list"
|
||||
import { FlashList } from "@shopify/flash-list"
|
||||
import { Image } from "expo-image"
|
||||
import { router } from "expo-router"
|
||||
import { useCallback, useContext, useMemo } from "react"
|
||||
import type { NativeScrollEvent, NativeSyntheticEvent } from "react-native"
|
||||
import { StyleSheet, Text, useAnimatedValue, View } from "react-native"
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context"
|
||||
|
||||
@@ -15,7 +16,12 @@ import {
|
||||
import { setWebViewEntry } from "@/src/components/native/webview/EntryContentWebView"
|
||||
import { ItemPressable } from "@/src/components/ui/pressable/item-pressable"
|
||||
import { useDefaultHeaderHeight } from "@/src/hooks/useDefaultHeaderHeight"
|
||||
import { useSelectedFeed, useSelectedFeedTitle } from "@/src/modules/feed-drawer/atoms"
|
||||
import {
|
||||
useEntryListContext,
|
||||
useFetchEntriesControls,
|
||||
useSelectedFeedTitle,
|
||||
useSelectedView,
|
||||
} from "@/src/modules/feed-drawer/atoms"
|
||||
import { useEntry } from "@/src/store/entry/hooks"
|
||||
import { debouncedFetchEntryContentByStream } from "@/src/store/entry/store"
|
||||
|
||||
@@ -28,29 +34,28 @@ const headerHideableBottomHeight = 58
|
||||
|
||||
export function EntryListScreen({ entryIds }: { entryIds: string[] }) {
|
||||
const scrollY = useAnimatedValue(0)
|
||||
const selectedFeed = useSelectedFeed()
|
||||
const view = selectedFeed.type === "view" ? selectedFeed.viewId : null
|
||||
const view = useSelectedView()
|
||||
const viewTitle = useSelectedFeedTitle()
|
||||
const screenType = useEntryListContext().type
|
||||
|
||||
return (
|
||||
<NavigationContext.Provider value={useMemo(() => ({ scrollY }), [scrollY])}>
|
||||
<NavigationBlurEffectHeader
|
||||
headerBackTitle={screenType === "feed" ? "Subscriptions" : undefined}
|
||||
headerShown
|
||||
headerTitle={viewTitle}
|
||||
headerLeft={useCallback(
|
||||
() => (
|
||||
<LeftAction />
|
||||
),
|
||||
[],
|
||||
() => (screenType === "timeline" ? <LeftAction /> : null),
|
||||
[screenType],
|
||||
)}
|
||||
headerRight={useCallback(
|
||||
() => (
|
||||
<RightAction />
|
||||
),
|
||||
[],
|
||||
() => (screenType === "timeline" ? <RightAction /> : null),
|
||||
[screenType],
|
||||
)}
|
||||
headerHideableBottomHeight={headerHideableBottomHeight}
|
||||
headerHideableBottom={ViewSelector}
|
||||
headerHideableBottomHeight={
|
||||
screenType === "timeline" ? headerHideableBottomHeight : undefined
|
||||
}
|
||||
headerHideableBottom={screenType === "timeline" ? ViewSelector : undefined}
|
||||
/>
|
||||
{view === FeedViewType.Pictures || view === FeedViewType.Videos ? (
|
||||
<EntryListContentGrid entryIds={entryIds} />
|
||||
@@ -61,42 +66,60 @@ export function EntryListScreen({ entryIds }: { entryIds: string[] }) {
|
||||
)
|
||||
}
|
||||
|
||||
function EntryListContent({ entryIds }: { entryIds: string[] }) {
|
||||
export function EntryListContent({ entryIds }: { entryIds: string[] }) {
|
||||
const screenType = useEntryListContext().type
|
||||
|
||||
const insets = useSafeAreaInsets()
|
||||
const tabBarHeight = useBottomTabBarHeight()
|
||||
|
||||
const originalDefaultHeaderHeight = useDefaultHeaderHeight()
|
||||
const headerHeight = originalDefaultHeaderHeight + headerHideableBottomHeight
|
||||
const { scrollY } = useContext(NavigationContext)!
|
||||
const headerHeight =
|
||||
screenType === "timeline"
|
||||
? originalDefaultHeaderHeight + headerHideableBottomHeight
|
||||
: originalDefaultHeaderHeight
|
||||
const scrollY = useContext(NavigationContext)?.scrollY
|
||||
|
||||
const { fetchNextPage, isFetchingNextPage } = useFetchEntriesControls()
|
||||
|
||||
const onScroll = useCallback(
|
||||
(e: NativeSyntheticEvent<NativeScrollEvent>) => {
|
||||
scrollY?.setValue(e.nativeEvent.contentOffset.y)
|
||||
},
|
||||
[scrollY],
|
||||
)
|
||||
|
||||
const renderItem = useCallback(
|
||||
({ item: id }: ListRenderItemInfo<string>) => <EntryItem key={id} entryId={id} />,
|
||||
[],
|
||||
)
|
||||
|
||||
return (
|
||||
<FlashList
|
||||
onScroll={useTypeScriptHappyCallback(
|
||||
(e) => {
|
||||
scrollY.setValue(e.nativeEvent.contentOffset.y)
|
||||
},
|
||||
[scrollY],
|
||||
<BottomTabBarHeightContext.Consumer>
|
||||
{(tabBarHeight) => (
|
||||
<FlashList
|
||||
onScroll={onScroll}
|
||||
data={entryIds}
|
||||
renderItem={renderItem}
|
||||
keyExtractor={(id) => id}
|
||||
onEndReached={() => {
|
||||
fetchNextPage()
|
||||
}}
|
||||
onViewableItemsChanged={({ viewableItems }) => {
|
||||
debouncedFetchEntryContentByStream(viewableItems.map((item) => item.key))
|
||||
}}
|
||||
scrollIndicatorInsets={{
|
||||
top: headerHeight - insets.top,
|
||||
bottom: tabBarHeight ? tabBarHeight - insets.bottom : undefined,
|
||||
}}
|
||||
estimatedItemSize={100}
|
||||
contentContainerStyle={{
|
||||
paddingTop: headerHeight,
|
||||
paddingBottom: tabBarHeight,
|
||||
}}
|
||||
ItemSeparatorComponent={ItemSeparator}
|
||||
ListFooterComponent={isFetchingNextPage ? <EntryItemSkeleton /> : null}
|
||||
/>
|
||||
)}
|
||||
data={entryIds}
|
||||
renderItem={useTypeScriptHappyCallback(
|
||||
({ item: id }) => (
|
||||
<EntryItem key={id} entryId={id} />
|
||||
),
|
||||
[],
|
||||
)}
|
||||
keyExtractor={(id) => id}
|
||||
onViewableItemsChanged={({ viewableItems }) => {
|
||||
debouncedFetchEntryContentByStream(viewableItems.map((item) => item.key))
|
||||
}}
|
||||
scrollIndicatorInsets={{
|
||||
top: headerHeight - insets.top,
|
||||
bottom: tabBarHeight - insets.bottom,
|
||||
}}
|
||||
estimatedItemSize={100}
|
||||
contentContainerStyle={{
|
||||
paddingTop: headerHeight,
|
||||
paddingBottom: tabBarHeight,
|
||||
}}
|
||||
ItemSeparatorComponent={ItemSeparator}
|
||||
/>
|
||||
</BottomTabBarHeightContext.Consumer>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ export function EntryList() {
|
||||
}, [setDrawerSwipeDisabled, isFocused])
|
||||
|
||||
const selectedFeed = useSelectedFeed()
|
||||
if (!selectedFeed) return null
|
||||
|
||||
switch (selectedFeed.type) {
|
||||
case "view": {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { FeedViewType } from "@follow/constants"
|
||||
import { jotaiStore } from "@follow/utils"
|
||||
import { atom, useAtom, useAtomValue, useSetAtom } from "jotai"
|
||||
import { useCallback, useMemo } from "react"
|
||||
import { createContext, useCallback, useContext, useMemo } from "react"
|
||||
|
||||
import { views } from "@/src/constants/views"
|
||||
import { usePrefetchEntries } from "@/src/store/entry/hooks"
|
||||
@@ -11,6 +11,7 @@ import { useFeed } from "@/src/store/feed/hooks"
|
||||
import { useInbox } from "@/src/store/inbox/hooks"
|
||||
import { useList } from "@/src/store/list/hooks"
|
||||
import { getSubscriptionByCategory } from "@/src/store/subscription/getter"
|
||||
import { useSubscription } from "@/src/store/subscription/hooks"
|
||||
|
||||
// drawer open state
|
||||
|
||||
@@ -64,25 +65,17 @@ export function useSelectedCollection() {
|
||||
export const selectCollection = (state: CollectionPanelState) => {
|
||||
jotaiStore.set(collectionPanelStateAtom, state)
|
||||
if (state.type === "view" || state.type === "list") {
|
||||
jotaiStore.set(selectedFeedAtom, state)
|
||||
jotaiStore.set(selectedTimelineAtom, state)
|
||||
}
|
||||
}
|
||||
|
||||
// feed panel selected state
|
||||
|
||||
export type SelectedFeed =
|
||||
export type SelectedTimeline =
|
||||
| {
|
||||
type: "view"
|
||||
viewId: FeedViewType
|
||||
}
|
||||
| {
|
||||
type: "feed"
|
||||
feedId: string
|
||||
}
|
||||
| {
|
||||
type: "category"
|
||||
categoryName: string
|
||||
}
|
||||
| {
|
||||
type: "list"
|
||||
listId: string
|
||||
@@ -92,13 +85,55 @@ export type SelectedFeed =
|
||||
inboxId: string
|
||||
}
|
||||
|
||||
const selectedFeedAtom = atom<SelectedFeed>({
|
||||
export type SelectedFeed =
|
||||
| {
|
||||
type: "feed"
|
||||
feedId: string
|
||||
}
|
||||
| {
|
||||
type: "category"
|
||||
categoryName: string
|
||||
}
|
||||
| null
|
||||
|
||||
const selectedTimelineAtom = atom<SelectedTimeline>({
|
||||
type: "view",
|
||||
viewId: FeedViewType.Articles,
|
||||
})
|
||||
|
||||
export function useSelectedFeed() {
|
||||
const selectedFeedAtom = atom<SelectedFeed>(null)
|
||||
|
||||
export const EntryListContext = createContext<{ type: "timeline" | "feed" }>({ type: "timeline" })
|
||||
export const useEntryListContext = () => {
|
||||
return useContext(EntryListContext)
|
||||
}
|
||||
|
||||
export function useSelectedView() {
|
||||
const selectedTimeLine = useAtomValue(selectedTimelineAtom)
|
||||
const selectedFeed = useAtomValue(selectedFeedAtom)
|
||||
|
||||
const list = useList(selectedTimeLine.type === "list" ? selectedTimeLine.listId : "")
|
||||
const subscription = useSubscription(
|
||||
selectedFeed && selectedFeed.type === "feed" ? selectedFeed.feedId : "",
|
||||
)
|
||||
const view =
|
||||
selectedTimeLine.type === "view"
|
||||
? selectedTimeLine.viewId
|
||||
: selectedTimeLine.type === "list"
|
||||
? list?.view
|
||||
: selectedFeed?.type === "feed"
|
||||
? subscription?.view
|
||||
: undefined
|
||||
return view
|
||||
}
|
||||
|
||||
function getFetchEntryPayload(
|
||||
selectedFeed: SelectedTimeline | SelectedFeed,
|
||||
): FetchEntriesProps | null {
|
||||
if (!selectedFeed) {
|
||||
return null
|
||||
}
|
||||
|
||||
let payload: FetchEntriesProps = {}
|
||||
switch (selectedFeed.type) {
|
||||
case "view": {
|
||||
@@ -123,16 +158,42 @@ export function useSelectedFeed() {
|
||||
}
|
||||
// No default
|
||||
}
|
||||
return payload
|
||||
}
|
||||
|
||||
export function useSelectedFeed() {
|
||||
const entryListContext = useEntryListContext()
|
||||
|
||||
const selectedTimeline = useAtomValue(selectedTimelineAtom)
|
||||
const selectedFeed = useAtomValue(selectedFeedAtom)
|
||||
|
||||
const payload = getFetchEntryPayload(
|
||||
entryListContext.type === "feed" ? selectedFeed : selectedTimeline,
|
||||
)
|
||||
usePrefetchEntries(payload)
|
||||
return selectedFeed
|
||||
|
||||
return entryListContext.type === "feed" ? selectedFeed : selectedTimeline
|
||||
}
|
||||
|
||||
export function useFetchEntriesControls() {
|
||||
const selectedFeed = useSelectedFeed()
|
||||
const payload = getFetchEntryPayload(selectedFeed)
|
||||
return usePrefetchEntries(payload)
|
||||
}
|
||||
|
||||
export const useSelectedFeedTitle = () => {
|
||||
const selectedFeed = useSelectedFeed()
|
||||
const viewDef = useViewDefinition(selectedFeed.type === "view" ? selectedFeed.viewId : undefined)
|
||||
const feed = useFeed(selectedFeed.type === "feed" ? selectedFeed.feedId : "")
|
||||
const list = useList(selectedFeed.type === "list" ? selectedFeed.listId : "")
|
||||
const inbox = useInbox(selectedFeed.type === "inbox" ? selectedFeed.inboxId : "")
|
||||
|
||||
const viewDef = useViewDefinition(
|
||||
selectedFeed && selectedFeed.type === "view" ? selectedFeed.viewId : undefined,
|
||||
)
|
||||
const feed = useFeed(selectedFeed && selectedFeed.type === "feed" ? selectedFeed.feedId : "")
|
||||
const list = useList(selectedFeed && selectedFeed.type === "list" ? selectedFeed.listId : "")
|
||||
const inbox = useInbox(selectedFeed && selectedFeed.type === "inbox" ? selectedFeed.inboxId : "")
|
||||
|
||||
if (!selectedFeed) {
|
||||
return ""
|
||||
}
|
||||
|
||||
switch (selectedFeed.type) {
|
||||
case "view": {
|
||||
@@ -153,6 +214,10 @@ export const useSelectedFeedTitle = () => {
|
||||
}
|
||||
}
|
||||
|
||||
export const selectTimeline = (state: SelectedTimeline) => {
|
||||
jotaiStore.set(selectedTimelineAtom, state)
|
||||
}
|
||||
|
||||
export const selectFeed = (state: SelectedFeed) => {
|
||||
jotaiStore.set(selectedFeedAtom, state)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { cn } from "@follow/utils"
|
||||
import { BottomTabBarHeightContext } from "@react-navigation/bottom-tabs"
|
||||
import { HeaderHeightContext } from "@react-navigation/elements"
|
||||
import { router } from "expo-router"
|
||||
import type { FC } from "react"
|
||||
import { createContext, memo, useContext, useState } from "react"
|
||||
import {
|
||||
@@ -155,6 +156,7 @@ const CategoryGrouped = memo(
|
||||
categoryName: category,
|
||||
})
|
||||
closeDrawer()
|
||||
router.push(`/feeds/${category}`)
|
||||
}}
|
||||
className="h-12 flex-row items-center px-3"
|
||||
>
|
||||
|
||||
@@ -9,7 +9,7 @@ import { useList } from "@/src/store/list/hooks"
|
||||
import { useAllListSubscription } from "@/src/store/subscription/hooks"
|
||||
import { useColor } from "@/src/theme/colors"
|
||||
|
||||
import { selectFeed, useSelectedFeed } from "../feed-drawer/atoms"
|
||||
import { selectTimeline, useSelectedFeed } from "../feed-drawer/atoms"
|
||||
|
||||
export function ViewSelector() {
|
||||
const lists = useAllListSubscription()
|
||||
@@ -33,15 +33,15 @@ export function ViewSelector() {
|
||||
}
|
||||
|
||||
function ViewItem({ view }: { view: ViewDefinition }) {
|
||||
const selectedFeed = useSelectedFeed()
|
||||
const isActive = selectedFeed.type === "view" && selectedFeed.viewId === view.view
|
||||
|
||||
const bgColor = useColor("gray2")
|
||||
const selectedFeed = useSelectedFeed()
|
||||
if (!selectedFeed) return null
|
||||
const isActive = selectedFeed.type === "view" && selectedFeed.viewId === view.view
|
||||
|
||||
return (
|
||||
<TouchableOpacity
|
||||
className="relative flex size-12 items-center justify-center overflow-hidden rounded-full"
|
||||
onPress={() => selectFeed({ type: "view", viewId: view.view })}
|
||||
onPress={() => selectTimeline({ type: "view", viewId: view.view })}
|
||||
style={{
|
||||
backgroundColor: isActive ? view.activeColor : bgColor,
|
||||
}}
|
||||
@@ -54,6 +54,7 @@ function ViewItem({ view }: { view: ViewDefinition }) {
|
||||
function ListItem({ listId }: { listId: string }) {
|
||||
const list = useList(listId)
|
||||
const selectedFeed = useSelectedFeed()
|
||||
if (!selectedFeed) return null
|
||||
const isActive = selectedFeed.type === "list" && selectedFeed.listId === listId
|
||||
|
||||
if (!list) return null
|
||||
@@ -61,7 +62,7 @@ function ListItem({ listId }: { listId: string }) {
|
||||
return (
|
||||
<TouchableOpacity
|
||||
className="relative flex size-12 items-center justify-center overflow-hidden rounded-full"
|
||||
onPress={() => selectFeed({ type: "list", listId })}
|
||||
onPress={() => selectTimeline({ type: "list", listId })}
|
||||
>
|
||||
{list.image ? (
|
||||
isActive ? (
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { router } from "expo-router"
|
||||
import { memo, useState } from "react"
|
||||
import { Text, TouchableOpacity } from "react-native"
|
||||
import Animated, { useAnimatedStyle, useSharedValue, withSpring } from "react-native-reanimated"
|
||||
@@ -49,6 +50,7 @@ export const CategoryGrouped = memo(
|
||||
categoryName: category,
|
||||
})
|
||||
closeDrawer()
|
||||
router.push(`/feeds/${category}`)
|
||||
}}
|
||||
className="h-12 flex-row items-center px-3"
|
||||
>
|
||||
|
||||
@@ -9,7 +9,7 @@ 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"
|
||||
import { closeDrawer, selectTimeline } from "../../feed-drawer/atoms"
|
||||
|
||||
export const InboxItem = memo(({ id }: { id: string }) => {
|
||||
const subscription = useSubscription(getInboxStoreId(id))
|
||||
@@ -21,7 +21,7 @@ export const InboxItem = memo(({ id }: { id: string }) => {
|
||||
<ItemPressable
|
||||
className="h-12 flex-row items-center px-3"
|
||||
onPress={() => {
|
||||
selectFeed({ type: "inbox", inboxId: id })
|
||||
selectTimeline({ type: "inbox", inboxId: id })
|
||||
closeDrawer()
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -8,7 +8,7 @@ import { useList } from "@/src/store/list/hooks"
|
||||
import { useUnreadCount } from "@/src/store/unread/hooks"
|
||||
|
||||
import { SubscriptionListItemContextMenu } from "../../context-menu/lists"
|
||||
import { closeDrawer, selectFeed } from "../../feed-drawer/atoms"
|
||||
import { closeDrawer, selectTimeline } from "../../feed-drawer/atoms"
|
||||
|
||||
export const ListSubscriptionItem = memo(({ id }: { id: string; className?: string }) => {
|
||||
const list = useList(id)
|
||||
@@ -20,7 +20,7 @@ export const ListSubscriptionItem = memo(({ id }: { id: string; className?: stri
|
||||
<ItemPressable
|
||||
className="h-12 flex-row items-center px-3"
|
||||
onPress={() => {
|
||||
selectFeed({
|
||||
selectTimeline({
|
||||
type: "list",
|
||||
listId: id,
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { cn } from "@follow/utils"
|
||||
import { router } from "expo-router"
|
||||
import { memo, useContext } from "react"
|
||||
import { ActivityIndicator, Text, View } from "react-native"
|
||||
import Animated, { FadeOutUp } from "react-native-reanimated"
|
||||
@@ -92,6 +93,7 @@ export const SubscriptionItem = memo(({ id, className }: { id: string; className
|
||||
feedId: id,
|
||||
})
|
||||
closeDrawer()
|
||||
router.push(`/feeds/${id}`)
|
||||
}}
|
||||
>
|
||||
<View className="dark:border-tertiary-system-background mr-3 size-5 items-center justify-center overflow-hidden rounded-full border border-transparent dark:bg-[#222]">
|
||||
|
||||
@@ -1,37 +1,19 @@
|
||||
import { Stack, useLocalSearchParams } from "expo-router"
|
||||
import { ScrollView, Text, View } from "react-native"
|
||||
import { useLocalSearchParams } from "expo-router"
|
||||
import { useMemo } from "react"
|
||||
|
||||
import { BlurEffect } from "@/src/components/common/BlurEffect"
|
||||
import { EntryListScreen } from "@/src/modules/entry-list/entry-list"
|
||||
import { EntryListContext } from "@/src/modules/feed-drawer/atoms"
|
||||
import { useEntryIdsByCategory, useEntryIdsByFeedId } from "@/src/store/entry/hooks"
|
||||
|
||||
export default function Feed() {
|
||||
const { feedId } = useLocalSearchParams()
|
||||
|
||||
const { feedId: feedIdOrCategory } = useLocalSearchParams()
|
||||
const entryIdsByFeedId = useEntryIdsByFeedId(feedIdOrCategory as string)
|
||||
const entryIdsByCategory = useEntryIdsByCategory(feedIdOrCategory as string)
|
||||
return (
|
||||
<View>
|
||||
<Stack.Screen
|
||||
options={{
|
||||
headerShown: true,
|
||||
headerBackTitle: "Subscriptions",
|
||||
headerBackground: BlurEffect,
|
||||
|
||||
headerTransparent: true,
|
||||
headerTitle: "Feed",
|
||||
}}
|
||||
<EntryListContext.Provider value={useMemo(() => ({ type: "feed" }), [])}>
|
||||
<EntryListScreen
|
||||
entryIds={entryIdsByFeedId.length > 0 ? entryIdsByFeedId : entryIdsByCategory}
|
||||
/>
|
||||
<ScrollView contentInsetAdjustmentBehavior="automatic" className="h-full">
|
||||
<Text>Feed {feedId}</Text>
|
||||
<Text>Feed {feedId}</Text>
|
||||
<Text>Feed {feedId}</Text>
|
||||
<Text>Feed {feedId}</Text>
|
||||
<Text>Feed {feedId}</Text>
|
||||
<Text>Feed {feedId}</Text>
|
||||
<Text>Feed {feedId}</Text>
|
||||
<Text>Feed {feedId}</Text>
|
||||
<Text>Feed {feedId}</Text>
|
||||
<Text>Feed {feedId}</Text>
|
||||
<Text>Feed {feedId}</Text>
|
||||
<Text>Feed {feedId}</Text>
|
||||
</ScrollView>
|
||||
</View>
|
||||
</EntryListContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,16 +1,24 @@
|
||||
import type { FeedViewType } from "@follow/constants"
|
||||
import { useMutation, useQuery } from "@tanstack/react-query"
|
||||
import { useInfiniteQuery, useMutation, useQuery } from "@tanstack/react-query"
|
||||
import { useCallback, useEffect } from "react"
|
||||
|
||||
import { getEntry } from "./getter"
|
||||
import { entrySyncServices, useEntryStore } from "./store"
|
||||
import type { EntryModel, FetchEntriesProps } from "./types"
|
||||
|
||||
export const usePrefetchEntries = (props: FetchEntriesProps) => {
|
||||
const { feedId, inboxId, listId, view, read, limit, pageParam, isArchived } = props
|
||||
return useQuery({
|
||||
queryKey: ["entries", feedId, inboxId, listId, view, read, limit, pageParam, isArchived],
|
||||
queryFn: () => entrySyncServices.fetchEntries(props),
|
||||
export const usePrefetchEntries = (props: Omit<FetchEntriesProps, "pageParam"> | null) => {
|
||||
const { feedId, inboxId, listId, view, read, limit, isArchived } = props || {}
|
||||
return useInfiniteQuery({
|
||||
queryKey: ["entries", feedId, inboxId, listId, view, read, limit, isArchived],
|
||||
queryFn: ({ pageParam }) => entrySyncServices.fetchEntries({ ...props, pageParam }),
|
||||
getNextPageParam: (lastPage) =>
|
||||
inboxId || listId
|
||||
? lastPage.data?.at(-1)?.entries.insertedAt
|
||||
: lastPage.data?.at(-1)?.entries.publishedAt,
|
||||
initialPageParam: undefined as undefined | string,
|
||||
refetchOnWindowFocus: false,
|
||||
refetchOnReconnect: false,
|
||||
enabled: !!props,
|
||||
})
|
||||
}
|
||||
export const usePrefetchEntryContent = (entryId: string) => {
|
||||
|
||||
@@ -45,7 +45,6 @@ const defaultState: EntryState = {
|
||||
|
||||
export const useEntryStore = createZustandStore<EntryState>("entry")(() => defaultState)
|
||||
|
||||
const set = useEntryStore.setState
|
||||
const immerSet = createImmerSetter(useEntryStore)
|
||||
|
||||
class EntryActions {
|
||||
@@ -155,19 +154,16 @@ class EntryActions {
|
||||
await tx.run()
|
||||
}
|
||||
|
||||
reset(entries: EntryModel[] = []) {
|
||||
if (entries.length > 0) {
|
||||
immerSet((draft) => {
|
||||
// remove all entries from draft.data not in entries
|
||||
for (const existingEntry of Object.values(draft.data)) {
|
||||
if (!entries.some((e) => e.id === existingEntry.id)) {
|
||||
delete draft.data[existingEntry.id]
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
set(defaultState)
|
||||
}
|
||||
resetByView({ view, entries }: { view: FeedViewType; entries: EntryModel[] }) {
|
||||
immerSet((draft) => {
|
||||
draft.entryIdByView[view] = new Set(entries.map((e) => e.id))
|
||||
})
|
||||
}
|
||||
|
||||
resetByCategory({ category, entries }: { category: Category; entries: EntryModel[] }) {
|
||||
immerSet((draft) => {
|
||||
draft.entryIdByCategory[category] = new Set(entries.map((e) => e.id))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,7 +202,22 @@ class EntrySyncServices {
|
||||
entryIds: entries.map((e) => e.id),
|
||||
})
|
||||
}
|
||||
return entries
|
||||
|
||||
// After initial fetch, we can reset the state to prefer the entries data from the server
|
||||
if (!pageParam) {
|
||||
if (view !== undefined) {
|
||||
entryActions.resetByView({ view, entries })
|
||||
}
|
||||
|
||||
if (params.feedIdList && params.feedIdList.length > 0) {
|
||||
const category = getSubscription(params.feedIdList[0]!)?.category
|
||||
if (category) {
|
||||
entryActions.resetByCategory({ category, entries })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
async fetchEntryContent(entryId: EntryId) {
|
||||
|
||||
Reference in New Issue
Block a user