fix some quirks with the game select menu

This commit is contained in:
Jesse D. McDonald 2020-04-04 06:03:13 -05:00
parent 7ebea1d1fc
commit 1a7728e53d
1 changed files with 51 additions and 24 deletions

View File

@ -546,6 +546,8 @@ $(function (){
} else {
$('#cb_select_game')[0].selectedIndex = -1;
}
refreshSelectOptions();
}
function disableNotify(){
@ -797,7 +799,6 @@ $(function (){
let optIndex = $('#cb_select_game')[0].selectedIndex;
if (optIndex === 0) {
switchGameId(randomId());
putState();
} else if (optIndex >= 1) {
let opt = $('#cb_select_game option')[optIndex];
if (opt) {
@ -822,12 +823,16 @@ $(function (){
age_str = ' (' + Math.floor((now - then) / (60*1000)) + 'm)';
} else if ((now - then) < 24*60*60*1000) {
age_str = ' (' + Math.floor((now - then) / (60*60*1000)) + 'h)';
} else if ((now - then) < 14*24*60*60*1000) {
age_str = ' (' + Math.floor((now - then) / (24*60*60*1000)) + 'd)';
} else if (opt.data('gameId') !== $('#cb_board').data('gameId')) {
} else {
if ((now - then) >= 14*24*60*60*1000) {
/* prune entries with no activity in 14 days, but leave the current game */
if (opt.data('gameId') !== $('#cb_board').data('gameId')) {
opt.remove();
return;
}
}
age_str = ' (' + Math.floor((now - then) / (24*60*60*1000)) + 'd)';
}
const newText = opt.data('title') + age_str;
if (opt.text() !== newText) {
@ -835,7 +840,7 @@ $(function (){
}
}
window.setTimeout(function(){
const refreshSelectOptions = (function(){
function updateSelectMeta(d, key) {
d = d || {};
debug('got meta for key ' + key, d);
@ -889,8 +894,16 @@ $(function (){
}
}
let cancellers = {};
let cancelAll = gun.get(PacoSakoUUID + '/meta').onWithCancel(function(meta) {
let cancelAll = function(){};
return function() {
cancelAll();
$('#cb_select_game .cb-game-option').remove();
updateSelectMeta(null, $('#cb_board').data('gameId'));
const cancellers = {};
let cancelMeta = gun.get(PacoSakoUUID + '/meta').onWithCancel(function(meta) {
for (const gameId in meta) { /* use of 'in' here is deliberate */
/* 'gameId' may include extra GUN fields like '_' */
if (gameId.match(/^[0-9a-f]{16}$/)) {
@ -908,7 +921,22 @@ $(function (){
}
}
}, { change: true });
}, 1);
cancelAll = function() {
cancelMeta();
cancelMeta = function(){};
for (const gameId in cancellers) {
cancellers[gameId]();
delete cancellers[gameId];
}
cancelAll = function(){};
};
return cancelAll;
};
})();
refreshSelectOptions();
window.setInterval(function(){
$('#cb_select_game').first().children('.cb-game-option').each(function(idx,opt){
@ -956,7 +984,6 @@ $(function (){
switchGameId(foundId[1]);
} else {
switchGameId(randomId());
putState();
}
/* Low-level commands to be run from the JS console */