Skip to content

Commit 4a7bbda

Browse files
committed
✨ Add effect persistence with localStorage
Store and restore the last selected effect across browser sessions - Save selected effect ID to localStorage when switching effects - Check localStorage for saved effect during initialization - Maintain URL parameter priority over saved preference - Fall back to first effect if neither URL nor saved effect exists This allows users to return to their previously selected effect when reopening the development environment.
1 parent 5452e8c commit 4a7bbda

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/dev/engine/preact-engine.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,11 @@ export class PreactDevEngine {
129129
throw new Error('Canvas element with ID "exCanvas" not found')
130130
}
131131

132-
// Get the effect ID from URL or use the first effect
132+
// Get the effect ID from URL, localStorage, or use the first effect
133133
const urlParams = new URLSearchParams(window.location.search)
134-
const effectId = urlParams.get('effect') || effects[0].id
134+
const urlEffect = urlParams.get('effect')
135+
const savedEffect = localStorage.getItem('lastSelectedEffect')
136+
const effectId = urlEffect || savedEffect || effects[0].id
135137

136138
// Set basic names for effects to ensure they're visible in UI
137139
for (const effect of effects as AppEffect[]) {
@@ -229,6 +231,9 @@ export class PreactDevEngine {
229231
return
230232
}
231233

234+
// Save the selected effect to localStorage
235+
localStorage.setItem('lastSelectedEffect', effectId)
236+
232237
// Update current effect reference
233238
this.currentEffect = effect
234239

0 commit comments

Comments
 (0)