import { useEffect , useState } from 'react' ; import { FILTERS , SORTING } from '../../components/ArtsFilter' ; import { useWallet } from '@solana/wallet-adapter-react' ; export const useCollectionFilters = ( ) : { filter : string ; sortBy : string ; showUserFrakts : boolean ; onFilterChange : ( filter : string ) => void ; onSortChange : ( sortBy : string ) => void ; setFilter : ( filter : string ) => void ; } => { const { connected } = useWallet ( ) ; const [ filter , setFilter ] = useState < string > ( FILTERS [ 0 ] . value ) ; const [ sortBy , setSortBy ] = useState < string > ( SORTING [ 0 ] . value ) ; const showUserFrakts = filter === FILTERS [ 1 ] . value ; const onFilterChange = ( filter ) : void => setFilter ( filter ) ; const onSortChange = ( sortBy ) : void => setSortBy ( sortBy ) ; useEffect ( ( ) => { ! connected && showUserFrakts && setFilter ( FILTERS [ 0 ] . value ) ; } , [ connected ] ) ; return { filter , sortBy , showUserFrakts , onFilterChange , onSortChange , setFilter , } ; } ;