From 7c4e13d11bc2fc5b0f03efc959dd551a30565e8a Mon Sep 17 00:00:00 2001 From: Eug-VS Date: Thu, 2 Jan 2020 17:20:23 +0300 Subject: Create Scoreboard component & integrate with API --- src/components/Scoreboard/Scoreboard.js | 28 ++++++++++++++++++++++++++++ src/components/Scoreboard/Solution.js | 32 ++++++++++++++++++++++++++++++++ src/index.js | 28 +++++++++++++++++++++++----- 3 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 src/components/Scoreboard/Scoreboard.js create mode 100644 src/components/Scoreboard/Solution.js diff --git a/src/components/Scoreboard/Scoreboard.js b/src/components/Scoreboard/Scoreboard.js new file mode 100644 index 0000000..1ebca90 --- /dev/null +++ b/src/components/Scoreboard/Scoreboard.js @@ -0,0 +1,28 @@ +import React, {useEffect, useState} from 'react'; + + +import { get } from "../../requests"; +import Solution from "./Solution"; + + +const Scoreboard = () => { + const [solutions, setSolutions] = useState([]); + + const updateSolutions = async () => { + const response = await get('solutions/'); + await setSolutions(response.data); + }; + + useEffect(() => { + updateSolutions(); + }, []); + + + return ( +
+ { solutions.map(solution => ) } +
+ ); +}; + +export default Scoreboard; \ No newline at end of file diff --git a/src/components/Scoreboard/Solution.js b/src/components/Scoreboard/Solution.js new file mode 100644 index 0000000..3f46eb5 --- /dev/null +++ b/src/components/Scoreboard/Solution.js @@ -0,0 +1,32 @@ +import React from 'react'; + +import { + Card, + CardContent, + Typography, + Paper, +} from "@material-ui/core"; + +import styled from "styled-components"; + +const Solution = ({ solution }) => { + + const author = solution.author? solution.author : 'anonymous'; + return ( + + + { solution.result } + + + by {author} + + + ) +}; + +const PaperWrapper = styled(Card)` + padding: 10px; + margin: 25px; +`; + +export default Solution; \ No newline at end of file diff --git a/src/index.js b/src/index.js index 5c657f9..38a79a6 100644 --- a/src/index.js +++ b/src/index.js @@ -1,10 +1,17 @@ import React, { useState } from 'react'; import ReactDOM from 'react-dom'; +import { + Typography, + Paper, + Container, +} from "@material-ui/core"; + import styled from 'styled-components'; import CssBaseline from '@material-ui/core/CssBaseline' import Header from './components/Header/Header'; +import Scoreboard from "./components/Scoreboard/Scoreboard"; const App = () => { @@ -15,11 +22,22 @@ const App = () => {
-

This is the {page} page!

-

- This text is rendered outside of Header component, but - interacting with Header can influence content of this page! -

+ + + This is the {page} page! + { + (page === 'scoreboard')? + () + : + ( +

+ This text is rendered outside of Header component, but + interacting with Header can influence content of this page! +

+ ) + } +
+
); }; -- cgit v1.2.3