diff --git a/apps/mobile/src/modules/entry-list/action.tsx b/apps/mobile/src/modules/entry-list/action.tsx deleted file mode 100644 index 189c47357..000000000 --- a/apps/mobile/src/modules/entry-list/action.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import { Text, TouchableOpacity, View } from "react-native" - -import { - setIsLoadingArchivedEntries, - useIsLoadingArchivedEntries, -} from "@/src/modules/screen/atoms" - -export function LoadArchiveButton() { - const isLoadingArchivedEntries = useIsLoadingArchivedEntries() - if (isLoadingArchivedEntries) return null - return ( - - { - setIsLoadingArchivedEntries(true) - }} - > - Load archived entries - - - ) -} diff --git a/apps/mobile/src/modules/entry-list/entry-list-article.tsx b/apps/mobile/src/modules/entry-list/entry-list-article.tsx index 1ddb4e3a8..6759864c6 100644 --- a/apps/mobile/src/modules/entry-list/entry-list-article.tsx +++ b/apps/mobile/src/modules/entry-list/entry-list-article.tsx @@ -9,19 +9,16 @@ import { setWebViewEntry } from "@/src/components/native/webview/EntryContentWeb import { FeedIcon } from "@/src/components/ui/icon/feed-icon" import { ItemPressable } from "@/src/components/ui/pressable/ItemPressable" import { gentleSpringPreset } from "@/src/constants/spring" -import { useEntryListContext, useFetchEntriesControls } from "@/src/modules/feed-drawer/atoms" +import { useFetchEntriesControls } from "@/src/modules/feed-drawer/atoms" import { useEntry } from "@/src/store/entry/hooks" import { debouncedFetchEntryContentByStream } from "@/src/store/entry/store" import { useFeed } from "@/src/store/feed/hooks" import { EntryItemContextMenu } from "../context-menu/entry" import { TimelineSelectorList } from "../screen/TimelineSelectorList" -import { LoadArchiveButton } from "./action" import { ItemSeparator } from "./ItemSeparator" export function EntryListContentArticle({ entryIds }: { entryIds: string[] }) { - const screenType = useEntryListContext().type - const { fetchNextPage, isFetching, refetch, isRefetching } = useFetchEntriesControls() const renderItem = useCallback( @@ -30,9 +27,8 @@ export function EntryListContentArticle({ entryIds }: { entryIds: string[] }) { ) const ListFooterComponent = useMemo( - () => - isFetching ? : screenType === "feed" ? : null, - [isFetching, screenType], + () => (isFetching ? : null), + [isFetching], ) return ( diff --git a/apps/mobile/src/modules/entry-list/entry-list-social.tsx b/apps/mobile/src/modules/entry-list/entry-list-social.tsx index 223fb3d0d..6a85ca0cc 100644 --- a/apps/mobile/src/modules/entry-list/entry-list-social.tsx +++ b/apps/mobile/src/modules/entry-list/entry-list-social.tsx @@ -11,18 +11,15 @@ import { ItemPressableStyle } from "@/src/components/ui/pressable/enum" import { ItemPressable } from "@/src/components/ui/pressable/ItemPressable" import { gentleSpringPreset } from "@/src/constants/spring" import { quickLookImage } from "@/src/lib/native" -import { useEntryListContext, useFetchEntriesControls } from "@/src/modules/feed-drawer/atoms" +import { useFetchEntriesControls } from "@/src/modules/feed-drawer/atoms" import { useEntry } from "@/src/store/entry/hooks" import { debouncedFetchEntryContentByStream } from "@/src/store/entry/store" import { EntryItemContextMenu } from "../context-menu/entry" import { TimelineSelectorList } from "../screen/TimelineSelectorList" -import { LoadArchiveButton } from "./action" import { ItemSeparatorFullWidth } from "./ItemSeparator" export function EntryListContentSocial({ entryIds }: { entryIds: string[] }) { - const screenType = useEntryListContext().type - const { fetchNextPage, isFetching, refetch, isRefetching } = useFetchEntriesControls() const renderItem = useCallback( @@ -31,9 +28,8 @@ export function EntryListContentSocial({ entryIds }: { entryIds: string[] }) { ) const ListFooterComponent = useMemo( - () => - isFetching ? : screenType === "feed" ? : null, - [isFetching, screenType], + () => (isFetching ? : null), + [isFetching], ) return ( diff --git a/apps/mobile/src/modules/screen/atoms.ts b/apps/mobile/src/modules/screen/atoms.ts index c4b5af482..8be468fdb 100644 --- a/apps/mobile/src/modules/screen/atoms.ts +++ b/apps/mobile/src/modules/screen/atoms.ts @@ -103,15 +103,6 @@ const selectedTimelineAtom = atom({ const selectedFeedAtom = atom(null) -const isLoadingArchivedEntriesAtom = atom(false) - -export const useIsLoadingArchivedEntries = () => { - return useAtomValue(isLoadingArchivedEntriesAtom) -} -export const setIsLoadingArchivedEntries = (isLoading: boolean) => { - jotaiStore.set(isLoadingArchivedEntriesAtom, isLoading) -} - export const EntryListContext = createContext<{ type: "timeline" | "feed" }>({ type: "timeline" }) export const useEntryListContext = () => { return useContext(EntryListContext) @@ -138,7 +129,6 @@ export function useSelectedView() { function getFetchEntryPayload( selectedFeed: SelectedTimeline | SelectedFeed, - isArchived = false, ): FetchEntriesProps | null { if (!selectedFeed) { return null @@ -169,7 +159,6 @@ function getFetchEntryPayload( // No default } - payload.isArchived = isArchived return payload } @@ -179,10 +168,8 @@ export function useSelectedFeed() { const selectedTimeline = useAtomValue(selectedTimelineAtom) const selectedFeed = useAtomValue(selectedFeedAtom) - const isArchived = useIsLoadingArchivedEntries() const payload = getFetchEntryPayload( entryListContext.type === "feed" ? selectedFeed : selectedTimeline, - entryListContext.type === "feed" ? isArchived : false, ) usePrefetchEntries(payload) @@ -190,15 +177,9 @@ export function useSelectedFeed() { } export function useFetchEntriesControls() { - const entryListContext = useEntryListContext() - const selectedFeed = useSelectedFeed() - const isArchived = useIsLoadingArchivedEntries() - const payload = getFetchEntryPayload( - selectedFeed, - entryListContext.type === "feed" ? isArchived : false, - ) + const payload = getFetchEntryPayload(selectedFeed) return usePrefetchEntries(payload) } @@ -241,7 +222,6 @@ export const selectTimeline = (state: SelectedTimeline) => { export const selectFeed = (state: SelectedFeed) => { jotaiStore.set(selectedFeedAtom, state) - jotaiStore.set(isLoadingArchivedEntriesAtom, false) } export const useViewDefinition = (view?: FeedViewType) => { diff --git a/apps/mobile/src/services/entry.ts b/apps/mobile/src/services/entry.ts index e6d6e95fd..dd15cad45 100644 --- a/apps/mobile/src/services/entry.ts +++ b/apps/mobile/src/services/entry.ts @@ -52,11 +52,7 @@ class EntryServiceStatic implements Hydratable, Resetable { async hydrate() { const entries = await db.query.entriesTable.findMany() - // TODO: Find a way to determine whether entry is archived, and then only hydrate unarchived entries - entryActions.upsertManyInSession( - entries.map((e) => dbStoreMorph.toEntryModel(e)), - "view", - ) + entryActions.upsertManyInSession(entries.map((e) => dbStoreMorph.toEntryModel(e))) } } diff --git a/apps/mobile/src/store/entry/store.ts b/apps/mobile/src/store/entry/store.ts index 6ce61d66b..d8fceb661 100644 --- a/apps/mobile/src/store/entry/store.ts +++ b/apps/mobile/src/store/entry/store.ts @@ -50,8 +50,6 @@ export const useEntryStore = createZustandStore("entry")(() => defau const immerSet = createImmerSetter(useEntryStore) -type UpsertPosition = "all" | "view" | "category" | "feed" | "inbox" | "list" - class EntryActions { private addEntryIdToView({ draft, @@ -126,7 +124,7 @@ class EntryActions { } } - upsertManyInSession(entries: EntryModel[], position: UpsertPosition) { + upsertManyInSession(entries: EntryModel[]) { if (entries.length === 0) return immerSet((draft) => { @@ -135,45 +133,37 @@ class EntryActions { draft.data[entry.id] = entry const { feedId, inboxHandle } = entry - if (position === "all" || position === "feed") { - this.addEntryIdToFeed({ - draft, - feedId, - entryId: entry.id, - }) - } + this.addEntryIdToFeed({ + draft, + feedId, + entryId: entry.id, + }) - if (position === "all" || position === "view") { - this.addEntryIdToView({ - draft, - feedId, - entryId: entry.id, - }) - } + this.addEntryIdToView({ + draft, + feedId, + entryId: entry.id, + }) - if (position === "all" || position === "inbox") { - this.addEntryIdToInbox({ - draft, - inboxHandle, - entryId: entry.id, - }) - } + this.addEntryIdToInbox({ + draft, + inboxHandle, + entryId: entry.id, + }) - if (position === "all" || position === "category") { - this.addEntryIdToCategory({ - draft, - feedId, - entryId: entry.id, - }) - } + this.addEntryIdToCategory({ + draft, + feedId, + entryId: entry.id, + }) } }) } - async upsertMany(entries: EntryModel[], position: UpsertPosition) { + async upsertMany(entries: EntryModel[]) { const tx = createTransaction() tx.store(() => { - this.upsertManyInSession(entries, position) + this.upsertManyInSession(entries) }) tx.persist(() => { @@ -290,20 +280,7 @@ class EntrySyncServices { } } - const position = - params.view !== undefined - ? "view" - : params.feedId - ? "feed" - : params.feedIdList - ? "category" - : params.inboxId - ? "inbox" - : params.listId - ? "list" - : "all" - - await entryActions.upsertMany(entries, position) + await entryActions.upsertMany(entries) if (params.listId) { await listActions.addEntryIds({ listId: params.listId, @@ -313,18 +290,18 @@ class EntrySyncServices { // After initial fetch, we can reset the state to prefer the entries data from the server if (!pageParam) { - if (position === "view") { + if (params.view !== undefined) { entryActions.resetByView({ view: params.view, entries }) } - if (position === "category") { - const category = getSubscription(params.feedIdList?.[0])?.category + if (params.feedIdList && params.feedIdList.length > 0) { + const category = getSubscription(params.feedIdList[0])?.category if (category) { entryActions.resetByCategory({ category, entries }) } } - if (position === "feed") { + if (params.feedId) { entryActions.resetByFeed({ feedId: params.feedId, entries }) } }