organize things and switch to using /game/:id over /game?id=

This commit is contained in:
Elijah Steres 2021-01-10 01:18:37 -05:00
parent 013d1e0585
commit 31acd0ceed
7 changed files with 21 additions and 23 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -1,10 +1,3 @@
:root {
--background-main: #2f3136; /*discord dark theme background-secondary - the same color as the embeds*/
--background-secondary: #4f545c; /*discord's background-tertiary*/
--background-accent: #4f545c; /*discord's background-accent*/
--highlight: rgb(113, 54, 138); /*matteo purple™*/
}
.game { .game {
align-self: stretch; align-self: stretch;
text-align: center; text-align: center;
@ -124,7 +117,7 @@
} }
.score { .score {
background: var(--background-accent); background: var(--background-secondary);
width: 40px; width: 40px;
min-width: 40px; min-width: 40px;
height: 40px; height: 40px;

View File

@ -57,7 +57,7 @@ function Game(props: {gameId: string, state : GameState}) {
</div> </div>
<div className="footer"> <div className="footer">
<div className="batting">{state.display_top_of_inning ? state.away_name : state.home_name} batting.</div> <div className="batting">{state.display_top_of_inning ? state.away_name : state.home_name} batting.</div>
<div className="leagueoruser">{state.leagueoruser} (<Link to={"/game?id=" + props.gameId}>share</Link>)</div> <div className="leagueoruser">{state.leagueoruser} (<Link to={"/game/" + props.gameId}>share</Link>)</div>
</div> </div>
</div> </div>
); );

View File

@ -1,16 +1,14 @@
import React, {useState} from 'react'; import React, {useState} from 'react';
import ReactRouter from 'react-router';
import {GameState, useListener} from './GamesUtil'; import {GameState, useListener} from './GamesUtil';
import './GamePage.css'; import './GamePage.css';
import Game from './Game'; import Game from './Game';
function GamePage() { function GamePage(props: ReactRouter.RouteComponentProps<{id: string}>) {
let searchparams = new URLSearchParams(window.location.search);
let gameId = searchparams.get('id');
let [games, setGames] = useState<[string, GameState][]>([]); let [games, setGames] = useState<[string, GameState][]>([]);
useListener((newGames) => setGames(newGames)); useListener((newGames) => setGames(newGames));
let game = games.find((game) => game[0] === gameId) let game = games.find((game) => game[0] === props.match.params.id)
return ( return (
<div id="game_container"> <div id="game_container">
{ game ? { game ?

View File

@ -109,17 +109,13 @@ function Grid(props: { gameList: GameList }) {
} }
} }
//set num cols after page loads //set num cols after page loads, then add listener to update if window resizes
useLayoutEffect(() => { useLayoutEffect(() => {
setNumcols(getCols()); setNumcols(getCols());
}, [])
//set num cols on page resize
useEffect(() => {
window.addEventListener('resize', (event) => { window.addEventListener('resize', (event) => {
setNumcols(getCols()); setNumcols(getCols());
}) })
}) }, [])
let emptyKey = 0; let emptyKey = 0;
return ( return (

View File

@ -1,11 +1,22 @@
@import url('https://fonts.googleapis.com/css2?family=Alegreya&display=swap'); @import url('https://fonts.googleapis.com/css2?family=Alegreya&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Goldman:wght@700&display=swap'); @import url('https://fonts.googleapis.com/css2?family=Goldman:wght@700&display=swap');
:root {
--background-main: #2f3136;
--background-secondary: #4f545c;
--background-tertiary: #202225;
--background-accent: #40444b;
--highlight: rgb(113, 54, 138); /*matteo purple™*/
--accent-red: #f04747;
--accent-green: rgb(67, 181, 129);
}
body { body {
background-image: url("img/naturalblack.png"); background-image: url("img/naturalblack.png");
} }
/* Background pattern from Toptal Subtle Patterns */ /* Background pattern from Toptal Subtle Patterns */
div, button, h1, h2, a { * {
font-family: 'Alegreya', serif; font-family: 'Alegreya', serif;
color: white; color: white;
} }

View File

@ -12,8 +12,8 @@ ReactDOM.render(
<Router> <Router>
<Header /> <Header />
<Switch> <Switch>
<Route path="/game" component={() => <GamePage key={window.location.search}/>}/> <Route path="/game/:id" component={GamePage}/>
<Route path="/" component={() => <GamesPage />}/> <Route path="/" component={GamesPage}/>
</Switch> </Switch>
</Router> </Router>
</React.StrictMode>, </React.StrictMode>,