Skip to content

Commit

Permalink
Merge pull request #138 from algorandfoundation/chore/redirect-to-act…
Browse files Browse the repository at this point in the history
…ive-session

chore: redirect to active session
  • Loading branch information
PhearZero authored Dec 11, 2023
2 parents 3b893ff + 5d1bcd8 commit ccea19e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 31 deletions.
6 changes: 1 addition & 5 deletions src/build-a-bull/src/components/siteHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ interface Link {
onClick?: () => void
}

const createNavigation = () =>
[
{ name: 'Home', href: '/', protect: false },
{ name: 'Create', href: '/create', protect: true },
] as Link[]
const createNavigation = () => [{ name: 'Create', href: '/create', protect: true }] as Link[]

function NavLink(props: { currentClasses: string; defaultClasses: string; link: Link; displayName?: string }) {
const classes = 'no-underline text-black'
Expand Down
12 changes: 11 additions & 1 deletion src/build-a-bull/src/features/rounds/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useWallet } from '@makerx/use-wallet'
import { Alert, Button, Skeleton, Typography } from '@mui/material'
import sortBy from 'lodash.sortby'
import { useEffect, useState } from 'react'
import { Link } from 'react-router-dom'
import { Link, useNavigate } from 'react-router-dom'
import { VotingRoundGlobalState, fetchVotingRoundGlobalStatesByCreators } from '@/shared/VotingRoundContract'
import { VoteType } from '@/shared/types'
import { getHasVoteEnded, getHasVoteStarted } from '@/shared/vote'
Expand Down Expand Up @@ -36,6 +36,16 @@ const VotingRounds = () => {
const [isLoading, setIsLoading] = useState(true)
const [error, setError] = useState<string | null>(null)

// Redirect to live round
const navigate = useNavigate()
useEffect(() => {
// TODO: add production voting round
const appId = import.meta.env.VITE_ALGOD_NETWORK === 'testnet' ? '499163907' : ''
if (import.meta.env.VITE_ENVIRONMENT !== 'local') {
navigate(`/vote/${appId}`)
}
}, [])

useEffect(() => {
let addressesToFetch = [] as string[]
if (showMyRounds && activeAddress) {
Expand Down
30 changes: 13 additions & 17 deletions src/build-a-bull/src/features/vote/VoteResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import FileDownloadIcon from '@mui/icons-material/FileDownload'
import { Alert, Button, Skeleton, Typography } from '@mui/material'
import { saveAs } from 'file-saver'
import Papa from 'papaparse'
import { useState } from 'react'
import { Link } from 'react-router-dom'
import { useMemo, useState } from 'react'
import { VotingRoundMetadata } from '@/shared/IPFSGateway'
import { VotingRoundGlobalState } from '@/shared/VotingRoundContract'
import { ProposalCard } from '@/shared/ProposalCard'
import { VotingRoundResult } from '@/shared/types'
import { generateOptionIDsToCountsMapping } from '@/utils/common'
import { VoteDetails } from './VoteDetails'
import VotingStats from './VotingStats'
import { VotingTime } from './VotingTime'

Expand All @@ -33,7 +31,15 @@ export const VoteResults = ({
const [error, setError] = useState<string | null>(null)

const optionIDsToCounts = votingRoundResults !== undefined ? generateOptionIDsToCountsMapping(votingRoundResults) : {}

function getTotalVotes() {
return votingRoundResults && votingRoundMetadata
? votingRoundResults.reduce((c, r) => {
const isYesOption = votingRoundMetadata.questions.map((q) => q.options[0]).some((el) => el.id === r.optionId)
return isYesOption ? c + r.count : c
}, 0)
: 0
}
const totalVotes = useMemo(() => getTotalVotes(), [votingRoundResults, votingRoundMetadata])
const generateProposalsResultsCsv = async () => {
if (votingRoundMetadata) {
setIsDownloadingProposalsCsv(true)
Expand Down Expand Up @@ -67,23 +73,11 @@ export const VoteResults = ({

return (
<div>
<div className="mb-4">
<Link to="/" className="no-underline text-gray-600 hover:underline">
<Typography>&#60; Back to Voting sessions</Typography>
</Link>
</div>
<div className="grid grid-cols-1 xl:grid-cols-3 gap-4">
<div className="col-span-1 xl:col-span-2">
<Typography variant="h3">{votingRoundMetadata?.title} - Results</Typography>
</div>
<div>
<VoteDetails
globalState={votingRoundGlobalState}
appId={votingRoundGlobalState.appId}
loading={isLoadingVotingRoundData}
roundMetadata={votingRoundMetadata}
/>
</div>
<div></div>
<div>
<VotingStats
isLoading={isLoadingVotingRoundData || isLoadingVotingRoundResults}
Expand Down Expand Up @@ -122,6 +116,8 @@ export const VoteResults = ({
link={question.metadata.link}
threshold={question.metadata.threshold}
ask={question.metadata.ask}
skipTags={true}
totalVotes={totalVotes}
votesTally={
question.options.length > 0 && optionIDsToCounts[question.options[0].id] ? optionIDsToCounts[question.options[0].id] : 0
}
Expand Down
7 changes: 1 addition & 6 deletions src/build-a-bull/src/features/vote/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ShuffleOnIcon from '@mui/icons-material/ShuffleOn'
import { Alert, Box, Button, Checkbox, IconButton, Link, Skeleton, Typography } from '@mui/material'
import clsx from 'clsx'
import { useEffect, useMemo, useState } from 'react'
import { Link as RouterLink, useNavigate, useParams } from 'react-router-dom'
import { useNavigate, useParams } from 'react-router-dom'
import { Question, VotingRoundMetadata, fetchVotingRoundMetadata } from '@/shared/IPFSGateway'
import {
TallyCounts,
Expand Down Expand Up @@ -316,11 +316,6 @@ function Vote({ sort: sortProp = 'none' }: { sort?: 'ascending' | 'descending' |

return (
<div>
<div className="mb-4">
<RouterLink to="/" className="no-underline text-gray-600 hover:underline">
<Typography>&#60; Back to events</Typography>
</RouterLink>
</div>
<div>
{error && (
<Alert className="max-w-xl mt-4 text-white bg-red font-semibold" icon={false}>
Expand Down
6 changes: 4 additions & 2 deletions src/build-a-bull/src/shared/ProposalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type ProposalCardProps = {
totalVotes?: number | undefined
hasClosed?: boolean
forcePass?: boolean
skipTags?: boolean
}

export const ProposalCard = ({
Expand All @@ -30,6 +31,7 @@ export const ProposalCard = ({
totalVotes = 0,
hasClosed = false,
forcePass = false,
skipTags = false,
}: ProposalCardProps) => {
// Handle collapse state
const [isOverflow, setIsOverflow] = useState(false)
Expand All @@ -51,8 +53,8 @@ export const ProposalCard = ({
<Paper elevation={0} className="p-5">
<div className="flex justify-between">
<div>
{hasPassed && <PassedChip />}
{hasClosed && !hasPassed && <DidNotPassChip />}
{hasPassed && !skipTags && <PassedChip />}
{hasClosed && !hasPassed && !skipTags && <DidNotPassChip />}
</div>
<div className="text-right">
<span className="hidden md:inline-block">
Expand Down

0 comments on commit ccea19e

Please sign in to comment.