Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: auto archived list flash #1269

Merged
merged 5 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions apps/renderer/src/modules/entry-column/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,15 @@ export const useEntriesByView = ({
const isFetchingFirstPage = query.isFetching && !query.isFetchingNextPage

useEffect(() => {
if (isArchived) {
return
}
if (!isFetchingFirstPage) {
prevEntryIdsRef.current = entryIds
setMergedEntries({ ...mergedEntries, [view]: entryIds })
onReset?.()
}
}, [isFetchingFirstPage])
}, [isFetchingFirstPage, isArchived])

const [mergedEntries, setMergedEntries] = useState<Record<number, string[]>>({
0: [],
Expand Down Expand Up @@ -207,7 +210,7 @@ export const useEntriesByView = ({
}

return counts
}, [groupByDate, sortEntries, view])
}, [groupByDate, listId, sortEntries, view])

return {
...query,
Expand Down
43 changes: 25 additions & 18 deletions apps/renderer/src/modules/entry-column/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,19 @@ function EntryColumnImpl() {
virtuosoRef.current?.scrollTo({
top: 0,
})
setIsArchived(false)
}, []),
isArchived,
})

const { entriesIds, isFetchingNextPage, groupedCounts } = entries
useSnapEntryIdList(entriesIds)
const prevEntriesIdsRef = useRef(entriesIds)

useEffect(() => {
if (entriesIds.length > 0) {
prevEntriesIdsRef.current = entriesIds
}
}, [entriesIds])

const {
entryId: activeEntryId,
Expand All @@ -69,6 +75,11 @@ function EntryColumnImpl() {
inboxId,
listId,
} = useRouteParams()

useEffect(() => {
setIsArchived(false)
}, [view, routeFeedId])

const activeEntry = useEntry(activeEntryId)
const feed = useFeedById(routeFeedId)
const title = useFeedHeaderTitle()
Expand Down Expand Up @@ -99,24 +110,17 @@ function EntryColumnImpl() {
}
}, [isArchived])

const showArchivedButton =
!isArchived &&
!unreadOnly &&
!isCollection &&
routeFeedId !== ROUTE_FEED_PENDING &&
entries.totalCount < 40 &&
feed?.type === "feed"
// Common conditions for both showArchivedButton and shouldLoadArchivedEntries
const commonConditions =
!isArchived && !unreadOnly && !isCollection && routeFeedId !== ROUTE_FEED_PENDING

// Determine if the archived button should be shown
const showArchivedButton = commonConditions && entries.totalCount < 40 && feed?.type === "feed"
const hasNoEntries = entries.totalCount === 0 && !entries.isLoading

// Determine if archived entries should be loaded
const shouldLoadArchivedEntries =
!isArchived &&
!unreadOnly &&
!isCollection &&
routeFeedId !== ROUTE_FEED_PENDING &&
(feed?.type === "feed" || !feed) &&
!inboxId &&
!listId &&
entries.totalCount === 0 &&
!entries.isLoading
commonConditions && (feed?.type === "feed" || !feed) && !inboxId && !listId && hasNoEntries

// automatically fetch archived entries when there is no entries in timeline
useEffect(() => {
Expand All @@ -125,6 +129,9 @@ function EntryColumnImpl() {
}
}, [shouldLoadArchivedEntries])

const finalEntriesIds =
hasNoEntries && !isArchived ? prevEntriesIdsRef.current || entriesIds : entriesIds

const scrollRef = useRef<HTMLDivElement>(null)
const virtuosoOptions = {
components: {
Expand Down Expand Up @@ -173,7 +180,7 @@ function EntryColumnImpl() {
}
}
}, [entries]),
data: entriesIds,
data: finalEntriesIds,
onScroll: () => {
if (!isInteracted.current) {
isInteracted.current = true
Expand Down
2 changes: 1 addition & 1 deletion apps/renderer/src/queries/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const entries = {
isArchived?: boolean
}) =>
defineQuery(
["entries", inboxId || listId || feedId, view, read, limit],
["entries", inboxId || listId || feedId, view, read, limit, isArchived],
async ({ pageParam }) =>
entryActions.fetchEntries({
feedId,
Expand Down
1 change: 0 additions & 1 deletion locales/app/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"achievement.list_subscribe_500": "500 リスト購読者",
"achievement.list_subscribe_500_description": "あなたが作成したリストの購読者数が 500 人を超えました",
"achievement.list_subscribe_50_description": "あなたが作成したリストの購読者数が 50 人を超えました",
"achievement.mint_more_power": "ハードコア プレイヤーになるとさらなる報酬を得られます <power />",
"achievement.product_hunt_vote": "Product Hunt 投票者",
"achievement.product_hunt_vote_description": "あなたは Product Hunt での Follow サポーターです",
"activation.activate": "有効化",
Expand Down
Loading