From 4acd278624f0005d5dd83a8b7b466ebbb34b72d6 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sat, 3 May 2025 22:53:23 +0400 Subject: [PATCH] refac --- .../components/channel/MessageInput.svelte | 6 +- src/lib/components/chat/MessageInput.svelte | 6 +- .../chat/MessageInput/VoiceRecording.svelte | 149 +++++++++------- .../components/common/RichTextInput.svelte | 164 +++++++++-------- src/lib/components/icons/Calendar.svelte | 19 ++ src/lib/components/icons/CalendarSolid.svelte | 11 ++ src/lib/components/icons/Users.svelte | 19 ++ src/lib/components/notes/NoteEditor.svelte | 167 ++++++++++++------ src/lib/components/notes/Notes.svelte | 39 ++-- src/lib/components/playground/Notes.svelte | 6 +- .../KnowledgeBase/AddTextContentModal.svelte | 6 +- 11 files changed, 370 insertions(+), 222 deletions(-) create mode 100644 src/lib/components/icons/Calendar.svelte create mode 100644 src/lib/components/icons/CalendarSolid.svelte create mode 100644 src/lib/components/icons/Users.svelte diff --git a/src/lib/components/channel/MessageInput.svelte b/src/lib/components/channel/MessageInput.svelte index 9f495a8de..d60851fc8 100644 --- a/src/lib/components/channel/MessageInput.svelte +++ b/src/lib/components/channel/MessageInput.svelte @@ -357,14 +357,14 @@ {#if recording} { + onCancel={async () => { recording = false; await tick(); document.getElementById(`chat-input-${id}`)?.focus(); }} - on:confirm={async (e) => { - const { text, filename } = e.detail; + onConfirm={async (data) => { + const { text, filename } = data; content = `${content}${text} `; recording = false; diff --git a/src/lib/components/chat/MessageInput.svelte b/src/lib/components/chat/MessageInput.svelte index d31861459..bcf28f61c 100644 --- a/src/lib/components/chat/MessageInput.svelte +++ b/src/lib/components/chat/MessageInput.svelte @@ -479,14 +479,14 @@ {#if recording} { + onCancel={async () => { recording = false; await tick(); document.getElementById('chat-input')?.focus(); }} - on:confirm={async (e) => { - const { text, filename } = e.detail; + onConfirm={async (data) => { + const { text, filename } = data; prompt = `${prompt}${text} `; recording = false; diff --git a/src/lib/components/chat/MessageInput/VoiceRecording.svelte b/src/lib/components/chat/MessageInput/VoiceRecording.svelte index 70472055f..726e26bbb 100644 --- a/src/lib/components/chat/MessageInput/VoiceRecording.svelte +++ b/src/lib/components/chat/MessageInput/VoiceRecording.svelte @@ -1,6 +1,6 @@
diff --git a/src/lib/components/icons/Calendar.svelte b/src/lib/components/icons/Calendar.svelte new file mode 100644 index 000000000..4406015fd --- /dev/null +++ b/src/lib/components/icons/Calendar.svelte @@ -0,0 +1,19 @@ + + + + + diff --git a/src/lib/components/icons/CalendarSolid.svelte b/src/lib/components/icons/CalendarSolid.svelte new file mode 100644 index 000000000..3f75fc91b --- /dev/null +++ b/src/lib/components/icons/CalendarSolid.svelte @@ -0,0 +1,11 @@ + + + + + diff --git a/src/lib/components/icons/Users.svelte b/src/lib/components/icons/Users.svelte new file mode 100644 index 000000000..9ef032dd7 --- /dev/null +++ b/src/lib/components/icons/Users.svelte @@ -0,0 +1,19 @@ + + + + + diff --git a/src/lib/components/notes/NoteEditor.svelte b/src/lib/components/notes/NoteEditor.svelte index c12511e04..3d2ebf837 100644 --- a/src/lib/components/notes/NoteEditor.svelte +++ b/src/lib/components/notes/NoteEditor.svelte @@ -3,26 +3,58 @@ const i18n = getContext('i18n'); import { toast } from 'svelte-sonner'; - import { getNoteById } from '$lib/apis/notes'; + + import { showSidebar } from '$lib/stores'; + import { goto } from '$app/navigation'; + + import dayjs from '$lib/dayjs'; + import calendar from 'dayjs/plugin/calendar'; + import duration from 'dayjs/plugin/duration'; + import relativeTime from 'dayjs/plugin/relativeTime'; + + dayjs.extend(calendar); + dayjs.extend(duration); + dayjs.extend(relativeTime); + + async function loadLocale(locales) { + for (const locale of locales) { + try { + dayjs.locale(locale); + break; // Stop after successfully loading the first available locale + } catch (error) { + console.error(`Could not load locale '${locale}':`, error); + } + } + } + + // Assuming $i18n.languages is an array of language codes + $: loadLocale($i18n.languages); + + import { getNoteById, updateNoteById } from '$lib/apis/notes'; import RichTextInput from '../common/RichTextInput.svelte'; import Spinner from '../common/Spinner.svelte'; - import Sparkles from '../icons/Sparkles.svelte'; - import SparklesSolid from '../icons/SparklesSolid.svelte'; import Mic from '../icons/Mic.svelte'; import VoiceRecording from '../chat/MessageInput/VoiceRecording.svelte'; import Tooltip from '../common/Tooltip.svelte'; - import { showSidebar } from '$lib/stores'; + + import Calendar from '../icons/Calendar.svelte'; + import Users from '../icons/Users.svelte'; export let id: null | string = null; - let title = ''; - let data = { - content: '', - files: [] + let note = { + title: '', + data: { + content: { + json: null, + html: '', + md: '' + } + }, + meta: null, + access_control: null }; - let meta = null; - let accessControl = null; let voiceInput = false; let loading = false; @@ -35,15 +67,38 @@ }); if (res) { - title = res.title; - data = res.data; - meta = res.meta; - accessControl = res.access_control; + note = res; + } else { + toast.error($i18n.t('Note not found')); + goto('/notes'); + return; } loading = false; }; + let debounceTimeout: NodeJS.Timeout | null = null; + + const changeDebounceHandler = () => { + console.log('debounce'); + if (debounceTimeout) { + clearTimeout(debounceTimeout); + } + + debounceTimeout = setTimeout(async () => { + const res = await updateNoteById(localStorage.token, id, { + ...note, + title: note.title === '' ? $i18n.t('Untitled') : note.title + }).catch((e) => { + toast.error(`${e}`); + }); + }, 200); + }; + + $: if (note) { + changeDebounceHandler(); + } + $: if (id) { init(); } @@ -56,35 +111,55 @@
- {/if} + {:else} +
+
+
+ +
+
-
-
-
- + + + +
+ +
+ { + note.data.html = content.html; + note.data.md = content.md; + }} />
- -
- -
-
+ {/if}
-
+
@@ -93,24 +168,12 @@ { + transcribe={false} + onCancel={() => { voiceInput = false; }} - on:confirm={(e) => { - const { text, filename } = e.detail; - - // url is hostname + /cache/audio/transcription/ + filename - const url = `${window.location.origin}/cache/audio/transcription/${filename}`; - - // Open in new tab - - if (content.trim() !== '') { - content = `${content}\n\n${text}\n\nRecording: ${url}\n\n`; - } else { - content = `${content}${text}\n\nRecording: ${url}\n\n`; - } - - voiceInput = false; + onConfirm={(data) => { + console.log(data); }} />
diff --git a/src/lib/components/notes/Notes.svelte b/src/lib/components/notes/Notes.svelte index 2ff3503fb..fd8ff6b1b 100644 --- a/src/lib/components/notes/Notes.svelte +++ b/src/lib/components/notes/Notes.svelte @@ -58,7 +58,11 @@ const res = await createNewNote(localStorage.token, { title: $i18n.t('New Note'), data: { - content: '' + content: { + json: null, + html: '', + md: '' + } }, meta: null, access_control: null @@ -95,30 +99,37 @@
-
+
{#if Object.keys(notes).length > 0} {#each Object.keys(notes) as timeRange}
{$i18n.t(timeRange)}
-