Rename gameId --> id in Game.vue
[vchess.git] / client / src / utils / gameStorage.js
index 0284763..6b44632 100644 (file)
@@ -1,6 +1,6 @@
 // Game object: {
 //   // Static informations:
-//   gameId: string
+//   id: string
 //   vname: string,
 //   fenStart: string,
 //   players: array of sid+id+name,
@@ -39,7 +39,7 @@ function dbOperation(callback)
       alert("Error while loading database: " + event.target.errorCode);
     };
     // Create objectStore for vchess->games
-    let objectStore = db.createObjectStore("games", { keyPath: "gameId" });
+    let objectStore = db.createObjectStore("games", { keyPath: "id" });
     objectStore.createIndex("score", "score"); //to search by game result
   }
 }
@@ -79,8 +79,7 @@ export const GameStorage =
           gid: gameId,
           newObj:
           {
-            // TODO: I think stringify isn't requuired here (see ajax() )
-            move: JSON.stringify(obj.move), //may be undefined...
+            move: obj.move, //may be undefined...
             fen: obj.fen,
             score: obj.score,
           }
@@ -134,7 +133,11 @@ export const GameStorage =
     if (Number.isInteger(gameId) || !isNaN(parseInt(gameId)))
     {
       ajax("/games", "GET", {gid:gameId}, res => {
-        callback(res.game);
+        let game = res.game;
+        game.moves.forEach(m => {
+          m.squares = JSON.parse(m.squares);
+        });
+        callback(game);
       });
     }
     else //local game