feat(viewer): persist hide/show instructions state in chrome.storage.local
CI / test (pull_request) Successful in 6m29s
CI / test (pull_request) Successful in 6m29s
Read the instructions panel's visibility on mount from chrome.storage.local['goon_instructions_visible'] (absent => shown, the first-time default) and persist the new value on every user toggle, so a 'hide instructions' choice survives popup reloads and service-worker termination and is respected across the app via the shared storage key. Adds unit tests: stored-hidden honored on mount, persistence on both toggle directions, and first-time (absent key) defaulting to shown.
This commit is contained in:
1 parent
fbc836d9c4
commit
42c1ad75c8
2 files changed
+95
-12
No files matched your search
+20
-2
@@ -6,6 +6,11 @@
|
||||
|
||||
const STORAGE_KEY = 'goon_videos';
|
||||
const TAGGED_KEY = 'goon_tagged';
|
||||
// Durable "hide instructions" toggle. Absent key === SHOWN (true), matching the
|
||||
// first-time "expanded on mount" behavior. chrome.storage.local is extension-wide,
|
||||
// so the viewer window and every popup instance read/write the same value — the
|
||||
// preference is respected application-wide and survives reloads / SW termination.
|
||||
const INSTRUCTIONS_VISIBLE_KEY = 'goon_instructions_visible';
|
||||
|
||||
// Set to true to enable verbose console output in the popup.
|
||||
const DEBUG = true; // TEMP: enabled for debugging — revert to false when done
|
||||
@@ -48,9 +53,22 @@ function setInstructionsExpanded(expanded) {
|
||||
}
|
||||
|
||||
if (instructionsToggle && instructionsBody) {
|
||||
setInstructionsExpanded(true);
|
||||
// On mount, read the stored visibility. An absent key means SHOWN (true), so a
|
||||
// first-time user still sees the steps. The viewer window reads the same
|
||||
// extension-wide key, so the choice is respected across the whole app.
|
||||
chrome.storage.local.get(INSTRUCTIONS_VISIBLE_KEY).then(stored => {
|
||||
const visible = stored[INSTRUCTIONS_VISIBLE_KEY];
|
||||
setInstructionsExpanded(visible === undefined ? true : visible);
|
||||
}).catch(() => {
|
||||
// Any read failure falls back to shown.
|
||||
setInstructionsExpanded(true);
|
||||
});
|
||||
// On every user toggle, apply in-DOM and persist. Both directions write, so
|
||||
// the state survives reloads and SW termination until the user flips it again.
|
||||
instructionsToggle.addEventListener('click', () => {
|
||||
setInstructionsExpanded(instructionsBody.hidden);
|
||||
const next = instructionsBody.hidden;
|
||||
setInstructionsExpanded(next);
|
||||
chrome.storage.local.set({ [INSTRUCTIONS_VISIBLE_KEY]: next });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user