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) => {
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;

View file

@ -1,15 +1,43 @@
<script>
import { mobile, showArchivedChats, showSidebar, user } from '$lib/stores';
import { getContext } from 'svelte';
import { getContext, onMount } from 'svelte';
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 Notes from '$lib/components/notes/Notes.svelte';
import Tooltip from '$lib/components/common/Tooltip.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>
{#if loaded}
<div
class=" flex flex-col w-full h-screen max-h-[100dvh] transition-width duration-200 ease-in-out {$showSidebar
? 'md:max-w-[calc(100%-260px)]'
@ -85,3 +113,4 @@
<Notes />
</div>
</div>
{/if}

View file

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