@@ -25,10 +25,11 @@ import { faGhost, faFire } from "@fortawesome/free-solid-svg-icons";
25
25
import { useDebounce } from "use-debounce" ;
26
26
import {
27
27
useLoaderData ,
28
- useNavigation ,
28
+ useNavigationType ,
29
+ // useNavigation,
29
30
useSearchParams ,
30
31
} from "@remix-run/react" ;
31
- import { Communities , Community } from "@thunderstore/dapper/types" ;
32
+ import { Communities } from "@thunderstore/dapper/types" ;
32
33
import { getDapper } from "cyberstorm/dapper/sessionUtils" ;
33
34
34
35
export const meta : MetaFunction = ( ) => {
@@ -90,8 +91,11 @@ export async function clientLoader({ request }: LoaderFunctionArgs) {
90
91
91
92
export default function CommunitiesPage ( ) {
92
93
const communitiesData = useLoaderData < typeof loader | typeof clientLoader > ( ) ;
94
+ const navigationType = useNavigationType ( ) ;
95
+
93
96
const [ searchParams , setSearchParams ] = useSearchParams ( ) ;
94
- const navigation = useNavigation ( ) ;
97
+ // TODO: Disabled until we can figure out how a proper way to display skeletons
98
+ // const navigation = useNavigation();
95
99
96
100
const changeOrder = ( v : SortOptions ) => {
97
101
searchParams . set ( "order" , v ) ;
@@ -101,17 +105,24 @@ export default function CommunitiesPage() {
101
105
const [ searchValue , setSearchValue ] = useState (
102
106
searchParams . getAll ( "search" ) . join ( " " )
103
107
) ;
108
+
109
+ useEffect ( ( ) => {
110
+ if ( navigationType === "POP" ) {
111
+ setSearchValue ( searchParams . getAll ( "search" ) . join ( " " ) ) ;
112
+ }
113
+ } , [ searchParams ] ) ;
114
+
104
115
const [ debouncedSearchValue ] = useDebounce ( searchValue , 300 , {
105
116
maxWait : 300 ,
106
117
} ) ;
107
118
108
119
useEffect ( ( ) => {
109
120
if ( debouncedSearchValue === "" ) {
110
121
searchParams . delete ( "search" ) ;
111
- setSearchParams ( searchParams ) ;
122
+ setSearchParams ( searchParams , { replace : true } ) ;
112
123
} else {
113
124
searchParams . set ( "search" , debouncedSearchValue ) ;
114
- setSearchParams ( searchParams ) ;
125
+ setSearchParams ( searchParams , { replace : true } ) ;
115
126
}
116
127
} , [ debouncedSearchValue ] ) ;
117
128
@@ -145,7 +156,6 @@ export default function CommunitiesPage() {
145
156
clearValue = { ( ) => setSearchValue ( "" ) }
146
157
leftIcon = { < FontAwesomeIcon icon = { faSearch } /> }
147
158
csColor = "cyber-green"
148
- rootClasses = { searchAndOrderStyles . searchInput }
149
159
id = "communitiesSearchInput"
150
160
/>
151
161
</ div >
@@ -161,48 +171,20 @@ export default function CommunitiesPage() {
161
171
</ div >
162
172
</ Container >
163
173
164
- { navigation . state === "loading" ? (
174
+ < CommunitiesList communitiesData = { communitiesData } />
175
+ { /* {navigation.state === "loading" ? (
165
176
<CommunitiesListSkeleton />
166
177
) : (
167
178
<CommunitiesList communitiesData={communitiesData} />
168
- ) }
179
+ )} */ }
169
180
</ main >
170
181
</ >
171
182
) ;
172
183
}
173
184
174
- function comparePackageCount ( a : Community , b : Community ) {
175
- if ( a . total_package_count < b . total_package_count ) {
176
- return 1 ;
177
- }
178
- if ( a . total_package_count > b . total_package_count ) {
179
- return - 1 ;
180
- }
181
- return 0 ;
182
- }
183
-
184
185
function CommunitiesList ( props : { communitiesData : Communities } ) {
185
186
const { communitiesData } = props ;
186
187
187
- const topDogs : Community [ ] = [ ] ;
188
- communitiesData . results . reduce ( ( prevCommunity , currentCommunity ) => {
189
- if ( topDogs . length > 4 ) {
190
- topDogs . sort ( comparePackageCount ) ;
191
- const lastDog = topDogs . at ( - 1 ) ;
192
- if (
193
- ( lastDog ? lastDog . total_package_count : 0 ) <
194
- currentCommunity . total_package_count
195
- ) {
196
- topDogs . pop ( ) ;
197
- topDogs . push ( currentCommunity ) ;
198
- }
199
- } else {
200
- topDogs . push ( currentCommunity ) ;
201
- }
202
- return topDogs ;
203
- } , topDogs ) ;
204
- const flatDogs = topDogs . map ( ( community ) => community . identifier ) ;
205
-
206
188
if ( communitiesData . results . length > 0 ) {
207
189
return (
208
190
< div className = { communitiesListStyles . root } >
0 commit comments