Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the static-path package #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"dependencies": {
"@craco/craco": "^6.1.1",
"@fortawesome/fontawesome-svg-core": "^1.2.34",
"@fortawesome/free-solid-svg-icons": "^5.15.2",
"@fortawesome/free-brands-svg-icons": "^5.15.4",
"@fortawesome/free-solid-svg-icons": "^5.15.2",
"@fortawesome/react-fontawesome": "^0.1.14",
"@tailwindcss/forms": "^0.3.3",
"@tsconfig/node16": "^1.0.1",
Expand All @@ -34,6 +34,7 @@
"react-markdown": "^6.0.2",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.2",
"static-path": "^0.0.1",
"typescript": "^4.1.2",
"uuid": "^8.3.2",
"web-vitals": "^1.0.1"
Expand Down
37 changes: 19 additions & 18 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,55 +1,56 @@
import React, {Component} from 'react';
import {BrowserRouter, Route, Switch, useParams} from "react-router-dom";
import {Footer} from './components/Footer';
import React, { Component } from 'react';
import { BrowserRouter, Route, Switch, useParams } from "react-router-dom";
import { Footer } from './components/Footer';
import Header from './components/Header';
import Home from './Pages/Home';
import {Games} from "./Pages/Games";
import {SingleGame} from "./Pages/SingleGame";
import { Games } from "./Pages/Games";
import { SingleGame } from "./Pages/SingleGame";
import Planning from './Pages/Planning';
import Contact from './Pages/Contact';
import CodeOfConduct from "./Pages/CodeOfConduct";
import AboutMegagames from "./Pages/AboutMegagames";
import {NoMatch} from "./components/NoMatch";
import { NoMatch } from "./components/NoMatch";
import * as paths from "./utils/path";

function WrappedSingleGame() {
const game = useParams<{game:string}>()["game"];
const game = useParams<{ game: string }>()["game"];

return <SingleGame game={game } />;
return <SingleGame game={game} />;
}

class App extends Component<{}> {
render() {
return <BrowserRouter>
<Header/>
<Header />
<main className='flex-1 flex flex-col'>
<Switch>
<Route exact path="/">
<Home/>
<Home />
</Route>
<Route exact path="/games">
<Route exact path={paths.gameList.pattern}>
<Games />
</Route>
<Route path="/games/:game">
<Route path={paths.singleGame.pattern}>
<WrappedSingleGame />
</Route>
<Route path="/planning">
<Route path={paths.planning.pattern}>
<Planning />
</Route>
<Route path="/contact">
<Route path={paths.contact.pattern}>
<Contact />
</Route>
<Route path="/code-of-conduct">
<Route path={paths.codeOfConduct.pattern}>
<CodeOfConduct />
</Route>
<Route path="/about-megagames">
<Route path={paths.aboutMegagames.pattern}>
<AboutMegagames />
</Route>
<Route path="*">
<NoMatch/>
<NoMatch />
</Route>
</Switch>
</main>
<Footer/>
<Footer />
</BrowserRouter>
}
}
Expand Down
79 changes: 40 additions & 39 deletions src/Pages/Games.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import React, {ReactElement} from "react";
import {isRight, Either, isLeft} from "fp-ts/Either";
import {Game, GameAPI} from "../types/types";
import {GameAPIDecode} from "../types/io-ts-def";
import {faEnvelopeOpenText} from "@fortawesome/free-solid-svg-icons/faEnvelopeOpenText";
import {faDesktop} from "@fortawesome/free-solid-svg-icons/faDesktop";
import {Circle, TextRow} from "../components/Placeholders";
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
import {Link} from "react-router-dom";
import {Hero, HeroHeading, MainContent} from "../components/Hero";
import {dateSorter, getJSDateFromGameDate, getStringFromGameDate} from "../utils";
import {apiCall} from "../utils/api";
import {MakeLeft, MakeRight} from "../utils/io-ts-helpers";
import React, { ReactElement } from "react";
import { isRight, Either, isLeft } from "fp-ts/Either";
import { Game, GameAPI } from "../types/types";
import { GameAPIDecode } from "../types/io-ts-def";
import { faEnvelopeOpenText } from "@fortawesome/free-solid-svg-icons/faEnvelopeOpenText";
import { faDesktop } from "@fortawesome/free-solid-svg-icons/faDesktop";
import { Circle, TextRow } from "../components/Placeholders";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { Link } from "react-router-dom";
import { Hero, HeroHeading, MainContent } from "../components/Hero";
import { dateSorter, getJSDateFromGameDate, getStringFromGameDate } from "../utils";
import { apiCall } from "../utils/api";
import { MakeLeft, MakeRight } from "../utils/io-ts-helpers";
import * as paths from "../utils/path";

function isGameApi(value: any): value is GameAPI {
let ma = GameAPIDecode.decode(value);
Expand Down Expand Up @@ -61,27 +62,27 @@ abstract class MegagameList<T> extends React.Component<T> {
class UnfetchedMegagame extends MegagameList<{ key: number }> {

protected getIcon(): React.ReactElement {
return <Circle className="bg-gray-500"/>;
return <Circle className="bg-gray-500" />;
}

protected getDate(): React.ReactElement {
return <div className="w-1/4"><TextRow className="bg-gray-500 mb-2 h-3" height={false}/></div>;
return <div className="w-1/4"><TextRow className="bg-gray-500 mb-2 h-3" height={false} /></div>;
}

protected getHeading(): React.ReactElement {
return <div className="w-2/4"><TextRow className="bg-gray-500 mb-2"/></div>;
return <div className="w-2/4"><TextRow className="bg-gray-500 mb-2" /></div>;
}

protected getSubtitle(): React.ReactElement {
return <div className="w-2/6"><TextRow className="bg-gray-500 mb-2 h-3" height={false}/></div>;
return <div className="w-2/6"><TextRow className="bg-gray-500 mb-2 h-3" height={false} /></div>;
}

protected getPreamble(): React.ReactElement {
return <div className="w-5/6">
{
(new Array(3))
.fill(null)
.map((value, index) => <TextRow key={index} className="bg-gray-500 mb-2 h-4" height={false}/>)
.map((value, index) => <TextRow key={index} className="bg-gray-500 mb-2 h-4" height={false} />)
}
</div>;
}
Expand All @@ -91,11 +92,11 @@ class UnfetchedMegagame extends MegagameList<{ key: number }> {
class FetchedMegagame extends MegagameList<Game> {

protected getIcon(): ReactElement {
return <FontAwesomeIcon icon={icons[this.props.type]} title={this.props.type} className="h-full text-5xl"/>;
return <FontAwesomeIcon icon={icons[this.props.type]} title={this.props.type} className="h-full text-5xl" />;
}

protected getHeading(): React.ReactElement {
return <Link to={`/games/${this.props.id}`}>{this.props.name}</Link>;
return <Link to={paths.singleGame({ game: this.props.id })}> {this.props.name}</Link >;
}

protected getDate(): React.ReactElement {
Expand Down Expand Up @@ -136,7 +137,7 @@ function GameListFilter(
</div>
<div className="flex-1 flex flex-col justify-center">
<div>
<input id="only-future" type="checkbox" checked={props.past} onChange={props.onChange}/>
<input id="only-future" type="checkbox" checked={props.past} onChange={props.onChange} />
<label className="pl-1" htmlFor="only-future">Show past games</label>
</div>
</div>
Expand All @@ -153,7 +154,7 @@ type GameListParams = {
}

function GameList(props: GameListParams) {
const {fetched, filter, changeFilter, past} = props;
const { fetched, filter, changeFilter, past } = props;

let gameList: Array<Game | number>;

Expand All @@ -166,8 +167,8 @@ function GameList(props: GameListParams) {
Looks like an error occurred while getting the list of games.
</p>
<p className="py-2">
Try refreshing your browser and trying again. If that doesn't work, <Link to="contact">send the
webmaster a message through the contact page</Link>
Try refreshing your browser and trying again. If that doesn't work, <Link to={paths.contact({})}>send the
webmaster a message through the contact page</Link>
</p>
</React.Fragment>
}
Expand All @@ -192,15 +193,15 @@ function GameList(props: GameListParams) {
const filteredGames = gameList.filter(filterGame);

return <React.Fragment>
<GameListFilter onChange={changeFilter} value={filter} past={past}/>
<GameListFilter onChange={changeFilter} value={filter} past={past} />
<ul>
{
filteredGames.length > 0
? filteredGames
.map(
value =>
typeof value === 'number'
? <UnfetchedMegagame key={value}/>
? <UnfetchedMegagame key={value} />
: <FetchedMegagame key={value.id} {...value} />
)
: <p>No games matched your criteria - try again!</p>
Expand Down Expand Up @@ -240,7 +241,7 @@ export class Games extends React.Component<GamesProps, GamesState> {
}

private getAllGames() {
const {controller, response: api} = apiCall('games');
const { controller, response: api } = apiCall('games');

this.controller = controller;

Expand All @@ -253,17 +254,17 @@ export class Games extends React.Component<GamesProps, GamesState> {

return response.json();
}).then(value => {
if (!isGameApi(value)) {
throw new Error('API response wasn\'t right? ' + JSON.stringify(value))
}
if (!isGameApi(value)) {
throw new Error('API response wasn\'t right? ' + JSON.stringify(value))
}

value.games.sort(dateSorter);
value.games.sort(dateSorter);

this.setState({
fetched: true,
gameList: MakeRight(value.games)
});
}
this.setState({
fetched: true,
gameList: MakeRight(value.games)
});
}
).catch(
reason => {
if (!(reason instanceof DOMException)) {
Expand All @@ -277,13 +278,13 @@ export class Games extends React.Component<GamesProps, GamesState> {
}

render() {
const {gameList, fetched, filter, past} = this.state;
const { gameList, fetched, filter, past } = this.state;

const changeFilter = (event: React.ChangeEvent<HTMLSelectElement | HTMLInputElement>) => {
if (event.target instanceof HTMLSelectElement) {
this.changeFilter(event.target.value);
} else {
this.setState({past: event.target.checked})
this.setState({ past: event.target.checked })
}
}
return <React.Fragment>
Expand All @@ -309,6 +310,6 @@ export class Games extends React.Component<GamesProps, GamesState> {
newVal = value
}

this.setState({filter: newVal})
this.setState({ filter: newVal })
}
}
Loading