Skip to content

Commit 80a0bf9

Browse files
committed
Added timers test
1 parent e3e2d4e commit 80a0bf9

File tree

5 files changed

+83
-4
lines changed

5 files changed

+83
-4
lines changed

src/routes/Navigation.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<a href="/crud">CRUD</a> |
55
<a href="/super-debug">SuperDebug</a> |
66
<a href="/nested">Nested</a> |
7+
<a href="/timers">Timers</a> |
78
<a href="/multiple">Multiple</a>
89
<br />
910
<a href="/multiple2">Multiple 2</a> |

src/routes/tests/_empty/+page.server.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import type { Actions, PageServerLoad } from './$types';
21
import { message, superValidate } from '$lib/server';
32
import { schema } from './schema';
43
import { fail } from '@sveltejs/kit';
54

6-
export const load = (async () => {
5+
export const load = async () => {
76
const form = await superValidate(schema);
87
return { form };
9-
}) satisfies PageServerLoad;
8+
};
109

1110
export const actions = {
1211
default: async ({ request }) => {
@@ -20,4 +19,4 @@ export const actions = {
2019

2120
return message(form, 'Posted OK!');
2221
}
23-
} satisfies Actions;
22+
};

src/routes/timers/+page.server.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { message, superValidate } from '$lib/server';
2+
import { schema } from './schema';
3+
import { fail } from '@sveltejs/kit';
4+
5+
export const load = async () => {
6+
const form = await superValidate(schema);
7+
return { form };
8+
};
9+
10+
export const actions = {
11+
default: async ({ request }) => {
12+
await new Promise((r) => setTimeout(r, 12000));
13+
const form = await superValidate(request, schema);
14+
15+
if (!form.valid) return fail(400, { form });
16+
17+
return message(form, 'Posted OK!');
18+
}
19+
};

src/routes/timers/+page.svelte

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<script lang="ts">
2+
import { superForm } from '$lib/client';
3+
import type { PageData } from './$types';
4+
5+
export let data: PageData;
6+
7+
const {
8+
form,
9+
errors,
10+
tainted,
11+
message,
12+
enhance,
13+
submitting,
14+
delayed,
15+
timeout
16+
} = superForm(data.form, {
17+
delayMs: 4000,
18+
timeoutMs: 8000
19+
});
20+
</script>
21+
22+
{#if $message}<h4>{$message}</h4>{/if}
23+
24+
<form method="POST" use:enhance>
25+
<label>
26+
Name: <input name="name" bind:value={$form.name} />
27+
{#if $errors.name}<span class="invalid">{$errors.name}</span>{/if}
28+
</label>
29+
<div>
30+
<button>Submit</button>
31+
<div>
32+
{#if $timeout}
33+
STATE-TIMEOUT
34+
{:else if $delayed}
35+
STATE-DELAYED
36+
{:else if $submitting}
37+
STATE-SUBMITTING
38+
{/if}
39+
</div>
40+
</div>
41+
</form>
42+
43+
<style lang="scss">
44+
form {
45+
margin: 2rem 0;
46+
47+
input {
48+
background-color: #dedede;
49+
}
50+
51+
.invalid {
52+
color: crimson;
53+
}
54+
}
55+
</style>

src/routes/timers/schema.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { z } from 'zod';
2+
3+
export const schema = z.object({
4+
name: z.string().min(1).default('Name')
5+
});

0 commit comments

Comments
 (0)