aboutsummaryrefslogtreecommitdiff
path: root/src/components/Scoreboard/Scoreboard.js
blob: 039b9515d1c96a73ef8a89dc0f6f7916fcb3f190 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import React, { useEffect, useState } from 'react';

import {
  Container,
  Typography,
  Grid,
} from "@material-ui/core";

import { get } from "../../requests";
import SolutionCard from "../SolutionCard/SolutionCard";
import { makeStyles } from "@material-ui/core/styles";


const useStyles = makeStyles(theme => ({
  pageHeader: {
    textAlign: 'center',
    margin: theme.spacing(2),
  }
}));

const Scoreboard = () => {
  const classes = useStyles();
  const [solutions, setSolutions] = useState([]);

  const updateSolutions = async () => {
    const response = await get('solutions/');
    await setSolutions(response.data);
  };

  const removeSolution = (id) => {
    setSolutions(solutions.filter((solution => solution.id !== id)));
  };

  useEffect(() => {
    updateSolutions();
  }, []);

  return (
    <Container maxWidth="xs">
      <Typography variant="h3" className={classes.pageHeader}>
        Scoreboard
      </Typography>
      <Grid container justify="center" direction="column" spacing={3}>
        {solutions.map(solution => (
          <Grid item>
            <SolutionCard solution={solution} removeThisCard={removeSolution}/>
          </Grid>
        ))}
      </Grid>
    </Container>
  );
};

export default Scoreboard;