diff --git a/src/lib/components/Course/components/Lesson/Materials/index.svelte b/src/lib/components/Course/components/Lesson/Materials/index.svelte index c8747af8..4996b264 100644 --- a/src/lib/components/Course/components/Lesson/Materials/index.svelte +++ b/src/lib/components/Course/components/Lesson/Materials/index.svelte @@ -117,6 +117,9 @@ function updateNoteByCompletion(completion) { $lesson.materials.note = completion; + + autoSave($lesson.materials); + if (editorWindowRef) { const tmceBody = editorWindowRef?.document?.querySelector('body'); @@ -148,8 +151,7 @@ window.players = players; } - function autoSave(updatedMaterials, _isLoading: boolean, lessonId: string) { - isSaving = false; + function autoSave(updatedMaterials, _isLoading?: boolean, lessonId?: string) { if (timeoutId) clearTimeout(timeoutId); if (!initAutoSave) { @@ -160,7 +162,6 @@ isSaving = true; timeoutId = setTimeout(async () => { await saveLesson(updatedMaterials); - isSaving = false; }, 500); } @@ -169,8 +170,9 @@ $isLessonDirty = true; } - function onLessonIdChange() { + function onLessonIdChange(_lid: string) { initAutoSave = false; + isSaving = false; } const onClose = () => { @@ -249,6 +251,7 @@
($lesson.materials.note = html)} diff --git a/src/lib/components/TextEditor/index.svelte b/src/lib/components/TextEditor/index.svelte index 5c57f5d7..5bf850a1 100644 --- a/src/lib/components/TextEditor/index.svelte +++ b/src/lib/components/TextEditor/index.svelte @@ -2,6 +2,7 @@ import { PUBLIC_TINYMCE_API_KEY } from '$env/static/public'; import Editor from '@tinymce/tinymce-svelte'; + export let id = ''; export let value: string; export let onChange = (html = '') => {}; export let height = 300; @@ -26,11 +27,16 @@ placeholder: placeholder, init_instance_callback: function (editor: any) { editorWindowRef = editor.iframeElement?.contentWindow; - editor.on('Input', function () { + editor.on('Change', function () { const html = editor.getContent(); if (onChange) { onChange(html); } + + // backup in case the data doesn't get to our backend, we should store the note to avoid data loss + if (id) { + localStorage.setItem(id, html); + } }); } };