diff --git a/src/routes/u/[name]/+page.svelte b/src/routes/u/[name]/+page.svelte index ca6fd3a3..19fdd6ac 100644 --- a/src/routes/u/[name]/+page.svelte +++ b/src/routes/u/[name]/+page.svelte @@ -26,11 +26,49 @@ import { page } from '$app/stores' import { goto } from '$app/navigation' import { isComment } from '$lib/components/lemmy/post/helpers.js' - import { authData, user } from '$lib/lemmy.js' + import { authData, getClient, user } from '$lib/lemmy.js' import { isBlocked } from '$lib/lemmy/user.js' import MultiSelect from '$lib/components/input/MultiSelect.svelte' + import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js' export let data + + let blocking = false + + async function blockUser(block: number) { + if (!$user || !$authData) throw new Error('Unauthenticated') + + blocking = true + try { + const blocked = isBlocked($user, block) + + await getClient().blockPerson({ + auth: $authData.token, + block: !blocked, + person_id: block, + }) + + if (blocked) { + const index = $user.person_blocks.map((p) => p.target.id).indexOf(block) + $user.person_blocks.splice(index, 1) + } + + toast({ + content: `Successfully ${blocked ? 'unblocked' : 'blocked'} that user.`, + type: ToastType.success, + }) + + goto($page.url, { + invalidateAll: true, + }) + } catch (err) { + toast({ + content: err as any, + type: ToastType.error, + }) + } + blocking = false + } @@ -93,7 +131,13 @@ {#if $user && $authData && data.person_view.person.id != $user.local_user_view.person.id}
-