Skip to content

Commit 2b360df

Browse files
committed
Chore: some polising
1 parent 73c2443 commit 2b360df

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

client/src/routes/manage/[id]/+page.svelte

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
export let data: PageData;
1414
let { timerData } = data;
15-
let submitResult: Promise<Timer> | undefined;
15+
let submitResult: Promise<Timer | void> = Promise.resolve();
1616
1717
$: {
1818
if (browser && !localStorage.getItem('token')) goto('/manage/login');
@@ -55,7 +55,7 @@
5555
<button
5656
class="btn-icon"
5757
on:click={() => {
58-
submitResult = undefined;
58+
submitResult = Promise.resolve();
5959
}}><Fa icon={faClose} /></button
6060
>
6161
</aside>
@@ -71,7 +71,7 @@
7171
<button
7272
class="btn-icon"
7373
on:click={() => {
74-
submitResult = undefined;
74+
submitResult = Promise.resolve();
7575
}}><Fa icon={faClose} /></button
7676
>
7777
</div>
@@ -80,6 +80,7 @@
8080
</div>
8181

8282
<div class="m-auto text-center">
83-
Alternatively, you can <a href="/">view an existing timer</a> or
84-
<a href="/manage/login">manage an existing timer</a>
83+
Alternatively, you can <a href="/">view an existing timer</a>,
84+
<a href="/manage/login">manage a diffrent existing timer</a> or
85+
<a href="/manage/create">create a new timer</a>
8586
</div>

client/src/routes/manage/create/+page.svelte

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@
1111
1212
export let data: PageData;
1313
const { fetch } = data;
14-
let submitResult: Promise<string> | undefined;
14+
let submitResult: Promise<string | void> = Promise.resolve();
15+
16+
interface ErrorMessages {
17+
[key: number]: string;
18+
}
19+
20+
const errorMessages: ErrorMessages = {
21+
409: 'A timer with that name already exists'
22+
};
1523
1624
const onSubmit = (timerData: TimerCreationRequest) => {
1725
submitResult = fetch(`${get(API_URL)}/timer`, {
@@ -22,9 +30,12 @@
2230
}
2331
})
2432
.then((res) => {
25-
if (!res.ok) {
33+
if (!res.ok && res.status in errorMessages) {
34+
throw new Error(errorMessages[res.status]);
35+
} else if (!res.ok) {
2636
throw new Error(res.statusText);
2737
}
38+
2839
return res.json();
2940
})
3041
.then((data) => {
@@ -61,7 +72,7 @@
6172
<button
6273
class="btn-icon"
6374
on:click={() => {
64-
submitResult = undefined;
75+
submitResult = Promise.resolve();
6576
}}><Fa icon={faClose} /></button
6677
>
6778
</aside>

client/src/routes/manage/login/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
1111
export let data: PageData;
1212
const { fetch } = data;
13-
let submitResult: Promise<string> | undefined;
13+
let submitResult: Promise<string | void> = Promise.resolve();
1414
1515
const onSubmit = async (id: string, password: string) => {
1616
submitResult = fetch(`${get(API_URL)}/timer/token`, {
@@ -62,7 +62,7 @@
6262
<button
6363
class="btn-icon"
6464
on:click={() => {
65-
submitResult = undefined;
65+
submitResult = Promise.resolve();
6666
}}><Fa icon={faClose} /></button
6767
>
6868
</aside>

0 commit comments

Comments
 (0)