Added local save feature

pull/6251/head
Tobeqz 5 years ago
parent a39fc8de72
commit 3ce518d1d0

@ -86,6 +86,8 @@
if (saving) return; if (saving) return;
if (!canSave) { if (!canSave) {
// Save to local storage
localStorage.setItem("repl_content", JSON.stringify(repl.toJSON()))
fork(true); fork(true);
return; return;
} }

@ -47,6 +47,17 @@
return; return;
} }
const local_repl_content = localStorage.getItem("repl_content")
// Check if user is not logged in and has local data
if (id == 'hello-world' && local_repl_content && !$session.user) {
setTimeout(() => {
repl.set(JSON.parse(local_repl_content))
}, 300) // Wait for repl var (it's undefined when this function gets called)
// TODO: Fix this possible race condition
return
}
// TODO handle `relaxed` logic // TODO handle `relaxed` logic
fetch(`repl/${id}.json`).then(r => { fetch(`repl/${id}.json`).then(r => {
if (r.ok) { if (r.ok) {

Loading…
Cancel
Save