Show accepted votes on ElectionStatusPage

This commit is contained in:
David Ernst
2020-08-14 14:46:40 -07:00
parent 6da9f1c5dc
commit 578ac88156
3 changed files with 29 additions and 1 deletions

View File

@@ -59,7 +59,8 @@
"next-transpile-modules": "^4.0.3",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-flip-move": "^3.0.4"
"react-flip-move": "^3.0.4",
"swr": "^0.3.0"
},
"devDependencies": {
"@types/mailgun-js": "^0.22.10",

View File

@@ -0,0 +1,25 @@
import { useRouter } from 'next/router'
import useSWR from 'swr'
const fetcher = (url: string) => fetch(url).then((r) => r.json())
export const AcceptedVotes = (): JSX.Element => {
const { election_id } = useRouter().query
// Grab votes from api
const { data, error } = useSWR(election_id ? `/api/election/${election_id}/accepted-votes` : null, fetcher)
if (error) return <div>Error loading Accepted Votes</div>
if (!data) return <div>Loading...</div>
return (
<div>
<h3>Accepted Votes</h3>
<ol>
{data.map((vote, index: number) => (
<li key={index}>{JSON.stringify(vote)}</li>
))}
</ol>
</div>
)
}

View File

@@ -2,6 +2,7 @@ import { useRouter } from 'next/router'
import { GlobalCSS } from '../GlobalCSS'
import { Head } from '../Head'
import { AcceptedVotes } from './AcceptedVotes'
export const ElectionStatusPage = (): JSX.Element => {
const { election_id } = useRouter().query
@@ -12,6 +13,7 @@ export const ElectionStatusPage = (): JSX.Element => {
<main>
<h1>Election Status</h1>
<h2>ID: {election_id}</h2>
<AcceptedVotes />
</main>
<style jsx>{`