Skip to content

Commit 07b075a

Browse files
committed
fix: showArchivedButton in PictureMasonry
close #1583
1 parent 50fd58f commit 07b075a

File tree

3 files changed

+46
-27
lines changed

3 files changed

+46
-27
lines changed

apps/renderer/src/modules/entry-column/hooks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ export const useEntriesByView = ({
228228
entriesIds: sortEntries,
229229
groupedCounts,
230230
totalCount: query.data?.pages?.[0]?.total ?? mergedEntries[view].length,
231+
queryTotalCount: query.data?.pages?.[0]?.total,
231232
}
232233
}
233234

apps/renderer/src/modules/entry-column/index.tsx

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { FeedViewType, views } from "@follow/constants"
66
import { useTitle, useTypeScriptHappyCallback } from "@follow/hooks"
77
import type { FeedModel } from "@follow/models/types"
88
import { clsx, isBizId } from "@follow/utils/utils"
9+
import type { FunctionComponent } from "react"
910
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react"
1011
import { useTranslation } from "react-i18next"
1112
import type {
@@ -42,6 +43,10 @@ const scrollSeekConfiguration: ScrollSeekConfiguration = {
4243
enter: (velocity) => Math.abs(velocity) > 1000,
4344
exit: (velocity) => Math.abs(velocity) < 1000,
4445
}
46+
47+
export type VirtuosoComponentProps = { onlyShowArchivedButton: boolean }
48+
type VirtuosoComponentPropsContext = { context?: VirtuosoComponentProps }
49+
4550
function EntryColumnImpl() {
4651
const { t } = useTranslation()
4752
const virtuosoRef = useRef<VirtuosoHandle>(null)
@@ -116,7 +121,7 @@ function EntryColumnImpl() {
116121

117122
// Determine if the archived button should be shown
118123
const showArchivedButton = commonConditions && entries.totalCount < 40 && feed?.type === "feed"
119-
const hasNoEntries = entries.totalCount === 0 && !entries.isLoading
124+
const hasNoEntries = entries.queryTotalCount === 0 && !entries.isLoading
120125

121126
// Determine if archived entries should be loaded
122127
const shouldLoadArchivedEntries =
@@ -136,31 +141,35 @@ function EntryColumnImpl() {
136141
const virtuosoOptions = {
137142
components: {
138143
List: EntryListContent,
139-
Footer: useCallback(() => {
140-
if (!isFetchingNextPage) {
141-
if (showArchivedButton) {
144+
Footer: useCallback(
145+
({ context }: VirtuosoComponentPropsContext) => {
146+
if (!isFetchingNextPage) {
147+
if (showArchivedButton) {
148+
return (
149+
<div className="flex justify-center py-4">
150+
<Button variant="outline" onClick={() => setIsArchived(true)}>
151+
{t("words.load_archived_entries")}
152+
</Button>
153+
</div>
154+
)
155+
} else {
156+
return null
157+
}
158+
} else {
159+
if (context?.onlyShowArchivedButton) return null
142160
return (
143-
<div className="flex justify-center py-4">
144-
<Button variant="outline" onClick={() => setIsArchived(true)}>
145-
{t("words.load_archived_entries")}
146-
</Button>
147-
</div>
161+
<EntryItemSkeleton
162+
view={view}
163+
count={Math.min(
164+
entries.data?.pages?.[0].data?.length || 20,
165+
entries.data?.pages.at(-1)?.remaining || 20,
166+
)}
167+
/>
148168
)
149-
} else {
150-
return null
151169
}
152-
} else {
153-
return (
154-
<EntryItemSkeleton
155-
view={view}
156-
count={Math.min(
157-
entries.data?.pages?.[0].data?.length || 20,
158-
entries.data?.pages.at(-1)?.remaining || 20,
159-
)}
160-
/>
161-
)
162-
}
163-
}, [isFetchingNextPage, showArchivedButton, t, view, entries.data?.pages]),
170+
},
171+
[isFetchingNextPage, showArchivedButton, t, view, entries.data?.pages],
172+
),
164173
ScrollSeekPlaceholder: useCallback(() => <EntryItemSkeleton view={view} count={1} />, [view]),
165174
},
166175
scrollSeekConfiguration,
@@ -194,7 +203,7 @@ function EntryColumnImpl() {
194203
},
195204
[view],
196205
),
197-
} satisfies VirtuosoProps<string, unknown>
206+
} satisfies VirtuosoProps<string, VirtuosoComponentProps>
198207

199208
const navigate = useNavigateEntry()
200209
const isRefreshing = entries.isFetching && !entries.isFetchingNextPage
@@ -272,7 +281,10 @@ const ListGird = ({
272281
virtuosoRef,
273282
hasNextPage,
274283
}: {
275-
virtuosoOptions: Omit<VirtuosoGridProps<string, unknown>, "data" | "endReached"> & {
284+
virtuosoOptions: Omit<
285+
VirtuosoGridProps<string, VirtuosoComponentProps>,
286+
"data" | "endReached"
287+
> & {
276288
data: string[]
277289
endReached: () => Promise<any>
278290
}
@@ -339,6 +351,11 @@ const ListGird = ({
339351
data={nextData}
340352
/>
341353

354+
{virtuosoOptions.components?.Footer &&
355+
(virtuosoOptions.components.Footer as FunctionComponent<VirtuosoComponentPropsContext>)({
356+
context: { onlyShowArchivedButton: true },
357+
})}
358+
342359
{FilteredContentTip}
343360
</>
344361
)

apps/renderer/src/modules/entry-column/lists.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { isListSubscription } from "~/store/subscription"
1515

1616
import { DateItem } from "./components/DateItem"
1717
import { EntryColumnShortcutHandler } from "./EntryColumnShortcutHandler"
18+
import type { VirtuosoComponentProps } from "./index"
1819

1920
export const EntryListContent = forwardRef<HTMLDivElement>((props, ref) => (
2021
<div className="px-2" {...props} ref={ref} />
@@ -48,7 +49,7 @@ type BaseEntryProps = {
4849
virtuosoRef: React.RefObject<VirtuosoHandle>
4950
refetch: () => void
5051
}
51-
type EntryListProps = VirtuosoProps<string, unknown> & {
52+
type EntryListProps = VirtuosoProps<string, VirtuosoComponentProps> & {
5253
groupCounts?: number[]
5354
} & BaseEntryProps
5455
export const EntryList: FC<EntryListProps> = memo(
@@ -90,7 +91,7 @@ export const EntryList: FC<EntryListProps> = memo(
9091

9192
const EntryGroupedList = forwardRef<
9293
VirtuosoHandle,
93-
VirtuosoProps<string, unknown> &
94+
VirtuosoProps<string, VirtuosoComponentProps> &
9495
DOMAttributes<HTMLDivElement> & {
9596
groupCounts: number[]
9697
}

0 commit comments

Comments
 (0)