From 59af2e0a29e5ed8fcce4cf034fe449eb5cb2278c Mon Sep 17 00:00:00 2001 From: Jesse McDonald Date: Sun, 21 Jun 2020 23:04:33 -0500 Subject: [PATCH] fix for missing data when showing tiles for old games --- js/pacosako_ui.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/js/pacosako_ui.js b/js/pacosako_ui.js index 357b22a..c50a7b8 100644 --- a/js/pacosako_ui.js +++ b/js/pacosako_ui.js @@ -780,6 +780,8 @@ $(function (){ $('#cb_dark_name').val(String(d.darkName || '')); $('#cb_board').data('modified', data.modified); + + updateSelectGameMeta(data, newId); } }); }); @@ -1305,11 +1307,6 @@ $(function (){ } function updateSelectGameMeta(data, gameId) { - data = Object.assign({}, data, { - gameId: gameId || data.gameId, - timestamp: data.timestamp || +new Date(), - }); - if (typeof gameId !== 'string' || !gameId.match(/^[0-9a-f]{16}$/)) { debug('invalid game ID', gameId); return; @@ -1319,8 +1316,8 @@ $(function (){ const oldTile = $('#game_tile_' + gameId).first(); if (!data.lightName && !data.darkName && !data.moves && gameId !== currentGameId) { - oldTile.removeAttr('id'); if (oldTile.length >= 1) { + oldTile.removeAttr('id'); oldTile.hide({ effect: "clip", direction: "horizontal", @@ -1332,6 +1329,13 @@ $(function (){ return; } + if (oldTile.length && data.modified && oldTile.data('gameMeta').modified >= data.modified) { + return; + } + + data = Object.assign({ gameId, timestamp: +new Date(), modified: 0 }, data); + delete data.board; + const tile = oldTile.length ? oldTile : $(`
`).hide(); tile.attr('id', 'game_tile_' + gameId).data('gameMeta', data).empty();