Skip to content

Latest commit

 

History

History
52 lines (32 loc) · 2.65 KB

File metadata and controls

52 lines (32 loc) · 2.65 KB

Persistence

The app persists everything needed to resume work across page reloads in localStorage. Nothing is ever sent off-device.

Storage keys

Key Written by Contents
auditClientViewer_session_v1 saveSession() { fileName, allData, completedData, savedAt } — the parsed rows plus metadata.
theme theme toggle handler 'dark' or 'light'.

Why not the file path?

The browser's File API deliberately does not expose absolute paths (only the File object and its bytes). Storing the file path is impossible without a desktop wrapper (Electron etc.). Saving the parsed rows achieves the same user-visible outcome — a refresh restores the session — without re-prompting for the file.

Save lifecycle

saveSession() serializes {fileName, allData, completedData, savedAt} to JSON and writes the storage key. It is called after every mutation that changes the session state:

  • parseCSV() — after a successful upload.
  • markRecordComplete() — after moving a row to Completed.
  • restoreRow() — after moving a row back to Active.

If localStorage throws (quota exceeded, storage disabled), the error is logged to the console and the app keeps working in-memory — progress is just not persisted for that session.

Restore lifecycle

On DOMContentLoaded, restoreFromSession() runs:

  1. Reads the storage key and JSON.parses it.
  2. If present and valid, repopulates allData, completedData, currentFileName, filteredData, and currentWorkbook.
  3. Calls showListView() + showContent() so the user lands on the Active tab.
  4. Shows a toast: Restored "<filename>" (N active, M completed).

If the key is missing or corrupt the app falls back to the normal upload-first flow.

Reset lifecycle

resetToUploadState() (fired by the 🔄 New Upload button after a confirm prompt):

  1. localStorage.removeItem('auditClientViewer_session_v1').
  2. Null out every piece of state.
  3. Hide #contentArea, show #uploadZone.
  4. Show a toast: Session cleared. Upload a new CSV file to begin.

Versioning

The storage key is suffixed with _v1. If the on-disk shape needs to change, bump to _v2 and the old session will simply be ignored (user re-uploads). This avoids the need for a migration layer inside a small tool.

Size notes

localStorage is typically 5–10 MB per origin. The session stores the parsed rows, not the raw CSV — JSON serialization is usually 1.5–2× the CSV size. A 10 MB CSV can therefore be near the edge; large sessions may fail to save. If that happens, the console will log a warning and completed state will only persist for the current tab lifetime.