This commit is contained in:
Timothy Jaeryang Baek 2025-11-19 14:14:53 -05:00
parent 17389e1b66
commit aad23e2e53
6 changed files with 36 additions and 31 deletions

View file

@ -36,7 +36,7 @@
import { createNewNote, deleteNoteById, getNotes } from '$lib/apis/notes';
import { capitalizeFirstLetter, copyToClipboard, getTimeRange } from '$lib/utils';
import { downloadPdf } from './utils';
import { downloadPdf, createNoteHandler } from './utils';
import EllipsisHorizontal from '../icons/EllipsisHorizontal.svelte';
import DeleteConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
@ -393,7 +393,11 @@
class="cursor-pointer p-2.5 flex rounded-full border border-gray-50 bg-white dark:border-none dark:bg-gray-850 hover:bg-gray-50 dark:hover:bg-gray-800 transition shadow-xl"
type="button"
on:click={async () => {
createNoteHandler();
const res = await createNoteHandler(dayjs().format('YYYY-MM-DD'));
if (res) {
goto(`/notes/${res.id}`);
}
}}
>
<Plus className="size-4.5" strokeWidth="2.5" />

View file

@ -1,4 +1,7 @@
import DOMPurify from 'dompurify';
import { toast } from 'svelte-sonner';
import { createNewNote } from '$lib/apis/notes';
export const downloadPdf = async (note) => {
const [{ default: jsPDF }, { default: html2canvas }] = await Promise.all([
@ -103,3 +106,27 @@ export const downloadPdf = async (note) => {
pdf.save(`${note.title}.pdf`);
};
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;
}
};

View file

@ -8,7 +8,7 @@
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import { createNoteHandler } from './utils';
import { createNoteHandler } from '$lib/components/notes/utils';
import UserMenu from '$lib/components/layout/Sidebar/UserMenu.svelte';
import Notes from '$lib/components/notes/Notes.svelte';

View file

@ -6,7 +6,7 @@
import { showSidebar } from '$lib/stores';
import dayjs from '$lib/dayjs';
import { createNoteHandler } from '../utils';
import { createNoteHandler } from '$lib/components/notes/utils';
import NoteEditor from '$lib/components/notes/NoteEditor.svelte';

View file

@ -5,7 +5,7 @@
import { page } from '$app/stores';
import dayjs from '$lib/dayjs';
import { createNoteHandler } from '../utils';
import { createNoteHandler } from '$lib/components/notes/utils';
onMount(async () => {
const title = $page.url.searchParams.get('title') ?? dayjs().format('YYYY-MM-DD');

View file

@ -1,26 +0,0 @@
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;
}
};