|
1 | 1 | <script lang="ts">
|
2 |
| - import { CheckIcon, ExternalLinkIcon, UndoIcon } from 'lucide-svelte'; |
| 2 | + import { |
| 3 | + BookmarkIcon, |
| 4 | + BookmarkXIcon, |
| 5 | + CheckIcon, |
| 6 | + ExternalLinkIcon, |
| 7 | + UndoIcon |
| 8 | + } from 'lucide-svelte'; |
3 | 9 | import type { ComponentType } from 'svelte';
|
4 | 10 | import type { Icon } from 'lucide-svelte';
|
5 | 11 | import * as Tooltip from '$lib/components/ui/tooltip';
|
|
12 | 18 | id: number;
|
13 | 19 | link: string;
|
14 | 20 | unread: boolean;
|
| 21 | + bookmark: boolean; |
15 | 22 | };
|
16 | 23 |
|
17 | 24 | function getActions(
|
18 |
| - unread: boolean |
| 25 | + unread: boolean, |
| 26 | + bookmark: boolean |
19 | 27 | ): { icon: ComponentType<Icon>; tooltip: string; handler: (e: Event) => void }[] {
|
20 |
| - const list = [ |
21 |
| - // { icon: BookmarkIcon, tooltip: 'Save to Bookmark', handler: handleSaveToBookmark }, |
22 |
| - { icon: ExternalLinkIcon, tooltip: 'Visit Original Link', handler: handleExternalLink } |
23 |
| - ]; |
| 28 | + const visitOriginalAction = { |
| 29 | + icon: ExternalLinkIcon, |
| 30 | + tooltip: 'Visit Original Link', |
| 31 | + handler: handleExternalLink |
| 32 | + }; |
24 | 33 | const unreadAction = unread
|
25 |
| - ? { icon: CheckIcon, tooltip: 'Mark as Read', handler: handleMarkAsRead } |
26 |
| - : { icon: UndoIcon, tooltip: 'Mark as Unread', handler: handleMarkAsUnread }; |
27 |
| - list.unshift(unreadAction); |
28 |
| - return list; |
| 34 | + ? { icon: CheckIcon, tooltip: 'Mark as Read', handler: handleToggleUnread } |
| 35 | + : { icon: UndoIcon, tooltip: 'Mark as Unread', handler: handleToggleUnread }; |
| 36 | + const bookmarkAction = bookmark |
| 37 | + ? { icon: BookmarkXIcon, tooltip: 'Cancel Bookmark', handler: handleToggleBookmark } |
| 38 | + : { icon: BookmarkIcon, tooltip: 'Add to Bookmark', handler: handleToggleBookmark }; |
| 39 | +
|
| 40 | + return [unreadAction, bookmarkAction, visitOriginalAction]; |
29 | 41 | }
|
30 |
| - $: actions = getActions(data.unread); |
| 42 | + $: actions = getActions(data.unread, data.bookmark); |
31 | 43 |
|
32 |
| - async function handleMarkAsRead(e: Event) { |
| 44 | + async function handleToggleUnread(e: Event) { |
33 | 45 | e.preventDefault();
|
34 | 46 | try {
|
35 |
| - await updateItem(data.id, false); |
| 47 | + await updateItem(data.id, { unread: !data.unread }); |
| 48 | + invalidateAll(); |
36 | 49 | } catch (e) {
|
37 | 50 | toast.error((e as Error).message);
|
38 | 51 | }
|
39 |
| - invalidateAll(); |
40 | 52 | }
|
41 | 53 |
|
42 |
| - async function handleMarkAsUnread(e: Event) { |
| 54 | + function handleExternalLink(e: Event) { |
| 55 | + e.preventDefault(); |
| 56 | + handleToggleUnread(e); |
| 57 | + window.open(data.link, '_target'); |
| 58 | + } |
| 59 | +
|
| 60 | + async function handleToggleBookmark(e: Event) { |
43 | 61 | e.preventDefault();
|
44 | 62 | try {
|
45 |
| - await updateItem(data.id, true); |
| 63 | + await updateItem(data.id, { bookmark: !data.bookmark }); |
| 64 | + invalidateAll(); |
46 | 65 | } catch (e) {
|
47 | 66 | toast.error((e as Error).message);
|
48 | 67 | }
|
49 |
| - invalidateAll(); |
50 |
| - } |
51 |
| -
|
52 |
| - function handleExternalLink(e: Event) { |
53 |
| - e.preventDefault(); |
54 |
| - handleMarkAsRead(e); |
55 |
| - window.open(data.link, '_target'); |
56 | 68 | }
|
57 | 69 | </script>
|
58 | 70 |
|
|
0 commit comments