Skip to content

Commit

Permalink
Backup to localStorage when not saving to account (fixes hackclub#977)
Browse files Browse the repository at this point in the history
  • Loading branch information
kognise committed Mar 21, 2023
1 parent 22abef7 commit 82f58e4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/components/big-interactive-pages/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export default function Editor({ persistenceState, cookies }: EditorProps) {
else if (persistenceState.value.kind === 'SHARED')
initialCode = persistenceState.value.code
else if (persistenceState.value.kind === 'IN_MEMORY')
initialCode = defaultExampleCode
initialCode = localStorage.getItem('sprigMemory') ?? defaultExampleCode

// Firefox has weird tab restoring logic. When you, for example, Ctrl-Shift-T, it opens
// a kinda broken cached version of the page. And for some reason this reverts the CM
Expand Down Expand Up @@ -212,6 +212,10 @@ export default function Editor({ persistenceState, cookies }: EditorProps) {
}
saveGame(persistenceState, codeMirror.value!.state.doc.toString())
}

if (persistenceState.value.kind === 'IN_MEMORY') {
localStorage.setItem('sprigMemory', codeMirror.value!.state.doc.toString())
}
}}
/>
{errorLog.value.length > 0 && (
Expand Down

0 comments on commit 82f58e4

Please sign in to comment.