Skip to content

Commit 69f8613

Browse files
committed
♻️ Update category step for use with controller
1 parent c8ac20f commit 69f8613

File tree

3 files changed

+68
-66
lines changed

3 files changed

+68
-66
lines changed

src/assets/categories.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1+
import CompareArrows from '@material-ui/icons/CompareArrows';
2+
import EuroSymbol from '@material-ui/icons/EuroSymbol';
3+
import LocalFlorist from '@material-ui/icons/LocalFlorist';
4+
import LocalHospital from '@material-ui/icons/LocalHospital';
5+
16
export const categories = {
2-
"arbeit-wirtschaft": "Arbeit & Wirtschaft",
3-
"bildung": "Bildung",
4-
"gesundheit": "Gesundheit",
5-
"umwelt": "Umwelt",
7+
"arbeit-wirtschaft": "Arbeit & Wirtschaft",
8+
"bildung": "Bildung",
9+
"gesundheit": "Gesundheit",
10+
"umwelt": "Umwelt",
611
};
712

13+
export const categoryIcons = {
14+
"arbeit-wirtschaft": CompareArrows,
15+
"bildung": LocalFlorist,
16+
"gesundheit": EuroSymbol,
17+
"umwelt": LocalHospital,
18+
}
19+
820
export type Category = keyof typeof categories;

src/pages/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useEffect } from "react";
22
import useGameController, { Step, GameController } from "../hooks/controller";
33
import Landing from "../templates/landing/landing";
44
import MatchMaking from "../templates/matchMaking/matchMaking";
5+
import Category from "../templates/categories/categories";
56

67
interface IndexPageProps {}
78

@@ -11,6 +12,8 @@ const renderStep = (step: Step): React.FC<ReturnType<GameController>> => {
1112
return Landing;
1213
case Step.opponents:
1314
return MatchMaking;
15+
case Step.category:
16+
return Category;
1417
default:
1518
return () => <h1>Not found</h1>;
1619
}
@@ -19,7 +22,7 @@ const renderStep = (step: Step): React.FC<ReturnType<GameController>> => {
1922
const localStorageKey = "GAME_STATE";
2023
let prevState;
2124
try {
22-
prevState = JSON.parse(window.localStorage.getItem(localStorageKey) || "");
25+
prevState = JSON.parse(window.localStorage.getItem(localStorageKey) || "");
2326
if (!prevState) {
2427
prevState = undefined;
2528
}

src/templates/categories/categories.jsx

Lines changed: 48 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,76 +2,63 @@ import React, { useState, useEffect } from "react";
22
import PropTypes from "prop-types";
33

44
import Typography from "@material-ui/core/es/Typography";
5-
import TextField from "@material-ui/core/es/TextField";
6-
import Select from "@material-ui/core/es/Select";
7-
import MenuItem from "@material-ui/core/es/MenuItem";
85
import Button from "@material-ui/core/es/Button";
9-
import LinearProgress from "@material-ui/core/es/LinearProgress";
10-
import FormControl from "@material-ui/core/es/FormControl";
11-
import FormHelperText from "@material-ui/core/es/FormHelperText";
126
import Grid from "@material-ui/core/es/Grid";
13-
import Paper from "@material-ui/core/es/Paper";
14-
import Avatar from "@material-ui/core/es/Avatar";
7+
158
import CountDown from "../../components/countDown";
16-
import CompareArrows from '@material-ui/icons/CompareArrows';
17-
import EuroSymbol from '@material-ui/icons/EuroSymbol';
18-
import LocalFlorist from '@material-ui/icons/LocalFlorist';
19-
import LocalHospital from '@material-ui/icons/LocalHospital';
20-
import * as locations from "../../assets/locations.json";
9+
import { categoryIcons, categories } from "../../assets/categories";
2110
import styles from "./categories.module.scss";
2211

23-
const Categories = ({ choosing }) => {
24-
const [timeLeft, setTimeLeft] = useState(true);
25-
useEffect(() => {
26-
const timer = setTimeout(() => setTimeLeft(false), 10000);
27-
return () => {
28-
clearTimeout(timer);
29-
};
30-
}, []);
31-
const categories = [
32-
{ name: "Bildung", icon: <CompareArrows className={styles.buttonIcon} /> },
33-
{ name: "Umwelt", icon: <LocalFlorist className={styles.buttonIcon} /> },
34-
{ name: "Arbeit & Wirtschaft", icon: <EuroSymbol className={styles.buttonIcon} /> },
35-
{ name: "Gesundheit", icon: <LocalHospital className={styles.buttonIcon} /> }
36-
];
37-
return (
38-
<>
39-
<CountDown />
40-
<Grid container spacing={3}>
41-
{choosing && (
42-
<Grid item xs={12}>
43-
<Typography variant="h3" component="h2">
44-
Wähle eine Kategorie:
45-
</Typography>
46-
</Grid>
47-
)}
48-
{!choosing && (
49-
<Grid item xs={12}>
50-
<Typography variant="h3" component="h2">
51-
Dein Gegner wählt eine Kategorie!
52-
</Typography>
53-
</Grid>
54-
)}
55-
{categories.map(category => (
56-
<Grid item xs={12}key={category.name} >
57-
<Button
58-
color={!timeLeft ? "secondary" : "primary"}
59-
variant="contained"
60-
disabled={!choosing && timeLeft}
61-
fullWidth
62-
>
63-
{category.icon}
64-
{category.name}
65-
</Button>
66-
</Grid>
67-
))}
12+
const Categories = ({ choosing = true }) => {
13+
const [timeLeft, setTimeLeft] = useState(true);
14+
useEffect(() => {
15+
const timer = setTimeout(() => setTimeLeft(false), 10000);
16+
return () => {
17+
clearTimeout(timer);
18+
};
19+
}, []);
20+
const categoryEntries = Object.entries(categories);
21+
return (
22+
<>
23+
<CountDown />
24+
<Grid container spacing={3}>
25+
{choosing && (
26+
<Grid item xs={12}>
27+
<Typography variant="h3" component="h2">
28+
Wähle eine Kategorie:
29+
</Typography>
30+
</Grid>
31+
)}
32+
{!choosing && (
33+
<Grid item xs={12}>
34+
<Typography variant="h3" component="h2">
35+
Dein Gegner wählt eine Kategorie!
36+
</Typography>
37+
</Grid>
38+
)}
39+
{categoryEntries.map(([cat, name]) => {
40+
const Icon = categoryIcons[cat];
41+
return (
42+
<Grid item xs={12} key={cat} >
43+
<Button
44+
color={!timeLeft ? "secondary" : "primary"}
45+
variant="contained"
46+
disabled={!choosing && timeLeft}
47+
fullWidth
48+
>
49+
<Icon className={styles.buttonIcon} />
50+
{name}
51+
</Button>
6852
</Grid>
69-
</>
70-
);
53+
);
54+
})}
55+
</Grid>
56+
</>
57+
);
7158
};
7259

7360
Categories.propTypes = {
74-
choosing: PropTypes.bool
61+
choosing: PropTypes.bool
7562
};
7663

7764
export default Categories;

0 commit comments

Comments
 (0)