allow page to expand as needed

This commit is contained in:
Elijah Steres 2020-12-30 03:50:29 -05:00
parent 88ae439273
commit 26611780b9

View File

@ -1,8 +1,7 @@
$(document).ready(function (){ $(document).ready(function (){
var socket = io.connect(); var socket = io.connect();
var gameslist = []; var gameslist = [];
var maxslot = 3; var maxSlot = 3;
var totalslots = 15;
var grid = document.getElementById("container"); var grid = document.getElementById("container");
@ -14,17 +13,23 @@ $(document).ready(function (){
for (const timestamp in json) { for (const timestamp in json) {
if (!gameslist.includes(timestamp)) { //adds game to list if not there already if (!gameslist.includes(timestamp)) { //adds game to list if not there already
gameslist.push(timestamp) gameslist.push(timestamp)
var gridBoxes = grid.children; for (var slotnum = 3; true; slotnum++) { //this is really a while loop but don't tell anyone
for (var slotnum = 3; slotnum <= Math.min(maxslot, totalslots-1); slotnum++) { if (slotnum >= grid.children.length) {
if (gridBoxes[slotnum].className == "emptyslot") { for (var i = 0; i < 3; i ++) {
newBox = document.createElement("DIV");
newBox.className = "emptyslot";
grid.appendChild(newBox);
}
}
if (grid.children[slotnum].className == "emptyslot") {
insertGame(slotnum, json[timestamp], timestamp); insertGame(slotnum, json[timestamp], timestamp);
maxslot += 1; maxSlot = Math.max(maxSlot, slotnum);
break; break;
}; };
}; };
}; };
for (var slotnum = 3; slotnum <= Math.min(maxslot, totalslots-1); slotnum++) { for (var slotnum = 3; slotnum <= maxSlot; slotnum++) {
if (grid.children[slotnum].timestamp == timestamp) { if (grid.children[slotnum].timestamp == timestamp) {
updateGame(grid.children[slotnum], json[timestamp]); updateGame(grid.children[slotnum], json[timestamp]);
}; };
@ -34,11 +39,9 @@ $(document).ready(function (){
const insertGame = (gridboxnum, gamestate, timestamp) => { const insertGame = (gridboxnum, gamestate, timestamp) => {
var thisBox = grid.children[gridboxnum]; var thisBox = grid.children[gridboxnum];
thisBox.className = "game";
thisBox.timestamp = timestamp;
fetch("/static/game.html").then(x=>x.text()).then(gamehtml => { fetch("/static/game.html").then(x=>x.text()).then(gamehtml => {
console.log(gamehtml)
console.log(thisBox)
thisBox.className = "game";
thisBox.timestamp = timestamp;
thisBox.innerHTML = gamehtml; thisBox.innerHTML = gamehtml;
updateGame(thisBox, gamestate); updateGame(thisBox, gamestate);
}); });