diff --git a/src/components/Header/index.tsx b/src/components/Header/index.tsx new file mode 100644 index 0000000..15bf236 --- /dev/null +++ b/src/components/Header/index.tsx @@ -0,0 +1,64 @@ +import React, { FC, useState } from "react"; +import { Link as RouterLink } from "react-router-dom"; +import { + AppBar, + Link, + Toolbar, + Typography, + InputBase, +} from "@material-ui/core"; +import SportsSoccerIcon from "@material-ui/icons/SportsSoccer"; +import SearchIcon from "@material-ui/icons/Search"; + +import { withGame, IGameState } from "../../store/GameProvider"; + +import useStyles from "./styles"; + +interface IProps extends IGameState { + title: string; +} + +const Header: FC = ({ title, filterGamesByText }) => { + const [searchText, setSearchText] = useState(""); + const classes = useStyles(); + + const handleChange = ( + e: React.ChangeEvent + ): void => setSearchText(e.target.value); + + const handleSubmit = (e: React.FormEvent): void => { + e.preventDefault(); + filterGamesByText(searchText); + }; + + return ( +
+ + + + + {title} + + +
+
+ +
+ + +
+
+
+ ); +}; + +export default withGame((props: IProps) =>
); diff --git a/src/components/Header.tsx b/src/components/Header/styles.ts similarity index 50% rename from src/components/Header.tsx rename to src/components/Header/styles.ts index 43e3bce..7aa8615 100644 --- a/src/components/Header.tsx +++ b/src/components/Header/styles.ts @@ -1,19 +1,9 @@ -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"; -import InputBase from "@material-ui/core/InputBase"; import { createStyles, fade, Theme, makeStyles, } from "@material-ui/core/styles"; -import SportsSoccerIcon from "@material-ui/icons/SportsSoccer"; -import SearchIcon from "@material-ui/icons/Search"; -import { Link as RouterLink } from "react-router-dom"; const useStyles = makeStyles((theme: Theme) => createStyles({ @@ -72,35 +62,4 @@ const useStyles = makeStyles((theme: Theme) => }) ); -const Header: FC<{ title: string }> = ({ title }) => { - const classes = useStyles(); - - return ( -
- - - - - {title} - - -
-
- -
- -
-
-
-
- ); -}; - -export default Header; +export default useStyles; diff --git a/src/components/Loader.tsx b/src/components/Loader/index.tsx similarity index 62% rename from src/components/Loader.tsx rename to src/components/Loader/index.tsx index c887035..8bae555 100644 --- a/src/components/Loader.tsx +++ b/src/components/Loader/index.tsx @@ -1,14 +1,7 @@ import React, { FC } from "react"; -import { makeStyles } from "@material-ui/core/styles"; import CircularProgress from "@material-ui/core/CircularProgress"; -const useStyles = makeStyles({ - root: { - position: "absolute", - top: "50vh", - left: "50vw", - }, -}); +import useStyles from "./styles"; const Loader: FC = () => { const classes = useStyles(); diff --git a/src/components/Loader/styles.ts b/src/components/Loader/styles.ts new file mode 100644 index 0000000..64f889b --- /dev/null +++ b/src/components/Loader/styles.ts @@ -0,0 +1,11 @@ +import { makeStyles } from "@material-ui/core/styles"; + +const useStyles = makeStyles({ + root: { + position: "absolute", + top: "50vh", + left: "50vw", + }, +}); + +export default useStyles; diff --git a/src/components/MatchFull.tsx b/src/components/MatchFull/index.tsx similarity index 73% rename from src/components/MatchFull.tsx rename to src/components/MatchFull/index.tsx index 25343a0..f34cbdd 100644 --- a/src/components/MatchFull.tsx +++ b/src/components/MatchFull/index.tsx @@ -1,18 +1,9 @@ import React, { FC } from "react"; import Moment from "react-moment"; -import { Container, Typography, makeStyles } from "@material-ui/core"; +import { Container, Typography } from "@material-ui/core"; -import IGame from "../types/Game"; - -const useStyles = makeStyles({ - root: { - marginTop: "16px", - marginBottom: "16px", - }, - video: { - marginTop: "16px", - }, -}); +import IGame from "../../types/Game"; +import useStyles from "./styles"; const MatchFull: FC<{ game: IGame }> = ({ game }) => { const classes = useStyles(); diff --git a/src/components/MatchFull/styles.ts b/src/components/MatchFull/styles.ts new file mode 100644 index 0000000..c9e9ece --- /dev/null +++ b/src/components/MatchFull/styles.ts @@ -0,0 +1,13 @@ +import { makeStyles } from "@material-ui/core"; + +const useStyles = makeStyles({ + root: { + marginTop: "16px", + marginBottom: "16px", + }, + video: { + marginTop: "16px", + }, +}); + +export default useStyles; diff --git a/src/components/MatchItem.tsx b/src/components/MatchItem/index.tsx similarity index 62% rename from src/components/MatchItem.tsx rename to src/components/MatchItem/index.tsx index b8d99a3..46c4504 100644 --- a/src/components/MatchItem.tsx +++ b/src/components/MatchItem/index.tsx @@ -1,26 +1,18 @@ import React, { FC } from "react"; import Moment from "react-moment"; import { Link } from "react-router-dom"; -import { makeStyles } from "@material-ui/core/styles"; -import Card from "@material-ui/core/Card"; -import CardActionArea from "@material-ui/core/CardActionArea"; -import CardActions from "@material-ui/core/CardActions"; -import CardContent from "@material-ui/core/CardContent"; -import CardMedia from "@material-ui/core/CardMedia"; -import Button from "@material-ui/core/Button"; -import Typography from "@material-ui/core/Typography"; +import { + Card, + CardActionArea, + CardActions, + CardContent, + CardMedia, + Button, + Typography, +} from "@material-ui/core"; -import IGame from "../types/Game"; - -const useStyles = makeStyles({ - root: { - maxWidth: 345, - marginTop: "16px", - }, - media: { - height: 140, - }, -}); +import IGame from "../../types/Game"; +import useStyles from "./styles"; const MatchItem: FC = ({ title, diff --git a/src/components/MatchItem/styles.ts b/src/components/MatchItem/styles.ts new file mode 100644 index 0000000..6231af6 --- /dev/null +++ b/src/components/MatchItem/styles.ts @@ -0,0 +1,13 @@ +import { makeStyles } from "@material-ui/core"; + +const useStyles = makeStyles({ + root: { + maxWidth: 345, + marginTop: "16px", + }, + media: { + height: 140, + }, +}); + +export default useStyles; diff --git a/src/components/MatchList.tsx b/src/components/MatchList/index.tsx similarity index 72% rename from src/components/MatchList.tsx rename to src/components/MatchList/index.tsx index 88495fd..831e322 100644 --- a/src/components/MatchList.tsx +++ b/src/components/MatchList/index.tsx @@ -1,10 +1,10 @@ import React, { FC } from "react"; import { Container, Grid } from "@material-ui/core"; -import { withGame, IGameState } from "../store/GameProvider"; +import { withGame, IGameState } from "../../store/GameProvider"; -import Loader from "./Loader"; -import MatchItem from "./MatchItem"; +import Loader from "../Loader"; +import MatchItem from "../MatchItem"; const MatchList: FC = ({ games, loading }) => loading ? ( @@ -13,7 +13,7 @@ const MatchList: FC = ({ games, loading }) => {games.map((game, i) => ( - + ))} diff --git a/src/store/GameProvider.tsx b/src/store/GameProvider.tsx index ca414a6..f881855 100644 --- a/src/store/GameProvider.tsx +++ b/src/store/GameProvider.tsx @@ -9,6 +9,7 @@ export interface IGameState { loading: boolean; setGames: React.Dispatch>; selectGameByID: (slug: string) => IGame; + filterGamesByText: (text: string) => void; } export const GameContext = createContext({ @@ -18,6 +19,7 @@ export const GameContext = createContext({ selectGameByID: () => { return {} as IGame; }, + filterGamesByText: () => {}, }); const GameProvider: FC = ({ children }) => { @@ -26,10 +28,12 @@ const GameProvider: FC = ({ children }) => { const selectGameByID = (slug: string): IGame => { const id = parseInt(slug); - const game = games[id]; - return game; + return games[id]; }; + const filterGamesByText = (text: string): void => + setGames(games.filter((g) => g.title.includes(text))); + useEffect(() => { apiClient .get("/") @@ -39,13 +43,14 @@ const GameProvider: FC = ({ children }) => { }) .catch((err) => { setLoading(false); - console.error(err); return
{JSON.stringify(err, null, 2)}
; }); }, []); return ( - + {children} );