From 09b90cf445c20ba2c71280d5a581ac72e3720c64 Mon Sep 17 00:00:00 2001 From: Elijah Steres Date: Thu, 7 Jan 2021 16:22:39 -0500 Subject: [PATCH] add grid filling --- main_controller.py | 1 - simmadome/src/App.css | 10 ++++++--- simmadome/src/App.tsx | 50 +++++++++++++++++++++++++++++++++++-------- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/main_controller.py b/main_controller.py index 9692ce0..707c9f7 100644 --- a/main_controller.py +++ b/main_controller.py @@ -25,7 +25,6 @@ game_states = [] @socketio.on("recieved") def handle_new_conn(data): - print("new connection") socketio.emit("states_update", game_states, room=request.sid) def update_loop(): diff --git a/simmadome/src/App.css b/simmadome/src/App.css index d8d9e02..d99b790 100644 --- a/simmadome/src/App.css +++ b/simmadome/src/App.css @@ -5,10 +5,16 @@ grid-auto-flow: row; } +.slot_container { + display: flex; + justify-content: space-around; +} + .emptyslot, .game { min-height: 18.75rem; - justify-self: center; max-width: 44rem; + min-width: 32rem; + width: 100%; } #filters { @@ -58,8 +64,6 @@ .emptyslot { border: 2px dashed white; border-radius: 15px; - align-self: stretch; - justify-self: stretch; text-align: center; color: white; } diff --git a/simmadome/src/App.tsx b/simmadome/src/App.tsx index c7e165e..58dc594 100644 --- a/simmadome/src/App.tsx +++ b/simmadome/src/App.tsx @@ -1,4 +1,4 @@ -import React, {useState, useRef, useEffect} from 'react'; +import React, {useState, useRef, useEffect, useLayoutEffect} from 'react'; import io from 'socket.io-client'; import './App.css'; import Game from './Game'; @@ -56,7 +56,7 @@ const useListener = (onUpdate: (update: [string, GameState][]) => void, url: str let socket = url ? io(url) : io(); socket.on('connect', () => socket.emit('recieved', {})); socket.on('states_update', onUpdate); - return () => {socket.disconnect()} + return () => {socket.disconnect()}; }, [url]) } @@ -111,13 +111,45 @@ function Filters (props: {filterList: string[], selectedFilter: string, onSelect } function Grid(props: { gameList: GameList }) { - return ( -
- {props.gameList.map((game) => {if (game) { - return - } else { - return
- }})} + let self: React.RefObject = useRef(null); + let [numcols, setNumcols] = useState(3); + let newList = [...props.gameList]; + + while (newList.length === 0 || newList.length % numcols !== 0) { + newList.push(null); + } + + function getCols() { + if (self.current !== null) { + //this is a hack, but there's weirdly no "real" way to get the number of columns + return window.getComputedStyle(self.current).getPropertyValue('grid-template-columns').split(' ').length; + } else { + return 3; + } + } + + useLayoutEffect(() => { + setNumcols(getCols()); + }, []) + + useEffect(() => { + window.addEventListener('resize', (event) => { + setNumcols(getCols()); + }) + }) + + + let slots = newList.map((game) => { + if (game) { + return + } else { + return
+ } + }) + + return ( +
+ {slots.map((elem) =>
{elem}
)}
); }