enh: channel delete

This commit is contained in:
Timothy Jaeryang Baek
2024-12-22 23:15:29 -07:00
parent 7ad8918cd9
commit 4c756b5501
4 changed files with 73 additions and 1 deletions

View File

@@ -24,6 +24,7 @@
bind:show={showEditChannelModal}
{channel}
edit={true}
{onUpdate}
onSubmit={async ({ name, access_control }) => {
const res = await updateChannelById(localStorage.token, channel.id, {
name,

View File

@@ -1,16 +1,19 @@
<script lang="ts">
import { getContext, createEventDispatcher, onMount } from 'svelte';
import { createNewChannel } from '$lib/apis/channels';
import { createNewChannel, deleteChannelById } from '$lib/apis/channels';
import Modal from '$lib/components/common/Modal.svelte';
import AccessControl from '$lib/components/workspace/common/AccessControl.svelte';
import DeleteConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
import { toast } from 'svelte-sonner';
import { page } from '$app/stores';
import { goto } from '$app/navigation';
const i18n = getContext('i18n');
export let show = false;
export let onSubmit: Function = () => {};
export let onUpdate: Function = () => {};
export let channel = null;
export let edit = false;
@@ -47,6 +50,20 @@
const deleteHandler = async () => {
showDeleteConfirmDialog = false;
const res = await deleteChannelById(localStorage.token, channel.id).catch((error) => {
toast.error(error.message);
});
if (res) {
toast.success('Channel deleted successfully');
onUpdate();
if ($page.url.pathname === `/channels/${channel.id}`) {
goto('/');
}
}
show = false;
};
</script>