1+ import type { Paginated , SearchResult } from '@/bindings.gen' ;
2+ import type { PaginationOptions } from '@/hooks/usePagination' ;
13import { PackageGrid } from '@/components/content/PackageItem' ;
24import { useBrowserContext , useBrowserSearch } from '@/hooks/useBrowser' ;
5+ import usePagination from '@/hooks/usePagination' ;
36import { Show } from '@onelauncher/common/components' ;
47import { createFileRoute } from '@tanstack/react-router' ;
58import { useEffect , useMemo , useState } from 'react' ;
69import { BrowserLayout } from './route' ;
7- import type { Paginated , SearchResult } from '@/bindings.gen' ;
8- import type { PaginationOptions } from '@/hooks/usePagination' ;
9- import usePagination from '@/hooks/usePagination' ;
1010
1111export const Route = createFileRoute ( '/app/browser/search' ) ( {
1212 component : RouteComponent ,
@@ -33,40 +33,39 @@ function Search() {
3333 return (
3434 < >
3535 {
36- search . data
37- ? < Results results = { search . data } />
38- : < h1 > Loading</ h1 >
36+ search . data
37+ ? < Results results = { search . data } />
38+ : < h1 > Loading</ h1 >
3939 }
4040 </ >
4141 ) ;
4242}
4343
44- function Results ( { results} : { results :Paginated < SearchResult > } ) {
44+ function Results ( { results } : { results : Paginated < SearchResult > } ) {
4545 const context = useBrowserContext ( ) ;
46- const [ oldTotal , setOldTotal ] = useState ( results . total )
46+ const [ oldTotal , setOldTotal ] = useState ( results . total ) ;
4747 const pagination = usePagination ( {
4848 itemsCount : results . total as unknown as number ,
49- itemsPerPage : context . query . limit as unknown as number
50- } )
51- useEffect ( ( ) => {
52- context . setQuery ( { ...context . query , offset : pagination . offset as unknown as bigint } )
53- } , [ pagination . page ] )
54- useEffect ( ( ) => {
55- if ( oldTotal === results . total ) return ;
56- pagination . reset ( )
57- console . log ( " pagination reset" , results . total )
58- setOldTotal ( results . total )
59- } , [ results . total ] )
49+ itemsPerPage : context . query . limit as unknown as number ,
50+ } ) ;
51+ useEffect ( ( ) => {
52+ context . setQuery ( { ...context . query , offset : pagination . offset as unknown as bigint } ) ;
53+ } , [ pagination . page ] ) ;
54+ useEffect ( ( ) => {
55+ if ( oldTotal === results . total )
56+ return ;
57+ pagination . reset ( ) ;
58+ setOldTotal ( results . total ) ;
59+ } , [ results . total ] ) ;
6060 return (
6161 < div >
62- < div className = ' w-full flex justify-end my-2' >
63- < pagination . Navigation />
62+ < div className = " w-full flex justify-end my-2" >
63+ < pagination . Navigation />
6464 </ div >
65- { results . items . length == 0
66- ? < h2 className = 'text-center text-lg font-light italic opacity-60' > No results</ h2 >
67- : < PackageGrid items = { results . items } provider = { context . provider } />
68- }
65+ { results . items . length === 0
66+ ? < h4 className = "text-center text-lg font-light opacity-60" > No results</ h4 >
67+ : < PackageGrid items = { results . items } provider = { context . provider } /> }
6968
7069 </ div >
71- )
70+ ) ;
7271}
0 commit comments