@@ -16,6 +16,7 @@ import { Button } from '~/ui'
1616import { useCurrentUser } from '~/hooks/useCurrentUser'
1717import { useLoginModal } from '~/contexts/LoginModalContext'
1818import type { LibraryId } from '~/libraries'
19+ import { PAGE_SIZE_OPTIONS } from '~/routes/showcase'
1920
2021export 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 ) }
0 commit comments