X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Futils%2FcompgameStorage.js;h=655fd6bf8c69838d14c3032fe0d948066a9d0f88;hb=5f918a278904266a2a66a3c8e2a3655f37c2d2a7;hp=a5c58af1de698e2e51ae7c08fb168d2250597182;hpb=7617c334b43d2f5fff40cbec72127ed30e5867c0;p=vchess.git diff --git a/client/src/utils/compgameStorage.js b/client/src/utils/compgameStorage.js index a5c58af1..655fd6bf 100644 --- a/client/src/utils/compgameStorage.js +++ b/client/src/utils/compgameStorage.js @@ -15,7 +15,8 @@ function dbOperation(callback) { let DBOpenRequest = window.indexedDB.open("vchess_comp", 4); DBOpenRequest.onerror = function(event) { - alert(store.state.tr["Database error: stop private browsing, or update your browser"]); + alert(store.state.tr[ + "Database error: stop private browsing, or update your browser"]); callback("error", null); }; @@ -27,13 +28,17 @@ function dbOperation(callback) { DBOpenRequest.onupgradeneeded = function(event) { let db = event.target.result; - db.createObjectStore("compgames", { keyPath: "vname" }); + let upgradeTransaction = event.target.transaction; + if (!db.objectStoreNames.contains("compgames")) + db.createObjectStore("compgames", { keyPath: "vname" }); + else + upgradeTransaction.objectStore("compgames"); }; } export const CompgameStorage = { add: function(game) { - dbOperation((err,db) => { + dbOperation((err, db) => { if (err) return; let objectStore = db .transaction("compgames", "readwrite") @@ -44,7 +49,7 @@ export const CompgameStorage = { // obj: move and/or fen update: function(gameId, obj) { - dbOperation((err,db) => { + dbOperation((err, db) => { let objectStore = db .transaction("compgames", "readwrite") .objectStore("compgames"); @@ -65,7 +70,7 @@ export const CompgameStorage = { // Retrieve any game from its identifier (variant name) // NOTE: need callback because result is obtained asynchronously get: function(gameId, callback) { - dbOperation((err,db) => { + dbOperation((err, db) => { let objectStore = db .transaction("compgames", "readonly") .objectStore("compgames"); @@ -77,7 +82,7 @@ export const CompgameStorage = { // Delete a game in indexedDB remove: function(gameId) { - dbOperation((err,db) => { + dbOperation((err, db) => { if (!err) { db.transaction("compgames", "readwrite") .objectStore("compgames")