fix: auto archived list flash (#1269)
* fix: auto archived list flash Signed-off-by: Innei <tukon479@gmail.com> * fix: reset isArchived on location change * chore: auto-fix linting and formatting issues * fix --------- Signed-off-by: Innei <tukon479@gmail.com> Co-authored-by: Stephen Zhou <38493346+hyoban@users.noreply.github.com> Co-authored-by: hyoban <hyoban@users.noreply.github.com>
This commit is contained in:
parent
0d0266b251
commit
8d2478c6a9
|
|
@ -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: [],
|
||||
|
|
@ -207,7 +210,7 @@ export const useEntriesByView = ({
|
|||
}
|
||||
|
||||
return counts
|
||||
}, [groupByDate, sortEntries, view])
|
||||
}, [groupByDate, listId, sortEntries, view])
|
||||
|
||||
return {
|
||||
...query,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
@ -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()
|
||||
|
|
@ -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(() => {
|
||||
|
|
@ -125,6 +129,9 @@ function EntryColumnImpl() {
|
|||
}
|
||||
}, [shouldLoadArchivedEntries])
|
||||
|
||||
const finalEntriesIds =
|
||||
hasNoEntries && !isArchived ? prevEntriesIdsRef.current || entriesIds : entriesIds
|
||||
|
||||
const scrollRef = useRef<HTMLDivElement>(null)
|
||||
const virtuosoOptions = {
|
||||
components: {
|
||||
|
|
@ -173,7 +180,7 @@ function EntryColumnImpl() {
|
|||
}
|
||||
}
|
||||
}, [entries]),
|
||||
data: entriesIds,
|
||||
data: finalEntriesIds,
|
||||
onScroll: () => {
|
||||
if (!isInteracted.current) {
|
||||
isInteracted.current = true
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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": "有効化",
|
||||
|
|
|
|||
Loading…
Reference in New Issue