From f47d113a014fb8cd55c2f261c5c86a1934991d50 Mon Sep 17 00:00:00 2001 From: fucksophie Date: Fri, 16 Jan 2026 20:44:19 +0200 Subject: [PATCH] switch to use:enchance for all forms, split overview into its own file --- src/lib/components/app-sidebar.svelte | 200 +++++++++++++++++++++-- src/lib/components/member-sidebar.svelte | 121 +++++++++++++- src/lib/state.svelte.ts | 53 ++++++ src/routes/app/+page.svelte | 73 ++------- src/routes/app/actions/group.ts | 1 + 5 files changed, 367 insertions(+), 81 deletions(-) create mode 100644 src/lib/state.svelte.ts diff --git a/src/lib/components/app-sidebar.svelte b/src/lib/components/app-sidebar.svelte index e9aab76..5097269 100644 --- a/src/lib/components/app-sidebar.svelte +++ b/src/lib/components/app-sidebar.svelte @@ -14,18 +14,25 @@ import Button, { buttonVariants } from './ui/button/button.svelte'; import User from './extra/User.svelte'; import type { SessionValidationResult } from '$lib/server/auth'; - import { Status, statuses, type OverviewData, type OverviewUser } from '$lib'; + import { Status, type OverviewData, type OverviewUser } from '$lib'; import Label from './ui/label/label.svelte'; + import { toast } from 'svelte-sonner'; + import { enhance } from '$app/forms'; + import { invalidateAll } from '$app/navigation'; + import { fill_overview_data } from '$lib/state.svelte'; + import type { PageServerLoad } from '../../routes/app/$types'; let { currentPage = $bindable(), subPage = $bindable(), data, + psd, user, ...restProps }: { currentPage: string | null; subPage: string | null; + psd: PageServerLoad; data: OverviewData; user: SessionValidationResult['user']; } = $props(); @@ -65,7 +72,27 @@ -
+ { + return async ({ result }) => { + if (result.type == 'success') { + toast.success('Friend request sent successfully'); + } + + if (result.type == 'error' || result.type == 'failure') { + toast.error( + 'Could not send friend request: ' + (result.error || result.data?.error) + ); + } + + await invalidateAll(); + await fill_overview_data(psd); + }; + }} + > Cancel @@ -93,7 +120,27 @@ Request sent - + { + return async ({ result }) => { + if (result.type == 'success') { + toast.success('Cancelled friend request successfully'); + } + + if (result.type == 'error' || result.type == 'failure') { + toast.error( + 'Could not cancel friend request: ' + + (result.error || result.data?.error) + ); + } + + await invalidateAll(); + await fill_overview_data(psd); + }; + }} + > @@ -116,12 +163,52 @@ -
+ { + return async ({ result }) => { + if (result.type == 'success') { + toast.success('Accepted friend request successfully'); + } + + if (result.type == 'error' || result.type == 'failure') { + toast.error( + 'Could not accept friend request: ' + + (result.error || result.data?.error) + ); + } + + await invalidateAll(); + await fill_overview_data(psd); + }; + }} + >
-
+ { + return async ({ result }) => { + if (result.type == 'success') { + toast.success('Cancelled friend request successfully'); + } + + if (result.type == 'error' || result.type == 'failure') { + toast.error( + 'Could not cancel friend request: ' + + (result.error || result.data?.error) + ); + } + + await invalidateAll(); + await fill_overview_data(psd); + }; + }} + >
@@ -141,7 +228,27 @@ Currently your friend -
+ { + return async ({ result }) => { + if (result.type == 'success') { + toast.success('Removed friend successfully'); + } + + if (result.type == 'error' || result.type == 'failure') { + toast.error( + 'Could not remove friend: ' + + (result.error || result.data?.error) + ); + } + + await invalidateAll(); + await fill_overview_data(psd); + }; + }} + >