@@ -2,7 +2,11 @@ import { keepPreviousData, useInfiniteQuery } from '@tanstack/react-query'
2
2
import isEqual from 'lodash/isEqual'
3
3
import React , { useReducer } from 'react'
4
4
import { useSearchParams } from 'react-router-dom'
5
- import ActionBar , { isOwnedTabOption } from '~/components/ActionBar'
5
+ import ActionBar , {
6
+ isOwnedTabOption ,
7
+ isTabOption ,
8
+ TabOption ,
9
+ } from '~/components/ActionBar'
6
10
import Layout from '~/components/Layout'
7
11
import { MaxSearchPhraseLength , Minute } from '~/consts'
8
12
import { Projects , ProjectsContainer } from '~/marketplace/components/Projects'
@@ -13,12 +17,13 @@ import useModal from '~/shared/hooks/useModal'
13
17
import { useWalletAccount } from '~/shared/stores/wallet'
14
18
import { ProjectFilter } from '~/types'
15
19
import { useCurrentChainId } from '~/utils/chains'
20
+ import { useUrlParams } from '~/hooks/useUrlParams'
21
+ import { TheGraph } from '~/shared/types'
16
22
17
- const DefaultFilter : ProjectFilter = {
18
- search : '' ,
19
- }
20
-
21
- const PageSize = 16
23
+ const PAGE_SIZE = 20
24
+ const DEFAULT_TAB = TabOption . Any
25
+ const DEFAULT_SEARCH = ''
26
+ const DEFAULT_TYPE = ''
22
27
23
28
function filterReducer (
24
29
state : ProjectFilter ,
@@ -32,13 +37,38 @@ function filterReducer(
32
37
}
33
38
34
39
export default function ProjectListingPage ( ) {
40
+ const [ params ] = useSearchParams ( )
41
+
42
+ const DefaultFilter : ProjectFilter = {
43
+ search : params . get ( 'search' ) || DEFAULT_SEARCH ,
44
+ type : ( params . get ( 'type' ) as TheGraph . ProjectType ) || DEFAULT_TYPE ,
45
+ }
46
+
35
47
const [ filter , setFilter ] = useReducer ( filterReducer , DefaultFilter )
36
48
37
49
const account = useWalletAccount ( )
38
50
39
- const [ params ] = useSearchParams ( )
51
+ const tab = params . get ( 'tab' )
52
+ const selectedTab = isTabOption ( tab ) ? tab : DEFAULT_TAB
53
+ const owner = isOwnedTabOption ( selectedTab ) ? account : undefined
40
54
41
- const owner = isOwnedTabOption ( params . get ( 'tab' ) ) ? account : undefined
55
+ useUrlParams ( [
56
+ {
57
+ param : 'tab' ,
58
+ value : selectedTab ,
59
+ defaultValue : DEFAULT_TAB ,
60
+ } ,
61
+ {
62
+ param : 'search' ,
63
+ value : filter . search ,
64
+ defaultValue : DEFAULT_SEARCH ,
65
+ } ,
66
+ {
67
+ param : 'type' ,
68
+ value : filter . type ,
69
+ defaultValue : DEFAULT_TYPE ,
70
+ } ,
71
+ ] )
42
72
43
73
const { api : createProductModal } = useModal ( 'marketplace.createProduct' )
44
74
@@ -51,7 +81,7 @@ export default function ProjectListingPage() {
51
81
52
82
const params = {
53
83
chainId : currentChainId ,
54
- first : PageSize ,
84
+ first : PAGE_SIZE ,
55
85
owner,
56
86
projectType,
57
87
skip,
0 commit comments