Skip to content

Commit

Permalink
fix: back to previous entry list will refresh data
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <tukon479@gmail.com>
  • Loading branch information
Innei committed Dec 9, 2024
1 parent ab85406 commit 84a188a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
5 changes: 5 additions & 0 deletions apps/renderer/src/atoms/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const useFeedUnreadIsDirty = (feedId: string) => {
() =>
selectAtom(feedUnreadDirtySetAtom, (set) => {
const isRealFeedId = isBizId(feedId)

if (isRealFeedId) return set.has(feedId)

if (feedId.startsWith(ROUTE_FEED_IN_LIST) || feedId.startsWith(INBOX_PREFIX_ID)) {
Expand Down Expand Up @@ -67,3 +68,7 @@ export const clearFeedUnreadDirty = (feedId: string) => {
return newSet
})
}

export const clearAllFeedUnreadDirty = () => {
jotaiStore.set(feedUnreadDirtySetAtom, new Set())
}
17 changes: 10 additions & 7 deletions apps/renderer/src/queries/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,20 @@ export const useEntries = ({
initialPageParam: undefined,
refetchOnWindowFocus: false,
refetchOnReconnect: false,
refetchOnMount: fetchUnread && feedUnreadDirty ? "always" : false,
// DON'T refetch when the router is pop to previous page
refetchOnMount: fetchUnread && feedUnreadDirty && !history.isPop ? "always" : false,

staleTime:
// Force refetch unread entries when feed is dirty
// HACK: disable refetch when the router is pop to previous page
fetchUnread && feedUnreadDirty && !history.isPop
? 0
: // Keep reduce data fetch logic
reduceRefetch
? maxStaleTime
: defaultStaleTime,
history.isPop
? Infinity
: fetchUnread && feedUnreadDirty
? 0
: // Keep reduce data fetch logic
reduceRefetch
? maxStaleTime
: defaultStaleTime,
},
)
}
Expand Down
9 changes: 6 additions & 3 deletions apps/renderer/src/store/entry/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { omitObjectUndefinedValue } from "@follow/utils/utils"
import { isNil, merge, omit } from "es-toolkit/compat"
import { produce } from "immer"

import { clearFeedUnreadDirty, setFeedUnreadDirty } from "~/atoms/feed"
import { clearAllFeedUnreadDirty, clearFeedUnreadDirty, setFeedUnreadDirty } from "~/atoms/feed"
import { runTransactionInScope } from "~/database"
import { apiClient } from "~/lib/api-fetch"
import { getEntriesParams } from "~/lib/utils"
Expand Down Expand Up @@ -147,7 +147,7 @@ class EntryActions {
})

if (data.data) {
this.upsertMany(data.data, { isArchived })
this.upsertMany(structuredClone(data.data), { isArchived })
}
return data
}
Expand All @@ -170,6 +170,9 @@ class EntryActions {

// Mark feed unread dirty, so re-fetch the unread data when view feed unread entires in the next time
if (read === false) {
if (typeof params.view === "number" && !params.feedId) {
clearAllFeedUnreadDirty()
}
if (params.feedId) {
clearFeedUnreadDirty(params.feedId as string)
}
Expand All @@ -180,7 +183,7 @@ class EntryActions {
}
}
if (data.data) {
this.upsertMany(data.data, { isArchived })
this.upsertMany(structuredClone(data.data), { isArchived })
}
return data
}
Expand Down

0 comments on commit 84a188a

Please sign in to comment.