Skip to content

Commit 7039615

Browse files
committed
Switch to runes and simplify
1 parent f46e7a8 commit 7039615

30 files changed

Lines changed: 255 additions & 325 deletions

frontend/eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default ts.config(
2121
}
2222
},
2323
{
24-
files: ["**/*.svelte"],
24+
files: ["**/*.svelte", "**/*.svelte.ts"],
2525

2626
languageOptions: {
2727
parserOptions: {

frontend/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
"license": "MIT",
88
"type": "module",
99
"scripts": {
10-
"dev": "vite dev",
11-
"build": "vite build",
12-
"preview": "vite preview",
13-
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
14-
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
15-
"lint": "eslint ."
10+
"dev": "bun run --bun vite dev",
11+
"build": "bun run --bun vite build",
12+
"preview": "bun run --bun vite preview",
13+
"check": "bun run --bun svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
14+
"check:watch": "bun run --bun svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
15+
"lint": "bun run --bun eslint ."
1616
},
1717
"devDependencies": {
1818
"@sveltejs/adapter-static": "^3.0.8",

frontend/package.json.md5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6e58a5b802452375c26c96a98fc755d5
1+
c2d828eed2c9ae8c618e56421f60c145

frontend/src/lib/actions/debug.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

frontend/src/lib/actions/log.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

frontend/src/lib/components/Checkbox.svelte

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script lang="ts">
2-
// NOTES: preventing the default click event behavior is needed to stop the change event being fired twice when the spacebar is pressed.
3-
import {handleKeyboardToggle, checkItem} from "../stores/controls";
2+
import {handleKeyboardToggle} from "$lib/utils/handlers";
43
54
65
interface Props {
@@ -10,23 +9,16 @@
109
}
1110
1211
// eslint-disable-next-line prefer-const
13-
let {checked, label, onchange}: Props = $props();
12+
let {checked = $bindable(), label, onchange}: Props = $props();
1413
1514
let checkbox: HTMLInputElement;
16-
17-
function handleKeyDown(e: KeyboardEvent) {
18-
if (e.key === " ") {
19-
e.preventDefault();
20-
checkItem(checkbox);
21-
}
22-
}
2315
</script>
2416

2517

2618
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
2719
<label class="checkbox-container" onkeypress={(e: KeyboardEvent) => handleKeyboardToggle(e, checkbox)}>
2820
<div class="checkbox-inner">
29-
<input class="checkbox" type="checkbox" bind:this={checkbox} bind:checked {onchange} onkeydown={handleKeyDown} />
21+
<input class="checkbox" type="checkbox" bind:this={checkbox} bind:checked {onchange} onkeypress={(e: KeyboardEvent) => handleKeyboardToggle(e, checkbox)} />
3022
<svg class="checkbox-glyph" viewBox="0 0 24 24">
3123
<path d="M0.73, 11.91 8.1,19.28 22.79,4.59" fill="none" />
3224
</svg>

frontend/src/lib/components/Footer.svelte

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,66 @@
22
import Button from "./Button.svelte";
33
import ButtonGroup from "./ButtonGroup.svelte";
44
import SocialLinks from "./SocialLinks.svelte";
5-
import {canGoForward, canGoBack, nextPage, state} from "../stores/navigation";
6-
import quit from "../actions/quit";
7-
import {goto, onNavigate} from "$app/navigation";
5+
import {goto} from "$app/navigation";
86
import {page} from "$app/state";
97
import {base} from "$app/paths";
8+
import app from "$lib/stores/state.svelte";
9+
import {NavDirection, type NavigationState} from "$lib/types";
1010
11+
const {
12+
next, previous,
13+
nextLabel = "Next",
14+
previousLabel = "Back",
15+
canGoNext = true,
16+
canGoPrevious = true,
17+
nextAction, previousAction
18+
}: NavigationState = $derived(app.navigation);
19+
20+
$effect(() => {
21+
// eslint-disable-next-line no-console
22+
console.log({
23+
next,
24+
previous,
25+
nextLabel,
26+
previousLabel,
27+
canGoNext,
28+
canGoPrevious,
29+
nextAction,
30+
previousAction
31+
});
32+
});
33+
34+
35+
const nextDisabled: boolean = $derived.by(() => {
36+
if (!canGoNext) return true;
37+
if (!nextAction && !next) return true;
38+
return false;
39+
});
40+
41+
const previousDisabled: boolean = $derived.by(() => {
42+
if (!canGoPrevious) return true;
43+
if (!previousAction && !previous) return true;
44+
return false;
45+
});
1146
12-
let nextButtonContent = "Next";
1347
1448
async function goToNext() {
15-
state.direction = 1;
16-
if ($nextPage) goto(`${base}${$nextPage}`, page.state);
17-
else await quit();
49+
app.navigation.direction = NavDirection.FORWARDS;
50+
if (typeof nextAction === "function") return nextAction();
51+
if (next) goto(`${base}${next}`, page.state);
1852
}
1953
2054
function goBack() {
21-
state.direction = -1;
22-
window.history.back();
55+
app.navigation.direction = NavDirection.BACKWARDS;
56+
if (typeof previousAction === "function") return previousAction();
57+
if (previous) goto(`${base}${previous}`, page.state);
2358
}
2459
25-
onNavigate(() => {
26-
if (window.location.pathname.startsWith("/actions/setup/")) {
27-
const action = window.location.pathname.slice(15);
28-
const actionText = action[0].toUpperCase() + action.slice(1);
29-
nextButtonContent = actionText;
30-
}
31-
else {
32-
nextButtonContent = "Next";
33-
}
34-
});
35-
3660
function navigatePage(event: KeyboardEvent) {
37-
if ((event.key === "ArrowRight" && event.ctrlKey) && $canGoForward) {
61+
if ((event.key === "ArrowRight" && event.ctrlKey) && canGoNext) {
3862
goToNext();
3963
}
40-
else if ((event.key === "ArrowLeft" && event.ctrlKey) && $canGoBack) {
64+
else if ((event.key === "ArrowLeft" && event.ctrlKey) && canGoPrevious) {
4165
goBack();
4266
}
4367
}
@@ -49,8 +73,12 @@
4973
<footer class="install-footer">
5074
<SocialLinks />
5175
<ButtonGroup>
52-
<Button style="secondary" disabled={!$canGoBack} onclick={goBack}>Back</Button>
53-
<Button style="primary" disabled={!$canGoForward} onclick={goToNext}>{#if $nextPage}{nextButtonContent}{:else}Close{/if}</Button>
76+
<Button style="secondary" disabled={previousDisabled} onclick={goBack}>
77+
{previousLabel}
78+
</Button>
79+
<Button style="primary" disabled={nextDisabled} onclick={goToNext}>
80+
{nextLabel}
81+
</Button>
5482
</ButtonGroup>
5583
</footer>
5684

frontend/src/lib/components/Multiselect.svelte

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import Button from "./Button.svelte";
3-
import {handleKeyboardToggle} from "../stores/controls";
3+
import {handleKeyboardToggle} from "$lib/utils/handlers";
44
import type {Snippet} from "svelte";
55
66
// export let value: string;
@@ -20,14 +20,15 @@
2020
children?: Snippet;
2121
}
2222
23-
const {children, icon, description, disabled = false, checked = false, onclick, onchange}: Props = $props();
23+
// eslint-disable-next-line prefer-const
24+
let {children, icon, description, disabled = false, checked = $bindable(), onclick, onchange}: Props = $props();
2425
2526
let checkbox: HTMLInputElement;
2627
2728
</script>
2829

2930
<label class="check-container">
30-
<input bind:this={checkbox} type="checkbox" hidden {disabled} {checked} {onchange} />
31+
<input bind:this={checkbox} bind:checked type="checkbox" hidden {disabled} {onchange} />
3132
<div onkeypress={(e: KeyboardEvent) => handleKeyboardToggle(e, checkbox)} tabindex="0" class="check-item" class:disabled role="listbox">
3233
<div class="icon">
3334
{@render icon?.()}

frontend/src/lib/components/Page.svelte

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,31 @@
22
import type {Snippet} from "svelte";
33
import PageHeader from "./PageHeader.svelte";
44
import page from "$lib/transitions/page";
5+
import {createNavState, type NavigationState} from "$lib/types";
6+
import app from "$lib/stores/state.svelte";
57
68
7-
interface Props {
9+
interface Props extends Partial<NavigationState> {
810
children: Snippet;
911
icon?: Snippet;
1012
title?: string;
1113
}
1214
13-
const {children, icon, title = "BetterDiscord"}: Props = $props();
15+
// TODO: remove when the PR lands in eslint-plugin-svelte
16+
// the below is not actually an issue with our code
17+
// eslint-disable-next-line svelte/valid-compile
18+
const {children, icon, title = "BetterDiscord", ...footer}: Props = $props();
19+
20+
21+
// Allow page users to easily setup the navigation state
22+
$effect(() => {
23+
const nav: Omit<NavigationState, "direction"> = createNavState(footer);
24+
for (const n in nav) {
25+
const key = n as keyof Omit<NavigationState, "direction">;
26+
// @ts-expect-error it doesn't make sense
27+
app.navigation[key] = nav[key];
28+
}
29+
});
1430
</script>
1531

1632

frontend/src/lib/components/Radio.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
let {group = $bindable(), value, onchange, children}: Props = $props();
1313
</script>
1414

15+
1516
<label class="radio-container">
1617
<input type="radio" hidden bind:group {onchange} {value} />
1718
<div tabindex="-1" class="radio-item">
@@ -21,6 +22,7 @@
2122
</div>
2223
</label>
2324

25+
2426
<style>
2527
.radio-item {
2628
display: flex;

0 commit comments

Comments
 (0)