refac/enh: create new note
Some checks are pending
Deploy to HuggingFace Spaces / check-secret (push) Waiting to run
Deploy to HuggingFace Spaces / deploy (push) Blocked by required conditions
Create and publish Docker images with specific build args / build-main-image (linux/amd64, ubuntu-latest) (push) Waiting to run
Create and publish Docker images with specific build args / merge-slim-images (push) Blocked by required conditions
Create and publish Docker images with specific build args / build-main-image (linux/arm64, ubuntu-24.04-arm) (push) Waiting to run
Create and publish Docker images with specific build args / build-cuda-image (linux/amd64, ubuntu-latest) (push) Waiting to run
Create and publish Docker images with specific build args / build-cuda-image (linux/arm64, ubuntu-24.04-arm) (push) Waiting to run
Create and publish Docker images with specific build args / build-cuda126-image (linux/amd64, ubuntu-latest) (push) Waiting to run
Create and publish Docker images with specific build args / build-cuda126-image (linux/arm64, ubuntu-24.04-arm) (push) Waiting to run
Create and publish Docker images with specific build args / build-ollama-image (linux/amd64, ubuntu-latest) (push) Waiting to run
Create and publish Docker images with specific build args / build-ollama-image (linux/arm64, ubuntu-24.04-arm) (push) Waiting to run
Create and publish Docker images with specific build args / build-slim-image (linux/amd64, ubuntu-latest) (push) Waiting to run
Create and publish Docker images with specific build args / build-slim-image (linux/arm64, ubuntu-24.04-arm) (push) Waiting to run
Create and publish Docker images with specific build args / merge-main-images (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge-cuda-images (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge-cuda126-images (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge-ollama-images (push) Blocked by required conditions
Python CI / Format Backend (push) Waiting to run
Frontend Build / Format & Build Frontend (push) Waiting to run
Frontend Build / Frontend Unit Tests (push) Waiting to run

This commit is contained in:
Timothy Jaeryang Baek 2025-11-18 18:37:57 -05:00
parent 07ef295a77
commit 4386e5abb8
5 changed files with 163 additions and 101 deletions

View file

@ -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) => { const downloadHandler = async (type) => {
if (type === 'txt') { if (type === 'txt') {
const blob = new Blob([selectedNote.data.content.md], { type: 'text/plain' }); const blob = new Blob([selectedNote.data.content.md], { type: 'text/plain' });
@ -241,12 +217,6 @@
}); });
onMount(async () => { onMount(async () => {
if ($page.url.searchParams.get('content') !== null) {
const content = $page.url.searchParams.get('content') ?? '';
createNoteHandler(content);
return;
}
await init(); await init();
loaded = true; loaded = true;

View file

@ -1,87 +1,116 @@
<script> <script>
import { mobile, showArchivedChats, showSidebar, user } from '$lib/stores'; import { getContext, onMount } from 'svelte';
import { getContext } from 'svelte';
const i18n = getContext('i18n'); const i18n = getContext('i18n');
import dayjs from '$lib/dayjs';
import { mobile, showArchivedChats, showSidebar, user } from '$lib/stores';
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import { createNoteHandler } from './utils';
import UserMenu from '$lib/components/layout/Sidebar/UserMenu.svelte'; import UserMenu from '$lib/components/layout/Sidebar/UserMenu.svelte';
import Notes from '$lib/components/notes/Notes.svelte'; import Notes from '$lib/components/notes/Notes.svelte';
import Tooltip from '$lib/components/common/Tooltip.svelte'; import Tooltip from '$lib/components/common/Tooltip.svelte';
import Sidebar from '$lib/components/icons/Sidebar.svelte'; import Sidebar from '$lib/components/icons/Sidebar.svelte';
let loaded = false;
onMount(async () => {
if (
$page.url.searchParams.get('content') !== null ||
$page.url.searchParams.get('title') !== null
) {
const title = $page.url.searchParams.get('title') ?? dayjs().format('YYYY-MM-DD');
const content = $page.url.searchParams.get('content') ?? '';
const res = await createNoteHandler(title, content);
if (res) {
goto(`/notes/${res.id}`);
}
return;
}
loaded = true;
});
</script> </script>
<div {#if loaded}
class=" flex flex-col w-full h-screen max-h-[100dvh] transition-width duration-200 ease-in-out {$showSidebar <div
? 'md:max-w-[calc(100%-260px)]' class=" flex flex-col w-full h-screen max-h-[100dvh] transition-width duration-200 ease-in-out {$showSidebar
: ''} max-w-full" ? 'md:max-w-[calc(100%-260px)]'
> : ''} max-w-full"
<nav class=" px-2 pt-1.5 backdrop-blur-xl w-full drag-region"> >
<div class=" flex items-center"> <nav class=" px-2 pt-1.5 backdrop-blur-xl w-full drag-region">
{#if $mobile} <div class=" flex items-center">
<div class="{$showSidebar ? 'md:hidden' : ''} flex flex-none items-center"> {#if $mobile}
<Tooltip <div class="{$showSidebar ? 'md:hidden' : ''} flex flex-none items-center">
content={$showSidebar ? $i18n.t('Close Sidebar') : $i18n.t('Open Sidebar')} <Tooltip
interactive={true} content={$showSidebar ? $i18n.t('Close Sidebar') : $i18n.t('Open Sidebar')}
> interactive={true}
<button
id="sidebar-toggle-button"
class=" cursor-pointer flex rounded-lg hover:bg-gray-100 dark:hover:bg-gray-850 transition cursor-"
on:click={() => {
showSidebar.set(!$showSidebar);
}}
>
<div class=" self-center p-1.5">
<Sidebar />
</div>
</button>
</Tooltip>
</div>
{/if}
<div class="ml-2 py-0.5 self-center flex items-center justify-between w-full">
<div class="">
<div
class="flex gap-1 scrollbar-none overflow-x-auto w-fit text-center text-sm font-medium bg-transparent py-1 touch-auto pointer-events-auto"
>
<a class="min-w-fit transition" href="/notes">
{$i18n.t('Notes')}
</a>
</div>
</div>
<div class=" self-center flex items-center gap-1">
{#if $user !== undefined && $user !== null}
<UserMenu
className="max-w-[240px]"
role={$user?.role}
help={true}
on:show={(e) => {
if (e.detail === 'archived-chat') {
showArchivedChats.set(true);
}
}}
> >
<button <button
class="select-none flex rounded-xl p-1.5 w-full hover:bg-gray-50 dark:hover:bg-gray-850 transition" id="sidebar-toggle-button"
aria-label="User Menu" class=" cursor-pointer flex rounded-lg hover:bg-gray-100 dark:hover:bg-gray-850 transition cursor-"
on:click={() => {
showSidebar.set(!$showSidebar);
}}
> >
<div class=" self-center"> <div class=" self-center p-1.5">
<img <Sidebar />
src={$user?.profile_image_url}
class="size-6 object-cover rounded-full"
alt="User profile"
draggable="false"
/>
</div> </div>
</button> </button>
</UserMenu> </Tooltip>
{/if} </div>
{/if}
<div class="ml-2 py-0.5 self-center flex items-center justify-between w-full">
<div class="">
<div
class="flex gap-1 scrollbar-none overflow-x-auto w-fit text-center text-sm font-medium bg-transparent py-1 touch-auto pointer-events-auto"
>
<a class="min-w-fit transition" href="/notes">
{$i18n.t('Notes')}
</a>
</div>
</div>
<div class=" self-center flex items-center gap-1">
{#if $user !== undefined && $user !== null}
<UserMenu
className="max-w-[240px]"
role={$user?.role}
help={true}
on:show={(e) => {
if (e.detail === 'archived-chat') {
showArchivedChats.set(true);
}
}}
>
<button
class="select-none flex rounded-xl p-1.5 w-full hover:bg-gray-50 dark:hover:bg-gray-850 transition"
aria-label="User Menu"
>
<div class=" self-center">
<img
src={$user?.profile_image_url}
class="size-6 object-cover rounded-full"
alt="User profile"
draggable="false"
/>
</div>
</button>
</UserMenu>
{/if}
</div>
</div> </div>
</div> </div>
</div> </nav>
</nav>
<div class=" pb-1 flex-1 max-h-full overflow-y-auto @container"> <div class=" pb-1 flex-1 max-h-full overflow-y-auto @container">
<Notes /> <Notes />
</div>
</div> </div>
</div> {/if}

View file

@ -1,10 +1,27 @@
<script lang="ts"> <script lang="ts">
import { onMount } from 'svelte';
import { goto } from '$app/navigation';
import { page } from '$app/stores'; import { page } from '$app/stores';
import { showSidebar } from '$lib/stores'; import { showSidebar } from '$lib/stores';
import dayjs from '$lib/dayjs';
import { createNoteHandler } from '../utils';
import NoteEditor from '$lib/components/notes/NoteEditor.svelte'; import NoteEditor from '$lib/components/notes/NoteEditor.svelte';
let loaded = false;
onMount(async () => {
loaded = true;
});
</script> </script>
<div id="note-container" class="w-full h-full {$showSidebar ? 'md:max-w-[calc(100%-260px)]' : ''}"> {#if loaded}
<NoteEditor id={$page.params.id} /> <div
</div> id="note-container"
class="w-full h-full {$showSidebar ? 'md:max-w-[calc(100%-260px)]' : ''}"
>
<NoteEditor id={$page.params.id} />
</div>
{/if}

View file

@ -0,0 +1,20 @@
<script lang="ts">
import { onMount } from 'svelte';
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import dayjs from '$lib/dayjs';
import { createNoteHandler } from '../utils';
onMount(async () => {
const title = $page.url.searchParams.get('title') ?? dayjs().format('YYYY-MM-DD');
const content = $page.url.searchParams.get('content') ?? '';
const res = await createNoteHandler(title, content);
if (res) {
goto(`/notes/${res.id}`);
}
});
</script>

View file

@ -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;
}
};