Skip to content

Commit

Permalink
url-based hard state reset
Browse files Browse the repository at this point in the history
  • Loading branch information
bobnik committed Sep 24, 2023
1 parent 5ff2fce commit 1b03050
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
- get rectangular preview image from Jeff
- bug: wiper, 90 degrees with noise effect; change wiper size from 4 to 40, hangs browser
- bug: edge-case optimization of pattern with inverted mask is adding a center point within the mask; workaround is to enable "minimize perimeter moves", but this isn't user-friendly obviously
- add URL parameter to reset pattern; needed for cases where page is hanging

- review/test
- all shapes/effects
Expand Down
28 changes: 20 additions & 8 deletions src/features/app/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,23 @@ let persistedState =
? loadState() || undefined
: undefined

// support a URL-based reset as a last resort
const params = new URLSearchParams(window.location.search)
const reset = params.get("reset")

// reset some values
if (persistedState) {
const importer = new SandifyImporter()
try {
// double JSON parsing ensures it's valid JSON before we try to import it
importer.import(JSON.stringify(persistedState))
persistedState.fonts.loaded = false
} catch (err) {
persistedState = undefined
if (reset === "all") {
persistedState = undefined
} else {
if (persistedState) {
const importer = new SandifyImporter()
try {
// double JSON parsing ensures it's valid JSON before we try to import it
importer.import(JSON.stringify(persistedState))
persistedState.fonts.loaded = false
} catch (err) {
persistedState = undefined
}
}
}

Expand All @@ -36,6 +44,10 @@ if (persistState) {
if (state.fonts.loaded) {
saveState(state)
resetLogCounts()

if (reset) {
window.location.href = window.location.pathname
}
}
})
}
Expand Down

0 comments on commit 1b03050

Please sign in to comment.