diff --git a/.env.example b/.env.example index bd75d8f..72c017c 100644 --- a/.env.example +++ b/.env.example @@ -8,4 +8,5 @@ ITEMS_TIMEOUT=600 ITEMS_STALE=600 PUBLIC_CATALOG_HREF=/ PUBLIC_DEVPORTAL_HREF=/ -PUBLIC_PUZZLE_HREF=/ \ No newline at end of file +PUBLIC_PUZZLE_HREF=/ +PUBLIC_CACHE_DEBOUNCE_MS=500 \ No newline at end of file diff --git a/helm/templates/configmap.yaml b/helm/templates/configmap.yaml index 2c8ce02..34535de 100644 --- a/helm/templates/configmap.yaml +++ b/helm/templates/configmap.yaml @@ -17,6 +17,7 @@ data: PUBLIC_CATALOG_HREF: 'http://catalog' PUBLIC_DEVPORTAL_HREF: 'http://developer-portal' PUBLIC_PUZZLE_HREF: '' + PUBLIC_CACHE_DEBOUNCE_MS: {{ .Values.cache.debounceMs | quote }} npm_config_cache: /tmp/ # default.conf: {{ tpl (.Files.Get "config/default.conf") . | quote }} {{- end }} diff --git a/helm/values.yaml b/helm/values.yaml index c10943b..7e0e30d 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -26,6 +26,9 @@ env: port: 8080 targetPort: 8080 +cache: + debounceMs: 500 + resources: enabled: true value: diff --git a/src/lib/cache/demoCache.ts b/src/lib/cache/demoCache.ts new file mode 100644 index 0000000..3ecd8e8 --- /dev/null +++ b/src/lib/cache/demoCache.ts @@ -0,0 +1,41 @@ +import type { File } from '$lib/types'; + +const NAMESPACE = 'demo-cache:v1'; + +function available(): boolean { + return typeof localStorage !== 'undefined'; +} + +export function cacheKey(client: string, name: string): string { + return `${NAMESPACE}:${client}/${name}`; +} + +export function loadCache(key: string): File[] | null { + if (!available()) return null; + const raw = localStorage.getItem(key); + if (raw === null) return null; + try { + const files = JSON.parse(raw) as File[]; + return Array.isArray(files) ? files : null; + } catch { + return null; + } +} + +export function saveCache(key: string, files: File[]): void { + if (!available()) return; + try { + localStorage.setItem(key, JSON.stringify(files)); + } catch { + // Ignore quota / private-mode write failures — caching is best-effort. + } +} + +export function clearCache(key: string): void { + if (!available()) return; + try { + localStorage.removeItem(key); + } catch { + // Ignore — clearing is best-effort. + } +} diff --git a/src/lib/components/flems.svelte b/src/lib/components/flems.svelte index 4a68d3c..92f9d7b 100644 --- a/src/lib/components/flems.svelte +++ b/src/lib/components/flems.svelte @@ -3,6 +3,7 @@ import type { File, Link } from '$lib/types'; export let files: File[]; export let links: Link[]; + export let onChange: ((files: File[]) => void) | undefined = undefined; const flemsBaseConfig = { shareButton: false, @@ -14,6 +15,15 @@ let flemsInstance: any; + function wireOnChange() { + if (!flemsInstance || !onChange) return; + // Flems' `onchange` is a registrar you CALL to install a handler, + // not a settable property (`onchange: fn => actions.onchange = fn`). + flemsInstance.onchange((state: { files: File[] }) => + onChange?.(state.files.map((f) => ({ name: f.name, content: f.content }))) + ); + } + $: if (flemsInstance) { flemsInstance.set({ ...flemsBaseConfig, @@ -29,6 +39,7 @@ files, links: links.map((link) => ({ ...link, url: window.location.origin + link.url })) }); + wireOnChange(); }); diff --git a/src/routes/demo/[client]/[name]/+page.svelte b/src/routes/demo/[client]/[name]/+page.svelte index e7a9d98..9a7f16b 100644 --- a/src/routes/demo/[client]/[name]/+page.svelte +++ b/src/routes/demo/[client]/[name]/+page.svelte @@ -1,31 +1,102 @@ -