@@ -230,7 +230,7 @@ export function PackageSearch(props: Props) {
230
230
let resetPage = false ;
231
231
const oldSearch = searchParams . getAll ( "search" ) . join ( " " ) ;
232
232
const oldOrdering = searchParams . get ( "ordering" ) ?? undefined ;
233
- const oldSection = searchParams . get ( "section" ) ?? "" ;
233
+ // const oldSection = searchParams.get("section") ?? "";
234
234
const oldDeprecated = searchParams . get ( "deprecated" ) ? true : false ;
235
235
const oldNSFW = searchParams . get ( "nsfw" ) ? true : false ;
236
236
const oldIncludedCategories =
@@ -264,18 +264,36 @@ export function PackageSearch(props: Props) {
264
264
resetPage = true ;
265
265
}
266
266
// Section
267
- if ( oldSection !== debouncedSearchParamsBlob . section ) {
267
+ // Because of the first section being a empty value, the logic check is a bit funky
268
+
269
+ // If no section in search params, delete
270
+ if ( sections . length === 0 ) searchParams . delete ( "section" ) ;
271
+
272
+ // If new section is empty, delete (defaults to first)
273
+ if ( debouncedSearchParamsBlob . section === "" )
274
+ searchParams . delete ( "section" ) ;
275
+
276
+ // If new section is the first one, delete. And reset page number if section is different from last render.
277
+ if ( debouncedSearchParamsBlob . section === sections [ 0 ] ?. uuid ) {
268
278
if (
269
- sections . length === 0 ||
270
- debouncedSearchParamsBlob . section === sections [ 0 ] ?. uuid ||
271
- debouncedSearchParamsBlob . section === ""
279
+ searchParamsBlobRef . current . section !==
280
+ debouncedSearchParamsBlob . section
272
281
) {
273
- searchParams . delete ( "section" ) ;
274
- } else {
275
- searchParams . set ( "section" , debouncedSearchParamsBlob . section ) ;
282
+ resetPage = true ;
276
283
}
284
+ searchParams . delete ( "section" ) ;
285
+ }
286
+
287
+ // If new section is different and not the first one, set it.
288
+ if (
289
+ searchParamsBlobRef . current . section !==
290
+ debouncedSearchParamsBlob . section &&
291
+ debouncedSearchParamsBlob . section !== sections [ 0 ] ?. uuid
292
+ ) {
293
+ searchParams . set ( "section" , debouncedSearchParamsBlob . section ) ;
277
294
resetPage = true ;
278
295
}
296
+
279
297
// Deprecated
280
298
if ( oldDeprecated !== debouncedSearchParamsBlob . deprecated ) {
281
299
if ( debouncedSearchParamsBlob . deprecated === false ) {
0 commit comments