|
1 | 1 | <script>
|
2 | 2 | import { page } from "$app/stores";
|
3 |
| - import { User, Heart, MoreVertical, Pencil, Trash, Loader2, CheckCircle2 } from "lucide-svelte"; |
| 3 | + import { User, Heart, MoreVertical, Pencil, Trash } from "lucide-svelte"; |
4 | 4 | import { Button } from "$lib/components/ui/button";
|
5 | 5 | import * as DropdownMenu from "$lib/components/ui/dropdown-menu";
|
6 |
| - import * as Dialog from "$lib/components/ui/dialog"; |
7 | 6 | import * as Avatar from "$lib/components/ui/avatar";
|
8 | 7 | import * as Tooltip from "$lib/components/ui/tooltip";
|
9 |
| - import * as Alert from "$lib/components/ui/alert"; |
10 | 8 |
|
11 | 9 | export let asset;
|
12 | 10 | export let manage = false;
|
13 |
| - let open = false; |
14 |
| - let title; |
| 11 | + export let deleteDialog = () => {}; |
15 | 12 | let animate;
|
16 |
| - let loading; |
17 |
| - let alert; |
18 |
| -
|
19 |
| - async function deleteAsset(id) { |
20 |
| - loading = true; |
21 |
| - await fetch("/asset", { method: "DELETE", body: JSON.stringify({ id }) }); |
22 |
| - loading = false; |
23 |
| - open = false; |
24 |
| - alert = true; |
25 |
| - setTimeout(() => { |
26 |
| - alert = false; |
27 |
| - }, 2000); |
28 |
| - } |
29 | 13 | async function changeLikeStatus() {
|
30 | 14 | animate = true;
|
31 | 15 | setTimeout(() => {
|
32 | 16 | animate = false;
|
33 | 17 | }, 250);
|
34 |
| - const response = await fetch("/like", { |
| 18 | + asset.liked = !asset.liked; |
| 19 | + asset.likes = asset.liked ? asset.likes + 1 : asset.likes - 1; |
| 20 | + await fetch("/like", { |
35 | 21 | method: "POST",
|
36 | 22 | body: JSON.stringify({
|
37 | 23 | assetId: asset.id,
|
38 | 24 | userId: $page.data.userId
|
39 | 25 | })
|
40 | 26 | });
|
41 |
| - asset.liked = (await response.json()).liked; |
42 |
| - asset.likes = asset.liked ? asset.likes + 1 : asset.likes - 1; |
43 | 27 | }
|
44 | 28 | </script>
|
45 | 29 |
|
46 |
| -<div class={`top-20 left-0 fixed flex h-20 w-full justify-center ${alert ? "" : "hidden"}`}> |
47 |
| - <Alert.Root variant="success" class="w-30 bg-slate-100 dark:bg-slate-900"> |
48 |
| - <CheckCircle2 class="h-4 w-4 text-green-500" /> |
49 |
| - <Alert.Title>Success</Alert.Title> |
50 |
| - <Alert.Description>Asset deleted successfully!</Alert.Description> |
51 |
| - </Alert.Root> |
52 |
| -</div> |
53 | 30 | <div class="animate-gradient rounded-xl p-[4px] hover:border-transparent hover:bg-gradient-to-r">
|
54 | 31 | <div class="h-full w-full rounded-lg bg-slate-100 p-4 dark:bg-slate-900">
|
55 | 32 | <svelte:element
|
|
96 | 73 | </DropdownMenu.Item>
|
97 | 74 | <DropdownMenu.Item
|
98 | 75 | class="flex flex-row items-center gap-2 text-destructive hover:bg-destructive"
|
99 |
| - on:click={() => { |
100 |
| - title = asset.title; |
101 |
| - open = true; |
102 |
| - }} |
| 76 | + on:click={() => deleteDialog(asset.id)} |
103 | 77 | >
|
104 | 78 | <Trash size={20} />
|
105 | 79 | Delete Asset
|
|
150 | 124 | </svelte:element>
|
151 | 125 | </div>
|
152 | 126 | </div>
|
153 |
| - |
154 |
| -<Dialog.Root {open}> |
155 |
| - <Dialog.Content> |
156 |
| - <Dialog.Header> |
157 |
| - <Dialog.Title>Delete Asset</Dialog.Title> |
158 |
| - <Dialog.Description> |
159 |
| - Are you sure you want to <span class="font-bold text-destructive">DELETE</span> the asset |
160 |
| - <span class="font-bold text-primary">{title}</span>? |
161 |
| - </Dialog.Description> |
162 |
| - </Dialog.Header> |
163 |
| - <div class="flex justify-end gap-4"> |
164 |
| - <Button variant="outline" on:click={() => (open = false)}>Cancel</Button> |
165 |
| - {#if loading} |
166 |
| - <Button disabled variant="destructive"> |
167 |
| - <Loader2 class="animate-spin" /> |
168 |
| - </Button> |
169 |
| - {:else} |
170 |
| - <Button variant="destructive" on:click={deleteAsset(asset.id)}>Delete</Button> |
171 |
| - {/if} |
172 |
| - </div> |
173 |
| - </Dialog.Content> |
174 |
| -</Dialog.Root> |
0 commit comments