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