about summary refs log tree commit diff
path: root/web
diff options
context:
space:
mode:
authorsternenseemann <git@lukasepple.de>2017-09-06 16:52:00 +0200
committersternenseemann <git@lukasepple.de>2017-09-06 16:52:00 +0200
commit346e5dcb77b213403c4a7911f3b97b3eb864ae7a (patch)
treec5218c4b6c41dd49f1a433ebc6dd2200d92861f9 /web
parent3ddac7b305e6024f25a1b15ea301c7f31f3732f2 (diff)
Auto save to localStorage
Diffstat (limited to 'web')
-rw-r--r--web/source/main.js21
1 files changed, 19 insertions, 2 deletions
diff --git a/web/source/main.js b/web/source/main.js
index 78e4755..a2c7a0b 100644
--- a/web/source/main.js
+++ b/web/source/main.js
@@ -272,6 +272,11 @@ function handleImport() {
     }
 }
 
+function saveGraphToLocalStorage() {
+    const json = JSON.stringify(collectGraphData(nodeData, edgeData));
+    localStorage.setItem("score", json)
+}
+
 function showStartingNode() {
     if(typeof starting_node_id === 'string') {
         network.selectNodes([starting_node_id], false);
@@ -333,7 +338,7 @@ function genInterpretation(format) {
     }
 }
 
-function main() {
+function init() {
     var container = document.getElementById('network');
 
     var options = {
@@ -396,6 +401,16 @@ function main() {
 
     network = new vis.Network(container, {}, options);
 
+    try {
+        const score = localStorage.getItem('score');
+        if(score !== null) {
+            importGraphData(JSON.parse(score));
+        }
+    } catch(e) {
+        localStorage.removeItem('score');
+    }
+
+
     const pitch_selector = valid_pitches.map((p, i) =>
         `<option value="${p}">${display_pitches[i]}</option>`)
         .reduce((acc, v) =>
@@ -413,6 +428,8 @@ function main() {
 
     document.getElementById('show-starting-node').onclick = showStartingNode;
     document.getElementById('set-starting-node').onclick = setStartingNode;
+
+    window.setInterval(saveGraphToLocalStorage, 10000);
 }
 
-document.addEventListener('DOMContentLoaded', () => main());
+document.addEventListener('DOMContentLoaded', () => init());