Skip to content

Commit c84a2e1

Browse files
committed
refactor: changed "dropdown" filter logic
1 parent 066fc35 commit c84a2e1

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

src/generic/network.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ export class Requests {
2222
const generi_esclusi: string[] = [];
2323
const tipi_esclusi: string[] = [];
2424
const tipologia: string[] = [];
25-
const stato: string[] = [];
26-
const anno: string[] = [];
2725
const getFilterValue = (id: string) =>
2826
query.filters.find((filter) => filter.id == id)?.value;
2927
const genres: string | Record<string, "included" | "excluded"> =
@@ -52,28 +50,18 @@ export class Requests {
5250
if (tag[1] == "excluded") tipi_esclusi.push(tag[0]);
5351
}
5452
}
55-
56-
if (status && typeof status === "object") {
57-
for (const tag of Object.entries(status)) {
58-
if (tag[0].length > 0) stato.push(tag[0]);
59-
}
60-
} else if (status.length > 0) stato.push(status);
61-
62-
if (year && typeof year === "object") {
63-
for (const tag of Object.entries(year)) {
64-
if (tag[0].length > 0) anno.push(tag[0]);
65-
}
66-
} else if (year.length > 0) anno.push(year);
67-
53+
const statusFilter = status as string;
54+
const yearFilter = year as string;
6855
const url = new URL(source.base_url).addPathComponent("archive");
6956
if (query.title.toString().length > 0)
7057
url.setQueryItem("keyword", query.title.toString() ?? "");
7158
url.setQueryItem("page", page.toString());
7259
if (sorting?.id) url.setQueryItem("sort", sorting?.id);
7360
if (generi.length > 0) url.setQueryItem("genre", generi);
7461
if (tipologia.length > 0) url.setQueryItem("type", tipologia);
75-
if (stato.length > 0) url.setQueryItem("status", stato[0] ?? "");
76-
if (anno.length > 0) url.setQueryItem("year", anno[0] ?? "");
62+
if (statusFilter.length > 0)
63+
url.setQueryItem("status", statusFilter ?? "");
64+
if (yearFilter.length > 0) url.setQueryItem("year", yearFilter ?? "");
7765
return {
7866
url: url.toString(),
7967
excluded: { generi: generi_esclusi, tipi: tipi_esclusi },

0 commit comments

Comments
 (0)