diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index ddead1b..9f67e55 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -13,7 +13,12 @@ }, "tauri": { "allowlist": { - "all": true + "all": true, + "clipboard": { + "all": true, + "writeText": true, + "readText": true + } }, "bundle": { "active": true, diff --git a/src/App.svelte b/src/App.svelte index af5a0ab..ca016e3 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -7,8 +7,20 @@ import { SvelteToast } from '@zerodevx/svelte-toast'; import { readCurrentLinks } from './components/utils'; import Loading from '~icons/line-md/loading-loop'; + import { readText } from '@tauri-apps/api/clipboard'; let initialFetch: Promise; + let showForm = false; + let url = ''; + + async function onKeyDown(event: KeyboardEvent) { + // Open save dialog if ctrl+v is used but only if it's not already open + // It then auto-fills the url field with clipboard contents + if (event.ctrlKey && event.key == 'v' && !showForm) { + url = await readText() ?? ""; + showForm = !showForm; + } + } onMount(() => { initialFetch = readCurrentLinks(); @@ -19,8 +31,16 @@
-

- ARK Shelf +

+ ARK Shelf + +

@@ -36,7 +56,13 @@ {/each} {/await}
-
+ + + {#if showForm} + + {/if}
@@ -54,3 +80,5 @@ --toastContainerLeft: auto; } + + \ No newline at end of file diff --git a/src/components/Form.svelte b/src/components/Form.svelte index a75622b..1252816 100644 --- a/src/components/Form.svelte +++ b/src/components/Form.svelte @@ -1,44 +1,44 @@
+ + +
+ + { @@ -69,11 +73,15 @@ url, desc, }; - if ($linksInfos.every(l => l.url !== url)) { + if ($linksInfos.some(link => link.url != url)) { + toast.push("There is already a link with the same URL") + return + } + if ($linksInfos.every(link => link.url !== url)) { const newLink = await createLink(data); if (newLink) { linksInfos.update(links => { - links = links.filter(l => l.url !== url); + links = links.filter(link => link.url !== url); links.push(newLink); return links; }); @@ -82,12 +90,12 @@ } else { toast.push('Error creating link'); } + show = false; } }}> + +
diff --git a/src/components/utils.ts b/src/components/utils.ts index c4643bc..eb8f898 100644 --- a/src/components/utils.ts +++ b/src/components/utils.ts @@ -106,15 +106,3 @@ export const createScore = async ({ value, url }: { value: number; url: string } return; } }; - -export const debounce = (callback: unknown, wait = 500) => { - let timeoutId: number; - return (...args: unknown[]) => { - window.clearTimeout(timeoutId); - timeoutId = window.setTimeout(() => { - if (typeof callback === 'function') { - callback(...args); - } - }, wait); - }; -};