channel creation / deletion

This commit is contained in:
Soph :3 2026-01-17 00:39:00 +02:00
parent f1dcd0cfc5
commit d0509788ff
19 changed files with 577 additions and 28 deletions

View file

@ -11,6 +11,7 @@
import UsersRound from '@lucide/svelte/icons/users-round';
import CirclePlus from '@lucide/svelte/icons/circle-plus';
import Input from './ui/input/input.svelte';
import * as ContextMenu from '$lib/components/ui/context-menu/index.js';
import Button, { buttonVariants } from './ui/button/button.svelte';
import User from './extra/User.svelte';
import type { SessionValidationResult } from '$lib/server/auth';
@ -482,34 +483,147 @@
<Collapsible.Content>
<Sidebar.MenuSub>
{#each overview_data.servers as server (server.id)}
<Sidebar.MenuSubItem>
<Sidebar.MenuSubButton
onclick={(e) => {
e.preventDefault();
currentPage = server.id;
subPage = null;
}}
>
<img
src={'https://api.dicebear.com/9.x/glass/svg?seed=' + server.name}
alt={server.name}
class="size-6 rounded-full"
/>
{server.name}
</Sidebar.MenuSubButton>
</Sidebar.MenuSubItem>
<Dialog.Root>
<ContextMenu.Root>
<ContextMenu.Trigger
><Sidebar.MenuSubItem>
<Sidebar.MenuSubButton
onclick={(e) => {
e.preventDefault();
currentPage = server.id;
subPage = null;
}}
>
<img
src={'https://api.dicebear.com/9.x/glass/svg?seed=' + server.name}
alt={server.name}
class="size-6 rounded-full"
/>
{server.name}
</Sidebar.MenuSubButton>
</Sidebar.MenuSubItem>
</ContextMenu.Trigger>
<ContextMenu.Content>
<ContextMenu.Item>
<Dialog.Trigger>Create channel</Dialog.Trigger>
</ContextMenu.Item>
</ContextMenu.Content>
</ContextMenu.Root>
<Dialog.Content>
<form
method="POST"
action="?/createChannel"
use:enhance={() => {
return async ({ result }) => {
if (result.type == 'success') {
toast.success('Created channel successfully');
}
if (result.type == 'error' || result.type == 'failure') {
toast.error(
'Could not create channel: ' +
(result.type === 'error' ? result.error : result.data?.error)
);
}
await invalidateAll();
await fill_overview_data(psd);
};
}}
>
<Dialog.Header>
<Dialog.Title>Create a channel</Dialog.Title>
<Dialog.Description>Add a new channel to this server.</Dialog.Description>
</Dialog.Header>
<div class="space-y-1">
<Label for="channelName">Channel name</Label>
<Input
id="channelName"
name="channelName"
placeholder="Channel name"
required
minlength={1}
maxlength={32}
/>
<input type="hidden" name="serverId" value={server.id} />
</div>
<Dialog.Footer>
<Dialog.Close class={buttonVariants({ variant: 'outline' })}
>Cancel</Dialog.Close
>
<Button type="submit">Create</Button>
</Dialog.Footer>
</form>
</Dialog.Content>
</Dialog.Root>
{#each server.channels as channel (channel.id)}
<a
onclick={(e) => {
e.preventDefault();
currentPage = server.id;
subPage = channel.id;
}}
href="##"
class="flex items-center gap-2"
>
{channel.name}
</a>
<Dialog.Root>
<ContextMenu.Root>
<ContextMenu.Trigger>
<a
onclick={(e) => {
e.preventDefault();
currentPage = server.id;
subPage = channel.id;
}}
href="##"
class="flex items-center gap-2"
>
{channel.name}
</a>
</ContextMenu.Trigger>
<ContextMenu.Content>
<ContextMenu.Item class="text-red-500 underline">
<Dialog.Trigger>Delete channel</Dialog.Trigger>
</ContextMenu.Item>
</ContextMenu.Content>
</ContextMenu.Root>
<Dialog.Content>
<form
method="POST"
action="?/deleteChannel"
use:enhance={() => {
return async ({ result }) => {
if (result.type == 'success') {
toast.success('Deleted channel successfully');
}
if (result.type == 'error' || result.type == 'failure') {
toast.error(
'Could not delete channel: ' +
(result.type === 'error' ? result.error : result.data?.error)
);
}
await invalidateAll();
await fill_overview_data(psd);
};
}}
>
<input type="hidden" name="serverId" value={server.id} />
<input type="hidden" name="channelId" value={channel.id} />
<Dialog.Header>
<Dialog.Title>Delete this channel</Dialog.Title>
<Dialog.Description
>This action is IRREVERSIBLE and will delete all messages in the
channel. Are you sure you want to proceed?</Dialog.Description
>
</Dialog.Header>
<Dialog.Footer>
<Dialog.Close class={buttonVariants({ variant: 'outline' })}
>No</Dialog.Close
>
<Button variant="destructive" type="submit">Yes</Button>
</Dialog.Footer>
</form>
</Dialog.Content>
</Dialog.Root>
{/each}
{/each}
</Sidebar.MenuSub>