feat(05-02): fix reward flow and call sites for paginated forest

- Import SLOTS_PER_PAGE in reward.ts; replace hardcoded 12 with it
- Import SLOTS_PER_PAGE and getForestElements in app.ts
- Zurueck zum Wald callback navigates to page containing new element
- currentForestPage updated in progress before initForestScreen
This commit is contained in:
2026-03-29 23:02:51 +02:00
parent 13b8df5db0
commit 8f888439f2
2 changed files with 16 additions and 7 deletions
+14 -6
View File
@@ -3,8 +3,8 @@ import { companions } from "./companion/characters";
import { getGreeting } from "./companion/companion";
import { renderInlineMarkdown } from "./utils/markdown";
import { initRewardScreen, startPreGeneration } from "./forest/reward";
import { initForestScreen, renderForestScene } from "./forest/scene";
import { getProgress, openDB, saveProgress } from "./storage/db";
import { initForestScreen, renderForestScene, SLOTS_PER_PAGE } from "./forest/scene";
import { getForestElements, getProgress, openDB, saveProgress } from "./storage/db";
import type { ScreenName } from "./types";
import { initParentScreen, showParentCodePrompt } from "./ui/parent";
import { initLessonScreen, initWelcomeScreen } from "./ui/screens";
@@ -119,11 +119,19 @@ async function handleLessonComplete(
);
},
async () => {
// "Zurück zum Wald" -- show forest with new element animated
// "Zurück zum Wald" -- navigate to page containing the new element
const elements = await getForestElements(db);
const newPage = Math.max(0, Math.ceil(elements.length / SLOTS_PER_PAGE) - 1);
// Update progress with new page before initForestScreen reads it
const latestProgress = await getProgress(db);
if (latestProgress) {
latestProgress.currentForestPage = newPage;
await saveProgress(db, latestProgress);
}
await initForestScreen(db, startLessonFromForest);
const prog = await getProgress(db);
const page = prog?.currentForestPage ?? 0;
await renderForestScene(db, page, elementId);
await renderForestScene(db, newPage, elementId);
showScreen("forest");
},
);