refactor(mobile): remove load archived entries button (#2774)

This commit is contained in:
Stephen Zhou 2025-02-17 14:50:55 +08:00 committed by GitHub
parent 4295decfa9
commit fc70859fe9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 36 additions and 113 deletions

View File

@ -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 (
<View className="items-center pt-2">
<TouchableOpacity
onPress={() => {
setIsLoadingArchivedEntries(true)
}}
>
<Text className="text-label">Load archived entries</Text>
</TouchableOpacity>
</View>
)
}

View File

@ -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 ? <EntryItemSkeleton /> : screenType === "feed" ? <LoadArchiveButton /> : null,
[isFetching, screenType],
() => (isFetching ? <EntryItemSkeleton /> : null),
[isFetching],
)
return (

View File

@ -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 ? <EntryItemSkeleton /> : screenType === "feed" ? <LoadArchiveButton /> : null,
[isFetching, screenType],
() => (isFetching ? <EntryItemSkeleton /> : null),
[isFetching],
)
return (

View File

@ -103,15 +103,6 @@ const selectedTimelineAtom = atom<SelectedTimeline>({
const selectedFeedAtom = atom<SelectedFeed>(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) => {

View File

@ -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)))
}
}

View File

@ -50,8 +50,6 @@ export const useEntryStore = createZustandStore<EntryState>("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 })
}
}