diff --git a/src/App.tsx b/src/App.tsx index 1c53c54..cd215f2 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2,20 +2,24 @@ import React, { FC } from "react"; import { Switch, Router, Route } from "react-router-dom"; import { createBrowserHistory } from "history"; +import MainLayout from "./layouts/MainLayout"; + import Index from "./pages/Index"; import Detail from "./pages/Detail"; const App: FC = () => ( - - - - + + + + + - - - - + + + + + ); diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 9031aec..baf166c 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -1,5 +1,6 @@ import React, { FC } from "react"; import AppBar from "@material-ui/core/AppBar"; +import Link from "@material-ui/core/Link"; import Toolbar from "@material-ui/core/Toolbar"; import IconButton from "@material-ui/core/IconButton"; import Typography from "@material-ui/core/Typography"; @@ -12,6 +13,7 @@ import { } from "@material-ui/core/styles"; import MenuIcon from "@material-ui/icons/Menu"; import SearchIcon from "@material-ui/icons/Search"; +import { Link as RouterLink } from "react-router-dom"; const useStyles = makeStyles((theme: Theme) => createStyles({ @@ -86,7 +88,9 @@ const Header: FC<{ title: string }> = ({ title }) => { - {title} + + {title} +
diff --git a/src/components/MatchFull.tsx b/src/components/MatchFull.tsx new file mode 100644 index 0000000..015d529 --- /dev/null +++ b/src/components/MatchFull.tsx @@ -0,0 +1,22 @@ +import React, { FC } from "react"; +import Moment from "react-moment"; +import { Container, Typography } from "@material-ui/core"; + +import IGame from "../types/Game"; + +const MatchFull: FC<{ game: IGame }> = ({ game }) => ( + + + {game.title} + + + {game.competition.name} +
+ {game.date} +
+ +
+
+); + +export default MatchFull; diff --git a/src/pages/Detail.tsx b/src/pages/Detail.tsx index a1c3d77..c271183 100644 --- a/src/pages/Detail.tsx +++ b/src/pages/Detail.tsx @@ -1,18 +1,16 @@ -import React, { FC, useState, useEffect } from "react"; +import React, { FC } from "react"; import { useRouteMatch } from "react-router-dom"; +import { withGame, IGameState } from "../store/GameProvider"; + import Loader from "../components/Loader"; -// import MatchItem from "../components/MatchItem"; +import MatchFull from "../components/MatchFull"; -const Detail: FC = () => { - // const [game, setGame] = useState([]); - const [loading, _] = useState(true); +const Detail: FC = ({ loading, selectGameByID }) => { const { params } = useRouteMatch<{ slug: string }>(); + const game = selectGameByID(params.slug); - useEffect(() => {}, []); - console.log(params.slug); - - return loading ? :
{/* */}
; + return loading ? : ; }; -export default Detail; +export default withGame((props: IGameState) => ); diff --git a/src/pages/Index.tsx b/src/pages/Index.tsx index b55af1c..e9a0a14 100644 --- a/src/pages/Index.tsx +++ b/src/pages/Index.tsx @@ -1,12 +1,7 @@ import React, { FC } from "react"; import MatchList from "../components/MatchList"; -import MainLayout from "../layouts/MainLayout"; -const Index: FC = () => ( - - - -); +const Index: FC = () => ; export default Index; diff --git a/src/store/GameProvider.tsx b/src/store/GameProvider.tsx index 1898ac5..ca414a6 100644 --- a/src/store/GameProvider.tsx +++ b/src/store/GameProvider.tsx @@ -8,24 +8,34 @@ export interface IGameState { games: IGame[]; loading: boolean; setGames: React.Dispatch>; + selectGameByID: (slug: string) => IGame; } export const GameContext = createContext({ games: [], loading: true, setGames: () => {}, + selectGameByID: () => { + return {} as IGame; + }, }); const GameProvider: FC = ({ children }) => { const [games, setGames] = useState([]); const [loading, setLoading] = useState(true); + const selectGameByID = (slug: string): IGame => { + const id = parseInt(slug); + const game = games[id]; + return game; + }; + useEffect(() => { apiClient .get("/") .then(({ data }) => { - setLoading(false); setGames(data); + setLoading(false); }) .catch((err) => { setLoading(false); @@ -35,7 +45,7 @@ const GameProvider: FC = ({ children }) => { }, []); return ( - + {children} );