From 4386e5abb896ba0ecf955a841df178b30aaa80c7 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Tue, 18 Nov 2025 18:37:57 -0500 Subject: [PATCH] refac/enh: create new note --- src/lib/components/notes/Notes.svelte | 30 ----- src/routes/(app)/notes/+page.svelte | 165 +++++++++++++---------- src/routes/(app)/notes/[id]/+page.svelte | 23 +++- src/routes/(app)/notes/new/+page.svelte | 20 +++ src/routes/(app)/notes/utils.ts | 26 ++++ 5 files changed, 163 insertions(+), 101 deletions(-) create mode 100644 src/routes/(app)/notes/new/+page.svelte create mode 100644 src/routes/(app)/notes/utils.ts diff --git a/src/lib/components/notes/Notes.svelte b/src/lib/components/notes/Notes.svelte index 14f1392625..43d7bb6e36 100644 --- a/src/lib/components/notes/Notes.svelte +++ b/src/lib/components/notes/Notes.svelte @@ -101,30 +101,6 @@ }); }; - const createNoteHandler = async (content?: string) => { - // $i18n.t('New Note'), - const res = await createNewNote(localStorage.token, { - // YYYY-MM-DD - title: dayjs().format('YYYY-MM-DD'), - data: { - content: { - json: null, - html: content ?? '', - md: content ?? '' - } - }, - meta: null, - access_control: {} - }).catch((error) => { - toast.error(`${error}`); - return null; - }); - - if (res) { - goto(`/notes/${res.id}`); - } - }; - const downloadHandler = async (type) => { if (type === 'txt') { const blob = new Blob([selectedNote.data.content.md], { type: 'text/plain' }); @@ -241,12 +217,6 @@ }); onMount(async () => { - if ($page.url.searchParams.get('content') !== null) { - const content = $page.url.searchParams.get('content') ?? ''; - createNoteHandler(content); - return; - } - await init(); loaded = true; diff --git a/src/routes/(app)/notes/+page.svelte b/src/routes/(app)/notes/+page.svelte index 8a57e18c16..759f16e018 100644 --- a/src/routes/(app)/notes/+page.svelte +++ b/src/routes/(app)/notes/+page.svelte @@ -1,87 +1,116 @@ -
- + -
- +
+ +
-
+{/if} diff --git a/src/routes/(app)/notes/[id]/+page.svelte b/src/routes/(app)/notes/[id]/+page.svelte index 390c1de313..76e3497f6c 100644 --- a/src/routes/(app)/notes/[id]/+page.svelte +++ b/src/routes/(app)/notes/[id]/+page.svelte @@ -1,10 +1,27 @@ -
- -
+{#if loaded} +
+ +
+{/if} diff --git a/src/routes/(app)/notes/new/+page.svelte b/src/routes/(app)/notes/new/+page.svelte new file mode 100644 index 0000000000..94e8042295 --- /dev/null +++ b/src/routes/(app)/notes/new/+page.svelte @@ -0,0 +1,20 @@ + diff --git a/src/routes/(app)/notes/utils.ts b/src/routes/(app)/notes/utils.ts new file mode 100644 index 0000000000..d963daf822 --- /dev/null +++ b/src/routes/(app)/notes/utils.ts @@ -0,0 +1,26 @@ +import { createNewNote } from '$lib/apis/notes'; +import { toast } from 'svelte-sonner'; + +export const createNoteHandler = async (title: string, content?: string) => { + // $i18n.t('New Note'), + const res = await createNewNote(localStorage.token, { + // YYYY-MM-DD + title: title, + data: { + content: { + json: null, + html: content ?? '', + md: content ?? '' + } + }, + meta: null, + access_control: {} + }).catch((error) => { + toast.error(`${error}`); + return null; + }); + + if (res) { + return res; + } +};