@@ -2,76 +2,63 @@ import React, { useState, useEffect } from "react";
2
2
import PropTypes from "prop-types" ;
3
3
4
4
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" ;
8
5
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" ;
12
6
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
+
15
8
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" ;
21
10
import styles from "./categories.module.scss" ;
22
11
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 >
68
52
</ Grid >
69
- </ >
70
- ) ;
53
+ ) ;
54
+ } ) }
55
+ </ Grid >
56
+ </ >
57
+ ) ;
71
58
} ;
72
59
73
60
Categories . propTypes = {
74
- choosing : PropTypes . bool
61
+ choosing : PropTypes . bool
75
62
} ;
76
63
77
64
export default Categories ;
0 commit comments