Skip to content

Commit a58d20f

Browse files
authored
Merge pull request #1361 from thunderstore-io/02-25-fix_section_preventing_page_number_from_being_set
Fix section preventing page number from being set
2 parents bff5d76 + 2098a31 commit a58d20f

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

apps/cyberstorm-remix/app/commonComponents/PackageSearch/PackageSearch.tsx

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export function PackageSearch(props: Props) {
230230
let resetPage = false;
231231
const oldSearch = searchParams.getAll("search").join(" ");
232232
const oldOrdering = searchParams.get("ordering") ?? undefined;
233-
const oldSection = searchParams.get("section") ?? "";
233+
// const oldSection = searchParams.get("section") ?? "";
234234
const oldDeprecated = searchParams.get("deprecated") ? true : false;
235235
const oldNSFW = searchParams.get("nsfw") ? true : false;
236236
const oldIncludedCategories =
@@ -264,18 +264,36 @@ export function PackageSearch(props: Props) {
264264
resetPage = true;
265265
}
266266
// 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) {
268278
if (
269-
sections.length === 0 ||
270-
debouncedSearchParamsBlob.section === sections[0]?.uuid ||
271-
debouncedSearchParamsBlob.section === ""
279+
searchParamsBlobRef.current.section !==
280+
debouncedSearchParamsBlob.section
272281
) {
273-
searchParams.delete("section");
274-
} else {
275-
searchParams.set("section", debouncedSearchParamsBlob.section);
282+
resetPage = true;
276283
}
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);
277294
resetPage = true;
278295
}
296+
279297
// Deprecated
280298
if (oldDeprecated !== debouncedSearchParamsBlob.deprecated) {
281299
if (debouncedSearchParamsBlob.deprecated === false) {

0 commit comments

Comments
 (0)