Skip to content

Commit 39afc6b

Browse files
committed
Fix: showcase pagination per-page selector now works correctly.
Before if we try to change the page size it did not do anything.
1 parent 01f9d70 commit 39afc6b

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

src/components/ShowcaseGallery.tsx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { Button } from '~/ui'
1616
import { useCurrentUser } from '~/hooks/useCurrentUser'
1717
import { useLoginModal } from '~/contexts/LoginModalContext'
1818
import type { LibraryId } from '~/libraries'
19+
import { PAGE_SIZE_OPTIONS } from '~/routes/showcase'
1920

2021
export function ShowcaseGallery() {
2122
const navigate = useNavigate({ from: '/showcase/' })
@@ -24,11 +25,13 @@ export function ShowcaseGallery() {
2425
const currentUser = useCurrentUser()
2526
const { openLoginModal } = useLoginModal()
2627

28+
const pageSize = search.pageSize ?? 24
29+
2730
const { data, isLoading } = useQuery(
2831
getApprovedShowcasesQueryOptions({
2932
pagination: {
3033
page: search.page,
31-
pageSize: 24,
34+
pageSize,
3235
},
3336
filters: {
3437
libraryIds: search.libraryIds,
@@ -69,7 +72,7 @@ export function ShowcaseGallery() {
6972
// Snapshot previous values
7073
const previousShowcases = queryClient.getQueryData(
7174
getApprovedShowcasesQueryOptions({
72-
pagination: { page: search.page, pageSize: 24 },
75+
pagination: { page: search.page, pageSize },
7376
filters: {
7477
libraryIds: search.libraryIds,
7578
useCases: search.useCases as ShowcaseUseCase[],
@@ -113,7 +116,7 @@ export function ShowcaseGallery() {
113116
// Optimistically update showcase score
114117
queryClient.setQueryData(
115118
getApprovedShowcasesQueryOptions({
116-
pagination: { page: search.page, pageSize: 24 },
119+
pagination: { page: search.page, pageSize },
117120
filters: {
118121
libraryIds: search.libraryIds,
119122
useCases: search.useCases as ShowcaseUseCase[],
@@ -154,7 +157,7 @@ export function ShowcaseGallery() {
154157
if (context?.previousShowcases) {
155158
queryClient.setQueryData(
156159
getApprovedShowcasesQueryOptions({
157-
pagination: { page: search.page, pageSize: 24 },
160+
pagination: { page: search.page, pageSize },
158161
filters: {
159162
libraryIds: search.libraryIds,
160163
useCases: search.useCases as ShowcaseUseCase[],
@@ -251,6 +254,16 @@ export function ShowcaseGallery() {
251254
})
252255
}
253256

257+
const handlePageSizeChange = (newPageSize: number) => {
258+
navigate({
259+
search: (prev: typeof search) => ({
260+
...prev,
261+
pageSize: newPageSize,
262+
page: 1,
263+
}),
264+
})
265+
}
266+
254267
const handleSearchChange = (q: string) => {
255268
navigate({
256269
search: (prev: typeof search) => ({
@@ -358,12 +371,14 @@ export function ShowcaseGallery() {
358371
currentPage={search.page - 1}
359372
totalPages={data.pagination.totalPages}
360373
totalItems={data.pagination.total}
361-
pageSize={24}
374+
pageSize={pageSize}
362375
onPageChange={handlePageChange}
363-
onPageSizeChange={() => {}}
376+
onPageSizeChange={handlePageSizeChange}
364377
canGoPrevious={search.page > 1}
365378
canGoNext={search.page < data.pagination.totalPages}
366379
itemLabel="projects"
380+
showPageSizeSelector
381+
pageSizeOptions={[...PAGE_SIZE_OPTIONS]}
367382
/>
368383
</div>
369384
)}

src/routes/showcase/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,20 @@ import { libraryIdSchema, showcaseUseCaseSchema } from '~/utils/schemas'
77

88
const searchSchema = v.object({
99
page: v.optional(v.number(), 1),
10+
pageSize: v.optional(v.number(), 24),
1011
libraryIds: v.optional(v.array(libraryIdSchema)),
1112
useCases: v.optional(v.array(showcaseUseCaseSchema)),
1213
hasSourceCode: v.optional(v.boolean()),
1314
q: v.optional(v.string()),
1415
})
1516

17+
export const PAGE_SIZE_OPTIONS = [24, 48, 96, 192] as const
18+
1619
export const Route = createFileRoute('/showcase/')({
1720
validateSearch: searchSchema,
1821
loaderDeps: ({ search }) => ({
1922
page: search.page,
23+
pageSize: search.pageSize,
2024
libraryIds: search.libraryIds,
2125
useCases: search.useCases,
2226
hasSourceCode: search.hasSourceCode,
@@ -27,7 +31,7 @@ export const Route = createFileRoute('/showcase/')({
2731
getApprovedShowcasesQueryOptions({
2832
pagination: {
2933
page: deps.page,
30-
pageSize: 24,
34+
pageSize: deps.pageSize,
3135
},
3236
filters: {
3337
libraryIds: deps.libraryIds,

0 commit comments

Comments
 (0)