X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Futils%2FgameStorage.js;h=3e3b68403d4de92eb0da99a36875f6545b33bcbb;hb=937c24ab2871b31a7e531226603fc75acab7edb8;hp=42f438843381ee29be06bf3530662e877ecd39f5;hpb=3d65195b5713c9e6f58b250069e685e4dca448c2;p=vchess.git diff --git a/client/src/utils/gameStorage.js b/client/src/utils/gameStorage.js index 42f43884..3e3b6840 100644 --- a/client/src/utils/gameStorage.js +++ b/client/src/utils/gameStorage.js @@ -51,6 +51,7 @@ function dbOperation(callback) { } export const GameStorage = { + // Optional callback to get error status add: function(game, callback) { dbOperation((err, db) => { @@ -73,14 +74,13 @@ export const GameStorage = { // obj: chat, move, fen, clocks, score[Msg], initime, ... update: function(gameId, obj) { - // live dbOperation((err, db) => { let objectStore = db .transaction("games", "readwrite") .objectStore("games"); objectStore.get(gameId).onsuccess = function(event) { // Ignoring error silently: shouldn't happen now. TODO? - if (event.target.result) { + if (!!event.target.result) { let game = event.target.result; // Hidden tabs are delayed, to prevent multi-updates: if (obj.moveIdx < game.moves.length) return; @@ -89,7 +89,8 @@ export const GameStorage = { else if (k == "chat") game.chats.push(obj[k]); else if (k == "chatRead") game.chatRead = Date.now(); else if (k == "delchat") game.chats = []; - else if (k == "playerName") game.players[obj.idx] = obj.name; + else if (k == "playerName") + game.players[obj[k].idx].name = obj[k].name; else game[k] = obj[k]; }); objectStore.put(game); //save updated data @@ -183,4 +184,5 @@ export const GameStorage = { } }); } + };