aboutsummaryrefslogtreecommitdiff
path: root/src/components/Scoreboard/Scoreboard.js
blob: c7bc6d8dfb6f7755ee940731d2d008c4bff030e3 (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
55
56
57
58
59
60
import React, { useEffect, useState } from 'react';

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

import { makeStyles } from "@material-ui/core/styles";

import { get } from "../../requests";
import SolutionCard from "../SolutionCard/SolutionCard";
import Loading from "../Loading/Loading";


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

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

  const updateSolutions = () => {
    get('scoreboard/').then(response => {
      setTimeout(() => {
        setSolutions(response.data);
      }, 300);
    });
  };

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

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

  return (
    <Container maxWidth="xs">
      <Typography variant="h3" className={classes.pageHeader}>
        Scoreboard
      </Typography>
      {(solutions.length === 0) && <Loading />}
      <Grid container justify="center" direction="column" spacing={3}>
        {solutions.slice(0, 30).map(solution => (
          <Grid item key={solution.id}>
            <SolutionCard data={solution} removeThisCard={removeSolution}/>
          </Grid>
        ))}
      </Grid>
    </Container>
  );
};

export default Scoreboard;