From ef98e1aa96100cf1e7722ea65edd43af2249ee45 Mon Sep 17 00:00:00 2001 From: Michael Czechowski Date: Tue, 30 Dec 2025 20:50:25 +0100 Subject: [PATCH] feat: cache lesson content for instant restore on reload Store lesson title, description, and task in localStorage after each lesson load. On page reload, immediately restore the cached content to avoid showing "Loading..." placeholder text. --- src/app.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/app.js b/src/app.js index da2c153..7d94024 100644 --- a/src/app.js +++ b/src/app.js @@ -205,6 +205,31 @@ function saveUserSettings() { localStorage.setItem("codeCrispies.settings", JSON.stringify(state.userSettings)); } +// ================= LESSON CACHE ================= + +function restoreLessonCache() { + try { + const cached = localStorage.getItem("codeCrispies.lessonCache"); + if (cached) { + const data = JSON.parse(cached); + if (data.moduleTitle && elements.moduleName) { + elements.moduleName.textContent = data.moduleTitle; + } + if (data.lessonTitle && elements.lessonTitle) { + elements.lessonTitle.textContent = data.lessonTitle; + } + if (data.lessonDescription && elements.lessonDescription) { + elements.lessonDescription.innerHTML = data.lessonDescription; + } + if (data.taskInstruction && elements.taskInstruction) { + elements.taskInstruction.innerHTML = data.taskInstruction; + } + } + } catch (e) { + // Ignore cache errors + } +} + // ================= MODULE INITIALIZATION ================= async function initializeModules() { @@ -406,6 +431,21 @@ function loadCurrentLesson() { requestAnimationFrame(() => { elements.editorSection?.classList.remove("transitioning"); }); + + // Cache lesson display data for instant restore on reload + try { + localStorage.setItem( + "codeCrispies.lessonCache", + JSON.stringify({ + moduleTitle: engineState.module?.title, + lessonTitle: lesson.title, + lessonDescription: lesson.description, + taskInstruction: lesson.task + }) + ); + } catch (e) { + // Ignore storage errors + } } // ================= LIVE PREVIEW ================= @@ -603,6 +643,9 @@ function init() { loadUserSettings(); + // Restore cached lesson content immediately to avoid "Loading..." flash + restoreLessonCache(); + // Initialize CodeMirror editor initCodeEditor();