fix bug that breaks subscriptions in channels, leaving servers, fix

subscrptions part 6
This commit is contained in:
Soph :3 2026-01-17 10:52:36 +02:00
parent d0509788ff
commit 5a85d72a51
5 changed files with 198 additions and 66 deletions

View file

@ -24,6 +24,8 @@
import { overview_data } from '$lib/state.svelte';
let dialogType: 'create_channel' | 'leave_server' | '' = $state('');
let {
currentPage = $bindable<string | null>(),
subPage = $bindable<string | null>(),
@ -505,59 +507,115 @@
</ContextMenu.Trigger>
<ContextMenu.Content>
<ContextMenu.Item>
<Dialog.Trigger>Create channel</Dialog.Trigger>
<Dialog.Trigger
onclick={() => {
dialogType = 'create_channel';
}}>Create channel</Dialog.Trigger
>
</ContextMenu.Item>
<ContextMenu.Item class="text-red-500 underline">
<Dialog.Trigger
onclick={() => {
dialogType = 'leave_server';
}}>Leave server</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 dialogType == 'create_channel'}
<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)
);
}
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>
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}
/>
<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
type="button"
class={buttonVariants({ variant: 'outline' })}>Cancel</Dialog.Close
>
<Button type="submit">Create</Button>
</Dialog.Footer>
</form>
</Dialog.Content>
{:else if dialogType == 'leave_server'}
<Dialog.Content>
<form
method="POST"
action="?/leaveServer"
use:enhance={() => {
return async ({ result }) => {
if (result.type == 'success') {
toast.success('Left server successfully');
}
if (result.type == 'error' || result.type == 'failure') {
toast.error(
'Could not leave server: ' +
(result.type === 'error' ? result.error : result.data?.error)
);
}
await invalidateAll();
await fill_overview_data(psd);
};
}}
>
<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.Header>
<Dialog.Title>Leave this server</Dialog.Title>
<Dialog.Description
>Would you like to leave this server?</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>
{/if}
</Dialog.Root>
{#each server.channels as channel (channel.id)}
<Dialog.Root>