X-Git-Url: https://git.auder.net/?a=blobdiff_plain;ds=sidebyside;f=client%2Fsrc%2Futils%2FgameStorage.js;h=3bd993470576a3186a2c0bc86770400a13d26572;hb=42c15a75118bfeb3251cea1f65acb01fcd023f01;hp=75696a09630b2b9eabfe7285fe15781f438583ce;hpb=f6f2bef10910ddb3430a40f4ab393b225250234a;p=vchess.git diff --git a/client/src/utils/gameStorage.js b/client/src/utils/gameStorage.js index 75696a09..3bd99347 100644 --- a/client/src/utils/gameStorage.js +++ b/client/src/utils/gameStorage.js @@ -37,7 +37,8 @@ function dbOperation(callback) alert("Error while loading database: " + event.target.errorCode); }; // Create objectStore for vchess->games - db.createObjectStore("games", { keyPath: "gameId" }); + let objectStore = db.createObjectStore("games", { keyPath: "gameId" }); + objectStore.createIndex("score", "score"); //to search by game result } } @@ -115,6 +116,16 @@ export const GameStorage = }); }, + getCurrent: function(callback) + { + dbOperation((db) => { + let objectStore = db.transaction('games').objectStore('games'); + objectStore.get("*").onsuccess = function(event) { + callback(event.target.result); + }; + }); + }, + // Delete a game in indexedDB remove: function(gameId, callback) {