diff --git a/election-ui-javascript/src/components/PartyLinks/PartyLinks.css b/election-ui-javascript/src/components/PartyLinks/PartyLinks.css index 8be8eb8..3bd20c6 100644 --- a/election-ui-javascript/src/components/PartyLinks/PartyLinks.css +++ b/election-ui-javascript/src/components/PartyLinks/PartyLinks.css @@ -1,3 +1,23 @@ .Party-links { color: red; + display: grid; + grid-template-columns: repeat(3, 1fr); + list-style: none; + gap: 10px; + grid-template-rows: repeat(2, 1fr); + padding-inline-start: 0px; } + +.Party-links li { + padding: 1rem; + border: 3px solid #bb1919; + margin-top: 1rem; +} +.Party-links li a { + color: black; + display: inline-block; + transition: all 500ms; +} +.Party-links li a:hover { + transform: scale(1.1); +} \ No newline at end of file diff --git a/election-ui-javascript/src/components/Scoreboard.js b/election-ui-javascript/src/components/Scoreboard.js index 3b39b82..40333c9 100644 --- a/election-ui-javascript/src/components/Scoreboard.js +++ b/election-ui-javascript/src/components/Scoreboard.js @@ -8,13 +8,14 @@ import PartyLinks from "./PartyLinks"; function Scoreboard() { const [loading, setLoading] = useState(true); const [error, setError] = useState(false); - const [results, setResults] = useState([]); + const [data, setData] = useState({results: [], isComplete: false}); + async function getData() { try { setLoading(true); - const resultData = await fetchData(); - setResults(resultData.results); + const theData = await fetchData(); + setData({results: theData.results, isComplete: theData.isComplete}) setLoading(false); } catch (e) { setLoading(false); @@ -37,9 +38,10 @@ function Scoreboard() { error ?

Error

: <>

Results

- - Refresh + +

Learn more about the parties...

+ } diff --git a/election-ui-javascript/src/components/Scorecard/Scorecard.css b/election-ui-javascript/src/components/Scorecard/Scorecard.css index aa5707b..f8f47af 100644 --- a/election-ui-javascript/src/components/Scorecard/Scorecard.css +++ b/election-ui-javascript/src/components/Scorecard/Scorecard.css @@ -1,4 +1,4 @@ -.Scorecard { +/* .Scorecard { background-color: #eeeeee; } @@ -18,4 +18,51 @@ .Scorecard-table tbody tr:nth-of-type(2n + 1) { background-color: white; -} \ No newline at end of file +} + +.winner{ + background-color: yellow; +} + + +.badge { + background-color: red; + color: white; + padding: 4px 8px; + text-align: center; + border-radius: 5px; + } */ + +.Scorecard { + background-color: #eeeeee; +} + +.Scorecard-table { + width: 100%; + & th, + & td { + padding: 0.5rem; + } + & thead { + background-color: #bb1919; + color: white; + } + + & tbody { + & tr:nth-of-type(2n + 1) { + background-color: white; + } + } +} + +.winner { + background-color: yellow; +} + +.badge { + background-color: red; + color: white; + padding: 4px 8px; + text-align: center; + border-radius: 5px; +} diff --git a/election-ui-javascript/src/components/Scorecard/index.js b/election-ui-javascript/src/components/Scorecard/index.js index 481678b..ecf1d11 100644 --- a/election-ui-javascript/src/components/Scorecard/index.js +++ b/election-ui-javascript/src/components/Scorecard/index.js @@ -1,17 +1,30 @@ import './Scorecard.css'; -function Scorecard({ results }) { +function Scorecard({data}) { + const {results, isComplete} = data ; if (!results || results.length === 0) { return
No results
; } let scores = []; + + +//gets the winner +//const winner = results.reduce((max, { votes }) => Math.max(max, votes), 0); +const votesArr = results.map(({votes}) => votes); +const winner = Math.max(...votesArr); + +const isWinner = (votes ,comp, winner ) => comp && votes === winner ; + + + for (let i=0; i < results.length; i++) { + const theWinner = isWinner(results[i].votes, isComplete, winner); scores.push( {results[i].party} - {results[i].candidateId} - {results[i].votes} + {results[i].name} + {results[i].votes} {theWinner && The winner} ) } diff --git a/election-ui-javascript/src/dataFetcher/index.js b/election-ui-javascript/src/dataFetcher/index.js index e6e00f6..3e0772b 100644 --- a/election-ui-javascript/src/dataFetcher/index.js +++ b/election-ui-javascript/src/dataFetcher/index.js @@ -1,10 +1,16 @@ import { fetchResultData, fetchCandidateData } from '../fakeAPI'; // Let's imagine this is an external service that we are calling via https async function fetchResults() { - const results = await fetchResultData(); - const candidateData = fetchCandidateData(); + const {results, isComplete} = await fetchResultData(); + const candidateData = fetchCandidateData(); + + const newResults = results.map((item, index) => { + return {...item, name: candidateData?.[index]?.name} + }) - return results; + const theResults = {isComplete, results: newResults}; + + return theResults } export default fetchResults;