📚 The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.
Vue dockergolangkanbanknowledge-baseknowledge-managementmarkdownnote-takingnotesnotes-appnotionnuxtnuxtjsoffline-firstoidcpwaselfhostedssovuevuejswiki
Debounce docs saving, close #68
Smaug67396d0066277051
diff --git a/frontend/app/components/MarkdownEditor/LazyMarkdownEditor.vue b/frontend/app/components/MarkdownEditor/LazyMarkdownEditor.vueindex 7b0b00ed..bc256a61 100644--- a/frontend/app/components/MarkdownEditor/LazyMarkdownEditor.vue+++ b/frontend/app/components/MarkdownEditor/LazyMarkdownEditor.vue@@ -382,12 +382,12 @@ function syncScroll() {markdownPreview.value.scrollTop = scrollPercentage * (markdownPreview.value.scrollHeight - markdownPreview.value.clientHeight);}-function save() {+const save = debounce(() => {const content = editorView.value?.state.doc.toString() || '';document.value.content_markdown = content;document.value.content_html = compile(content);emit('save', document.value);-}+}, 1000);</script><style scoped lang="scss">diff --git a/frontend/app/composables/utils.ts b/frontend/app/composables/utils.tsindex e99178b1..2483d7d5 100644--- a/frontend/app/composables/utils.ts+++ b/frontend/app/composables/utils.ts@@ -37,3 +37,28 @@ export function setAppColor(color: string | number) {document.documentElement.style.setProperty('--primary-bg', `var(--${color}-bg)`);document.documentElement.style.setProperty('--primary-border', `var(--${color}-border)`);}++export function debounce<T extends (...args: unknown[]) => void>(fn: T, delay = 500) {+ let timeout: ReturnType<typeof setTimeout> | null = null;+ let called = false;++ return (...args: Parameters<T>) => {+ if (!called) {+ // premier appel : exécution immédiate+ fn(...args);+ called = true;+ timeout = setTimeout(() => {+ called = false;+ timeout = null;+ }, delay);+ } else {+ // si on spam, on relance le timer et on exécute à la fin+ if (timeout) clearTimeout(timeout);+ timeout = setTimeout(() => {+ fn(...args);+ called = false;+ timeout = null;+ }, delay);+ }+ };+}