Skip to content

Commit a9a7657

Browse files
committed
sup
1 parent 4fc73da commit a9a7657

4 files changed

Lines changed: 77 additions & 31 deletions

File tree

src/parts/ui/clicky.select.svelte

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,19 @@ A button that selects a single option from a list of available options when clic
66
<script lang="ts">
77
88
interface Props {
9-
source?: string | null;
10-
key: string | null;
9+
text: string;
10+
active: boolean;
1111
disabled?: boolean;
12+
onclick: () => void;
1213
}
1314
14-
let { source = $bindable(), key, disabled = false }: Props = $props();
15-
16-
17-
let active = $derived(source === key);
15+
let { text, active, disabled = false, onclick }: Props = $props();
1816
1917
</script>
2018

2119

22-
<button class:active {disabled}
23-
onclick={() => {
24-
source = key;
25-
}}
26-
>
27-
{key?.toUpperCase() ?? "DEFAULT"}
20+
<button class:active {disabled} {onclick}>
21+
{text}
2822
</button>
2923

3024

src/parts/ui/search-filters.svelte

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,23 @@ let open = $state(false);
5555
<td> <div class="toggles">
5656
{#each filters.groups as group}
5757
<ClickySelect
58-
bind:source={filters.group_by}
59-
key={group}
58+
text={group.toUpperCase()}
59+
active={filters.group_by === group}
6060
disabled={filters.sort_by !== "default" && filters.sort_by === group}
61+
onclick={() => {
62+
if (group === "default") {
63+
if (filters.group_by !== "default") {
64+
filters.group_by = "default";
65+
filters.dirtiness--;
66+
}
67+
}
68+
else {
69+
if (filters.group_by === "default") {
70+
filters.dirtiness++;
71+
}
72+
filters.group_by = group;
73+
}
74+
}}
6175
/>
6276
{/each}
6377
</div> </td>
@@ -75,9 +89,23 @@ let open = $state(false);
7589
<td> <div class="toggles">
7690
{#each filters.sorts as sort}
7791
<ClickySelect
78-
bind:source={filters.sort_by}
79-
key={sort}
92+
text={sort.toUpperCase()}
93+
active={filters.sort_by === sort}
8094
disabled={filters.group_by !== "default" && filters.group_by === sort}
95+
onclick={() => {
96+
if (sort === "default") {
97+
if (filters.sort_by !== "default") {
98+
filters.sort_by = "default";
99+
filters.dirtiness--;
100+
}
101+
}
102+
else {
103+
if (filters.sort_by === "default") {
104+
filters.dirtiness++;
105+
}
106+
filters.sort_by = sort;
107+
}
108+
}}
81109
/>
82110
{/each}
83111
</div> </td>

src/routes/(sup)/sup/projects/filter.svelte.ts

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { partial_ratio } from "fuzzball";
22

3-
import { SearchFilter } from "#scripts/search-filter.svelte";
3+
import { SearchFilter, type FilterResults } from "#scripts/search-filter.svelte";
44
import { any, all, get_enabled } from "#scripts/utils";
55

66
import { Lang, Tool, Flavour, Kind, State } from "./projects";
@@ -72,8 +72,22 @@ export class ProjectSearchFilter extends SearchFilter<ProjectData>
7272
}
7373

7474

75-
apply(projects: ProjectData[]): ProjectData[]
75+
apply(projects: ProjectData[]): FilterResults<ProjectData>
7676
{
77+
let out: FilterResults<ProjectData> = this.#filter(projects);
78+
79+
if (this.group_by !== "default") {
80+
out = this.#group_and_sort(out);
81+
}
82+
else if (this.query) {
83+
out = this.#sort(out);
84+
}
85+
86+
return out;
87+
}
88+
89+
#filter(projects: ProjectData[]): ProjectData[]
90+
{
7791
let out = projects.filter(
7892
proj => {
7993
proj._score_ = 0;
@@ -115,18 +129,28 @@ export class ProjectSearchFilter extends SearchFilter<ProjectData>
115129
out = projects;
116130
}
117131

118-
if (this.query) {
119-
out = super.sort(out,
120-
proj => Math.max(
121-
partial_ratio(this.query, proj.name),
122-
partial_ratio(this.query, proj.tech.join(" ")),
123-
proj.desc ? partial_ratio(this.query, proj.desc) : 0,
124-
proj.tech ? partial_ratio(this.query, proj.tech.join(" ")) : 0,
125-
proj.tags ? partial_ratio(this.query, proj.tags.join(" ")) : 0,
126-
)
127-
);
128-
}
129-
130132
return out;
131133
}
134+
135+
#group_and_sort(projects: ProjectData[]): [string, ProjectData[]][]
136+
{
137+
return super.group(
138+
projects,
139+
proj => proj[this.group_by],
140+
group => 1,
141+
);
142+
}
143+
144+
#sort(projects: ProjectData[]): ProjectData[]
145+
{
146+
return super.sort(projects,
147+
proj => Math.max(
148+
partial_ratio(this.query, proj.name),
149+
partial_ratio(this.query, proj.tech.join(" ")),
150+
proj.desc ? partial_ratio(this.query, proj.desc) : 0,
151+
proj.tech ? partial_ratio(this.query, proj.tech.join(" ")) : 0,
152+
proj.tags ? partial_ratio(this.query, proj.tags.join(" ")) : 0,
153+
)
154+
);
155+
}
132156
}

src/scripts/search-filter.svelte.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class SearchFilter<Entity extends Searchable>
9494
let out = Object.entries(groups);
9595

9696
if (sorter) {
97-
out.sort(([group, entities]) => sorter(group));
97+
out.sort(([group1, _], [group2, __]) => sorter(group1) - sorter(group2));
9898
}
9999

100100
if (this.reverse_group) {

0 commit comments

Comments
 (0)