From ee7cf20202fda36dfae489840454a216cda47c8f Mon Sep 17 00:00:00 2001 From: Stephan Richter Date: Tue, 3 Feb 2026 16:15:09 +0100 Subject: [PATCH] added cache for task and wiki page markdown editor, reverted previous attempt Signed-off-by: Stephan Richter --- frontend/src/Components/MarkdownEditor.svelte | 30 ++- frontend/src/routes/task/Add.svelte | 193 +++++++----------- frontend/src/routes/task/View.svelte | 2 +- frontend/src/routes/wiki/AddPage.svelte | 3 +- frontend/src/routes/wiki/View.svelte | 2 +- translations/src/main/resources/de.json | 1 + translations/src/main/resources/en.json | 1 + 7 files changed, 104 insertions(+), 128 deletions(-) diff --git a/frontend/src/Components/MarkdownEditor.svelte b/frontend/src/Components/MarkdownEditor.svelte index 53eea6c5..c54e8e1c 100644 --- a/frontend/src/Components/MarkdownEditor.svelte +++ b/frontend/src/Components/MarkdownEditor.svelte @@ -6,9 +6,9 @@ let { editable = true, onclick = evt => {}, - onRender = src => {}, onSet = newVal => {return true;}, simple = false, + store_id = null, type = 'div', value = $bindable({source:null,rendered:null}) } = $props(); @@ -16,6 +16,7 @@ let editing = $state(false); let editValue = $state({source:value.source,rendered:value.rendered}); let start = 0; + let stored_source = $state(store_id ? localStorage.getItem(store_id) : null); let timer = null; async function applyEdit(){ @@ -28,6 +29,7 @@ } function doSave(){ + if (store_id) localStorage.removeItem(store_id); if (simple){ onSet(editValue.source); } else applyEdit(); @@ -51,7 +53,7 @@ body : editValue.source }); editValue.rendered = await resp.text(); - onRender(editValue.source); + if (store_id) localStorage.setItem(store_id,editValue.source); } function typed(ev){ @@ -102,13 +104,37 @@ measured(evt, evt.timeStamp - start); } + function restore(ev){ + editValue.source = stored_source; + stored_source = null; + render(); + } + activeField.subscribe((val) => resetEdit()); if (simple) startEdit(); + +
{#if editing} {@html t('markdown_supported')} + {#if stored_source} + {t('unsaved_content')} + {/if}
{@html target(editValue.rendered)}
{#if !simple} diff --git a/frontend/src/routes/task/Add.svelte b/frontend/src/routes/task/Add.svelte index 3931497f..fddb9cd9 100644 --- a/frontend/src/routes/task/Add.svelte +++ b/frontend/src/routes/task/Add.svelte @@ -16,8 +16,8 @@ let extendedSettings = $state(false); let parent_task = $state(null); let task = $state({ - name : localStorage.getItem('task.name'), - description : { source : localStorage.getItem('task.markdown'), rendered : '' }, + name : '', + description : { source:'',rendered:''}, due_date : null, est_time : null, members : {}, @@ -110,8 +110,7 @@ body : JSON.stringify(task) }); if (resp.ok) { - localStorage.removeItem('task.markdown'); - localStorage.removeItem('task.name'); + localStorage.removeItem(`task/${task.id}/description`); if (!assignee) { // if assignee is set, this form was opened within an external context. hence we don`t want to navigate somewhere else! task = await resp.json(); if (task.parent_task_id){ @@ -124,12 +123,6 @@ } } - function storeSource(markdown){ - if (markdown) localStorage.setItem('task.markdown',markdown); - localStorage.setItem('task.name',task.name); - } - - function toggleSettings(){ extendedSettings = !extendedSettings; } @@ -143,120 +136,74 @@
{t('add_object',{object:t('task')})} - - - - - - - {#if project} - - - - - {/if} - {#if parent_task} - - - - - {/if} +
+
{t('name')}
+
+ +
-
- - - - - - - - {#if extendedSettings} - - - - - - - - - - - - - - - - - - - - - - - - - {:else} - - - - - {/if} - -
- {t('name')} - - -
- {t('project')} - - {project.name} -
- {t('parent_task')} - - {parent_task.name} -
- {t('description')} - - -
- {t('tags')} - - -
- {t('members')} - - -
- {t('estimated_time')} - - {t('hours')} -
- {t('start_date')} - - -
- {t('due_date')} - - -
- {t('subtasks')} - - -
- {t('index_page')} - - -
- {t('extended_settings')} - - -
+ {#if project} +
{t('project')}
+ {project.name} + {/if} + + {#if parent_task} +
{t('parent_task')}
+
{parent_task.name}
+ {/if} + +
{t('description')}
+
+ +
+
{t('tags')}
+
+ +
+ + {#if extendedSettings} +
{t('members')}
+
+ +
+ +
{t('estimated_time')}
+
+ {t('hours')} +
+ +
{t('start_date')}
+
+ +
+ +
{t('due_date')}
+
+ +
+ +
{t('subtasks')}
+
+ +
+ +
+ {t('index_page')} +
+ + {:else} +
{t('extended_settings')}
+
+ +
+ {/if} +
{#if on_abort} diff --git a/frontend/src/routes/task/View.svelte b/frontend/src/routes/task/View.svelte index ce415259..d8077dcb 100644 --- a/frontend/src/routes/task/View.svelte +++ b/frontend/src/routes/task/View.svelte @@ -241,7 +241,7 @@ {#if task.description}
{t('description')}
- update({description:val})} /> + update({description:val})} /> {/if} {#if !showSettings && task.start_date}
{t('start_date')}
diff --git a/frontend/src/routes/wiki/AddPage.svelte b/frontend/src/routes/wiki/AddPage.svelte index 94158abb..7849ce08 100644 --- a/frontend/src/routes/wiki/AddPage.svelte +++ b/frontend/src/routes/wiki/AddPage.svelte @@ -22,6 +22,7 @@ }); if (res.ok){ yikes(); + localStorage.removeItem('wiki/new/content'); router.navigate(`/wiki/${title}/view`); } else { error(res); @@ -60,7 +61,7 @@ \ No newline at end of file diff --git a/frontend/src/routes/wiki/View.svelte b/frontend/src/routes/wiki/View.svelte index 09c51fe6..78d87608 100644 --- a/frontend/src/routes/wiki/View.svelte +++ b/frontend/src/routes/wiki/View.svelte @@ -188,7 +188,7 @@ {/if} {/if} - patch({content:s})} /> + patch({content:s})} store_id="wiki/{page.id}/description" /> +id)} />

{t('notes')}

diff --git a/translations/src/main/resources/de.json b/translations/src/main/resources/de.json index 00cc7b21..247e7027 100644 --- a/translations/src/main/resources/de.json +++ b/translations/src/main/resources/de.json @@ -399,6 +399,7 @@ "unit_price": "Preis/Einheit", "unknown_item_location": "Artikel {0} von {1} {2} ist verknüpft mit unbekanntem Lagerort {3}!", "unlink": "Trennen", + "unsaved_content": "Hier klicken, um ungespeicherte Änderungen zu laden", "update": "aktualisieren", "UPDATE_USERS" : "Nutzer aktualisieren", "upload_file": "Datei hochladen", diff --git a/translations/src/main/resources/en.json b/translations/src/main/resources/en.json index 1925432e..5bc60bb4 100644 --- a/translations/src/main/resources/en.json +++ b/translations/src/main/resources/en.json @@ -399,6 +399,7 @@ "unit_price": "price/unit", "unknown_item_location": "Item {0} of {1} {2} refers to location {3}, which is unknown!", "unlink": "unlink", + "unsaved_content": "Click here to load unsaved changes", "update": "update", "UPDATE_USERS" : "update users", "upload_file": "upload file",