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 1 commit
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
Prev Previous commit
Next Next commit
fix: reset isArchived on location change
  • Loading branch information
hyoban committed Nov 1, 2024
commit 61f5ec2d265de6acfdf7831a72670fdf15445fbc
25 changes: 16 additions & 9 deletions apps/renderer/src/modules/entry-column/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,19 @@ export const useEntriesByView = ({
}
if (!isFetchingFirstPage) {
prevEntryIdsRef.current = entryIds
setMergedEntries(entryIds)
setMergedEntries({ ...mergedEntries, [view]: entryIds })
onReset?.()
}
}, [isFetchingFirstPage, isArchived])

const [mergedEntries, setMergedEntries] = useState<string[]>([])
const [mergedEntries, setMergedEntries] = useState<Record<number, string[]>>({
0: [],
1: [],
2: [],
3: [],
4: [],
5: [],
})

const entryIdsAsDeps = entryIds.toString()

Expand All @@ -155,23 +162,23 @@ export const useEntriesByView = ({
useEffect(() => {
if (!prevEntryIdsRef.current) {
prevEntryIdsRef.current = entryIds
setMergedEntries(entryIds)
setMergedEntries({ ...mergedEntries, [view]: entryIds })
return
}
// merge the new entries with the old entries, and unique them
const nextIds = [...new Set([...prevEntryIdsRef.current, ...entryIds])]
prevEntryIdsRef.current = nextIds
setMergedEntries(nextIds)
setMergedEntries({ ...mergedEntries, [view]: entryIds })
}, [entryIdsAsDeps])

const sortEntries = useMemo(
() =>
isCollection
? sortEntriesIdByStarAt(mergedEntries)
? sortEntriesIdByStarAt(mergedEntries[view])
: listId
? sortEntriesIdByEntryInsertedAt(mergedEntries)
: sortEntriesIdByEntryPublishedAt(mergedEntries),
[isCollection, listId, mergedEntries],
? sortEntriesIdByEntryInsertedAt(mergedEntries[view])
: sortEntriesIdByEntryPublishedAt(mergedEntries[view]),
[isCollection, listId, mergedEntries, view],
)

const groupByDate = useGeneralSettingKey("groupByDate")
Expand Down Expand Up @@ -215,7 +222,7 @@ export const useEntriesByView = ({
}, [query, view]),
entriesIds: sortEntries,
groupedCounts,
totalCount: query.data?.pages?.[0]?.total ?? mergedEntries.length,
totalCount: query.data?.pages?.[0]?.total ?? mergedEntries[view].length,
}
}

Expand Down
7 changes: 6 additions & 1 deletion apps/renderer/src/modules/entry-column/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { FeedModel } from "@follow/models/types"
import { clsx, isBizId } from "@follow/utils/utils"
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react"
import { useTranslation } from "react-i18next"
import { useLocation } from "react-router-dom"
import type {
ScrollSeekConfiguration,
VirtuosoGridProps,
Expand Down Expand Up @@ -52,11 +53,15 @@ function EntryColumnImpl() {
virtuosoRef.current?.scrollTo({
top: 0,
})
setIsArchived(false)
}, []),
isArchived,
})

const location = useLocation()
useEffect(() => {
setIsArchived(false)
}, [location])

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