Skip to content

Commit

Permalink
update page load data to svelte 5 paradigms, change reactive to effec…
Browse files Browse the repository at this point in the history
…t runes.
  • Loading branch information
haukened committed Nov 4, 2024
1 parent 05356e8 commit d177c61
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
13 changes: 8 additions & 5 deletions src/routes/login/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
import { loginFormSchema, type LoginFormSchema } from './schema';
import * as m from '$lib/paraglide/messages.js';
import { toast } from "svelte-sonner";
import type { PageData } from "./$types";
export let data: SuperValidated<Infer<LoginFormSchema>>;
//export let data: SuperValidated<Infer<LoginFormSchema>>;
let { data }: { data: SuperValidated<Infer<LoginFormSchema>> } = $props();
const form = superForm(data, {
validators: zodClient(loginFormSchema),
Expand All @@ -18,13 +21,13 @@
const { form: formData, errors, enhance } = form;
$: ((errors) => {
if (errors) {
errors.forEach(error => {
$effect(() => {
if ($errors._errors) {
$errors._errors.forEach(error => {
toast.error(error);
});
}
})($errors._errors);
});
</script>

<Card.Root class="w-96 max-w-full">
Expand Down
17 changes: 7 additions & 10 deletions src/routes/password/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import type { PageData } from "./$types";
import { toast } from "svelte-sonner";
export let data: PageData;
let { data }: { data: PageData } = $props();
const form = superForm(data.form, {
validators: zodClient(passwordFormSchema),
Expand All @@ -20,19 +20,16 @@
const { form: formData, enhance, errors, message } = form;
$: ((errors) => {
if (errors) {
errors.forEach(error => {
$effect(() => {
if ($errors._errors) {
$errors._errors.forEach(error => {
toast.error(error);
});
}
})($errors._errors);
$: ((message) => {
if (message) {
toast.success(message);
if ($message) {
toast.success($message);
}
})($message);
});
</script>

<Card.Root class="w-96 max-w-full">
Expand Down
17 changes: 7 additions & 10 deletions src/routes/profile/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import type { PageData } from "./$types";
import { toast } from "svelte-sonner";
export let data: PageData;
let { data }: { data: PageData } = $props();
const form = superForm(data.form, {
validators: zodClient(profileFormSchema),
Expand All @@ -22,19 +22,16 @@
const { form: formData, enhance, tainted, errors, message } = form;
$: ((errors) => {
if (errors) {
errors.forEach(error => {
$effect(() => {
if ($errors._errors) {
$errors._errors.forEach(error => {
toast.error(error);
});
}
})($errors._errors);
$: ((message) => {
if (message) {
toast.success(message);
if ($message) {
toast.success($message);
}
})($message);
});
</script>

<Card.Root class="w-96 max-w-full">
Expand Down

0 comments on commit d177c61

Please sign in to comment.