diff --git a/src/routes/(app)/links/+page.svelte b/src/routes/(app)/links/+page.svelte index 474fc4e..126df21 100644 --- a/src/routes/(app)/links/+page.svelte +++ b/src/routes/(app)/links/+page.svelte @@ -4,9 +4,15 @@ import { Button, buttonVariants } from '$lib/components/ui/button' import * as Dialog from '$lib/components/ui/dialog' import * as Card from '$lib/components/ui/card' + import * as DropdownMenu from '$lib/components/ui/dropdown-menu' import { Input } from '$lib/components/ui/input' import { Label } from '$lib/components/ui/label' - import { Link2, Loader2, PlusCircle } from 'lucide-svelte' + import { + Link2, + Loader2, + MoreVertical, + PlusCircle, + } from 'lucide-svelte' import { invalidateAll } from '$app/navigation' export let data: PageData @@ -14,19 +20,31 @@ let dialogOpen = false let inputLink = '' let isLoading = false + const addShortener = async () => { isLoading = true - await fetch('/api/shortener', { + const response = await fetch('/api/shortener', { method: 'post', body: JSON.stringify({ link: inputLink }), }) + const responseData = await response.json() + isLoading = false + + if (responseData.success) { + await invalidateAll() + dialogOpen = false + } + } + + const deleteShortener = async (code: string) => { + await fetch(`/api/shortener/${code}`, { + method: 'delete', + }) await invalidateAll() - dialogOpen = false } - $: console.log(inputLink)