Skip to content

Commit

Permalink
update results screen
Browse files Browse the repository at this point in the history
  • Loading branch information
aao056 committed Jan 22, 2025
1 parent 62c4f68 commit 8f996cd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/components/account/account-ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export function AccountTransactions({ address }: { address: PublicKey }) {
return (
<div className="space-y-2">
<div className="flex justify-between">
<h2 className="text-2xl font-bold">Transaction History</h2>
<h2 className="text-2xl font-bold">Voting History</h2>
<div className="space-x-2">
{query.isLoading ? (
<span className="loading loading-spinner"></span>
Expand All @@ -213,7 +213,7 @@ export function AccountTransactions({ address }: { address: PublicKey }) {
{query.isSuccess && (
<div>
{query.data.length === 0 ? (
<div>No transactions found.</div>
<div>No votes found.</div>
) : (
<table className="table border-4 rounded-lg border-separate border-base-300">
<thead>
Expand Down
2 changes: 0 additions & 2 deletions src/components/results/results-data-access.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export function useCandidateScores() {

const scores: any[] = []

console.log(candidates)

candidates.map((cand) => {
if (!cand.voters.length) {
scores.push({
Expand Down
43 changes: 33 additions & 10 deletions src/components/results/results-feature.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,55 @@ import { useVotingdappProgram } from '../votingdapp/votingdapp-data-access'
import { ResultsChart } from "./results-ui"
import { WalletButton } from '../solana/solana-provider'
import getUnixInDate from '@/utils/getUnixInDate'
import { AccountTransactions } from '../account/account-ui'
import { useState, useEffect } from 'react'

export default function ResultsFeature() {
const { publicKey } = useWallet()
const { accounts, programId } = useVotingdappProgram()
const [electionHasFinished, setElectionHasFinished] = useState(false)
const [endTime, setEndTime] = useState(null)

// const title = accounts.data && accounts.data.length ? accounts.data[0].account?.name : "Unintialized Blockchain Presidental Election"
// const subtitle = accounts.data && accounts.data.length ? `${accounts.data[0].account?.description}` : "No description yet"
// const start_time = accounts.data && accounts.data.length ? `${getUnixInDate(accounts.data[0].account?.startTime.toNumber())}` : "No data"
// const end_time = accounts.data && accounts.data.length ? `${getUnixInDate(accounts.data[0].account?.endTime.toNumber())}` : "No data"
// Extract and parse the election end time
useEffect(() => {
if (accounts.data && accounts.data.length) {
const endTimeUnix = accounts.data[0].account?.endTime.toNumber()
const parsedDate = getUnixInDate(endTimeUnix)
if (!parsedDate) setEndTime(parsedDate)

const endDate = new Date(parsedDate)
if (endDate < new Date()) {
setElectionHasFinished(true)
}
}
}, [accounts.data])

return publicKey ? (
<div>
<AppHero
title={"Election results"}
subtitle={'This page displays the election results'}
>
{/* <p className='mb-3'>
Election starts: {start_time}<br />
Election ends: {end_time}
</p> */}
<p className="mb-6">
<ExplorerLink path={`account/${programId}`} label={ellipsify(programId.toString())} />
</p>
{/* <VotingDappSystemCreate /> */}
</AppHero>
<ResultsChart />
{electionHasFinished ? (
<div>
<div className='my-2'>
<ResultsChart />
</div>
<div className='my-8'>
<AccountTransactions address={programId} />
</div>
</div>
) : (
<div className="text-center">
<p className="text-lg font-medium">
The election is still taking place. Please come back after the election has finished.
</p>
</div>
)}
</div>
) : (
<div className="max-w-4xl mx-auto">
Expand Down
2 changes: 1 addition & 1 deletion src/utils/getUnixInDate.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default function getUnixInDate(timestamp: number) {
export default function getUnixInDate(timestamp: number): Date {
return new Date(timestamp * 1000)
}

0 comments on commit 8f996cd

Please # to comment.