Skip to content

Add browser storage persistence for GramFrame annotations#164

Merged
IanMayo merged 6 commits intomainfrom
claude/implement-browser-storage-5OnwT
Mar 27, 2026
Merged

Add browser storage persistence for GramFrame annotations#164
IanMayo merged 6 commits intomainfrom
claude/implement-browser-storage-5OnwT

Conversation

@IanMayo
Copy link
Copy Markdown
Contributor

@IanMayo IanMayo commented Mar 27, 2026

Summary

Implements automatic persistence of user annotations (analysis markers, harmonic sets, doppler curves) in browser storage, with context-aware storage selection (localStorage for trainers, sessionStorage for students) and a "Clear gram" button for trainer pages.

Key Changes

  • Storage Module (src/core/storage.js): New adapter module providing context detection, key generation, save/load/clear operations, schema versioning (v1), and graceful degradation with try/catch wrapping all Web Storage calls

    • detectUserContext(): Identifies trainer pages by presence of anchor with exact text "ANALYSIS"
    • getStorage(): Returns appropriate Storage object (localStorage/sessionStorage) with availability probing
    • saveAnnotations(): Persists annotation state only when data exists; removes empty entries
    • loadAnnotations(): Validates schema version and discards incompatible data
    • clearAnnotations(): Removes stored data for current page
  • GramFrame Integration (src/main.js):

    • Detects user context and calculates storage instance index during construction
    • Restores saved annotations before first state notification
    • Registers state listener that saves annotations on relevant state changes (with deduplication)
    • Adds "Clear gram" button to trainer pages only
    • _clearGram(): Resets all annotation state and storage, re-renders UI
  • Type Definitions (src/types.js): Added JSDoc typedefs for StoredAnnotations, StoredAnalysisData, StoredMarker, StoredHarmonicsData, StoredHarmonicSet, and StoredDopplerData

  • Styling (src/gramframe.css): Added .gram-frame-clear-btn with gradient background, hover/active states, and responsive styling

  • Test Fixtures: Created trainer-page.html and student-page.html for integration testing

  • Test Suite (tests/storage.spec.js): Comprehensive Playwright tests covering:

    • US1: Trainer annotations persist across page reloads (analysis markers, harmonic sets, doppler curves)
    • US2: Student annotations persist within session only
    • US3: Clear gram button removes annotations from display and storage
    • Edge cases: graceful degradation when storage unavailable, schema version validation, lazy storage initialization
  • Test Helpers (tests/helpers/gram-frame-page.js): Added storage utility methods (clearStorage(), getStorageEntry(), setStorageEntry(), getStorageKeys())

Notable Implementation Details

  • Multi-instance support: Storage keys include instance index to support multiple GramFrame instances on the same page
  • Lazy initialization: Storage entries only created when first annotation is added; empty state removes entries
  • Schema versioning: Unrecognized schema versions are discarded with console warning
  • Deduplication: State listener compares serialized annotation snapshots to avoid redundant writes
  • Silent restoration: Annotations restored without prompts or dialogs
  • Graceful degradation: All storage operations wrapped in try/catch; component continues functioning if storage unavailable

https://claude.ai/code/session_01Gb6npXwykVzbvHBZUgmYty

Add automatic save/restore of annotations (analysis markers, harmonic sets,
doppler curves) using the Web Storage API. Trainer pages (identified by an
"ANALYSIS" link) use localStorage for permanent persistence; student pages
use sessionStorage for session-scoped persistence.

- New storage adapter module (src/core/storage.js) with context detection,
  key generation, save/load/clear, schema versioning, and graceful degradation
- JSDoc types for StoredAnnotations and related entities
- GramFrame constructor integration: restore on init, save on state change
- "Clear gram" button on trainer pages to reset all annotations
- Comprehensive Playwright tests covering all 3 user stories plus edge cases
- All 101 tests pass, typecheck clean, build clean

https://claude.ai/code/session_01Gb6npXwykVzbvHBZUgmYty
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 27, 2026

Deploy Preview for gramframe ready!

Name Link
🔨 Latest commit cc31846
🔍 Latest deploy log https://app.netlify.com/projects/gramframe/deploys/69c66bddb906a50007d9eac8
😎 Deploy Preview https://deploy-preview-164--gramframe.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 27, 2026

PR Preview

Preview deployment is ready! View Preview

Last updated: 2026-03-27T11:37:22.951Z

claude added 4 commits March 27, 2026 11:20
- New debug-trainer.html with "ANALYSIS" link (triggers localStorage persistence)
- Updated debug.html with badge and link to trainer page for easy navigation
- Added trainer page to Vite build inputs

https://claude.ai/code/session_01Gb6npXwykVzbvHBZUgmYty
Root index.html now serves as a demo hub linking to the student
(sessionStorage) and trainer (localStorage) pages, so the preview
URL works without specifying a page name.

https://claude.ai/code/session_01Gb6npXwykVzbvHBZUgmYty
The PR preview now serves a landing page with links to:
- Student page (sessionStorage, no ANALYSIS link)
- Trainer page (localStorage, with ANALYSIS link + Clear gram)

Also adds debug-trainer.html to the main site deploy.

https://claude.ai/code/session_01Gb6npXwykVzbvHBZUgmYty
The main site now builds the standalone bundle and serves
student/trainer demo pages at /demo/ alongside the existing
dev-oriented pages.

https://claude.ai/code/session_01Gb6npXwykVzbvHBZUgmYty
@IanMayo IanMayo merged commit a453d0d into main Mar 27, 2026
7 checks passed
@IanMayo IanMayo deleted the claude/implement-browser-storage-5OnwT branch March 27, 2026 11:40
github-actions bot added a commit that referenced this pull request Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants