-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #216 from ourzora/add-reasons-to-proposal
Add proposal votes
- Loading branch information
Showing
8 changed files
with
263 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
apps/web/src/modules/proposal/components/ProposalVotes/ProposalVotes.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Flex, Text } from '@zoralabs/zord' | ||
import { useMemo } from 'react' | ||
|
||
import { Proposal } from 'src/data/graphql/requests/proposalQuery' | ||
import { propPageWrapper } from 'src/styles/Proposals.css' | ||
|
||
import { VotePlacard } from './VotePlacard' | ||
|
||
export type ProposalVotesProps = { | ||
proposal: Proposal | ||
} | ||
|
||
export const ProposalVotes: React.FC<ProposalVotesProps> = ({ proposal }) => { | ||
const totalVotes = useMemo(() => { | ||
if (!proposal.votes) return 0 | ||
return proposal.votes.reduce((acc, vote) => acc + vote.weight, 0) | ||
}, [proposal.votes]) | ||
|
||
const hasVotes = proposal.votes?.length || 0 > 0 | ||
|
||
return ( | ||
<Flex className={propPageWrapper}> | ||
{hasVotes ? ( | ||
proposal.votes?.map((vote) => <VotePlacard vote={vote} totalVotes={totalVotes} />) | ||
) : ( | ||
<Text textAlign={'center'} color="text3" mt="x4"> | ||
No votes yet for this proposal. | ||
</Text> | ||
)} | ||
</Flex> | ||
) | ||
} |
146 changes: 146 additions & 0 deletions
146
apps/web/src/modules/proposal/components/ProposalVotes/VotePlacard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import { Flex, Grid, Text, atoms } from '@zoralabs/zord' | ||
import { AnimatePresence, motion } from 'framer-motion' | ||
import { useMemo, useState } from 'react' | ||
|
||
import { Avatar } from 'src/components/Avatar' | ||
import { ProposalVoteFragment, Support } from 'src/data/graphql/sdk.generated' | ||
import { useEnsData } from 'src/hooks' | ||
import { useLayoutStore } from 'src/stores' | ||
import { walletSnippet } from 'src/utils/helpers' | ||
|
||
const variants = { | ||
inital: { | ||
height: 0, | ||
overflow: 'hidden', | ||
transition: { | ||
animate: 'easeInOut', | ||
}, | ||
}, | ||
animate: { | ||
height: 'auto', | ||
transition: { | ||
animate: 'easeInOut', | ||
}, | ||
}, | ||
} | ||
|
||
export interface VotePlacardProps { | ||
vote: ProposalVoteFragment | ||
totalVotes: number | ||
} | ||
|
||
export const VotePlacard: React.FC<VotePlacardProps> = ({ vote, totalVotes }) => { | ||
const { ensName, ensAvatar } = useEnsData(vote.voter) | ||
const [open, setOpen] = useState(true) | ||
const { isMobile } = useLayoutStore() | ||
|
||
const supportStyle = useMemo(() => { | ||
const base = atoms({ | ||
borderStyle: 'solid', | ||
borderRadius: 'phat', | ||
borderWidth: 'thin', | ||
py: 'x1', | ||
px: 'x3', | ||
mr: 'x2', | ||
}) | ||
|
||
switch (vote.support) { | ||
case Support.For: | ||
return [base, atoms({ color: 'positive', borderColor: 'positiveDisabled' })] | ||
case Support.Against: | ||
return [base, atoms({ color: 'negative', borderColor: 'negativeDisabled' })] | ||
case Support.Abstain: | ||
return [base, atoms({ color: 'text3', borderColor: 'border' })] | ||
} | ||
}, [vote.support]) | ||
|
||
const votePercentage = ((100 * vote.weight) / totalVotes).toFixed(2) | ||
|
||
return ( | ||
<Grid | ||
as="button" | ||
onClick={() => (vote.reason ? setOpen((x) => !x) : null)} | ||
columns={7} | ||
gap={isMobile ? 'x1' : 'x0'} | ||
backgroundColor="background1" | ||
cursor={vote.reason ? 'pointer' : 'auto'} | ||
align={'center'} | ||
mb="x2" | ||
px={isMobile ? 'x2' : 'x6'} | ||
py="x6" | ||
color="text1" | ||
borderStyle="solid" | ||
borderColor="border" | ||
borderRadius="curved" | ||
w="100%" | ||
> | ||
<Text | ||
fontSize={isMobile ? 12 : 14} | ||
style={{ width: 'max-content' }} | ||
className={supportStyle} | ||
> | ||
{vote.support} | ||
</Text> | ||
<Flex align={'center'} style={{ gridColumn: 'span 4 / span 4' }}> | ||
<Avatar address={vote.voter} src={ensAvatar} size={isMobile ? '24' : '32'} /> | ||
<Text variant={isMobile ? 'label-sm' : 'label-md'} ml="x2"> | ||
{ensName || walletSnippet(vote.voter)} | ||
</Text> | ||
</Flex> | ||
|
||
<Flex | ||
align={'center'} | ||
style={{ gridColumn: 'span 2 / span 2', justifyContent: 'end' }} | ||
> | ||
<Text variant={isMobile ? 'label-sm' : 'label-md'} mr={isMobile ? 'x2' : 'x6'}> | ||
{vote.weight} {vote.weight === 1 ? 'Vote' : 'Votes'} | ||
</Text> | ||
{!isMobile && ( | ||
<Text | ||
style={{ fontWeight: 500 }} | ||
fontSize={12} | ||
borderStyle="solid" | ||
borderColor="border" | ||
color="text4" | ||
borderRadius="phat" | ||
py="x1" | ||
px="x2" | ||
> | ||
{votePercentage}% | ||
</Text> | ||
)} | ||
</Flex> | ||
|
||
<AnimatePresence initial={false}> | ||
{open && vote.reason && ( | ||
<motion.div | ||
variants={variants} | ||
initial={'inital'} | ||
animate={'animate'} | ||
exit={'inital'} | ||
style={{ | ||
gridColumn: isMobile ? 'span 7 / span 7' : '2 / span 6', | ||
}} | ||
> | ||
<Text | ||
variant={isMobile ? 'paragraph-sm' : 'paragraph-md'} | ||
borderRadius="curved" | ||
mt="x4" | ||
p="x6" | ||
textAlign={'left'} | ||
style={{ | ||
fontWeight: 400, | ||
whiteSpace: 'pre-wrap', | ||
wordBreak: 'break-word', | ||
minWidth: '80%', | ||
backgroundColor: '#F9F9F9', | ||
}} | ||
> | ||
{vote.reason} | ||
</Text> | ||
</motion.div> | ||
)} | ||
</AnimatePresence> | ||
</Grid> | ||
) | ||
} |
1 change: 1 addition & 0 deletions
1
apps/web/src/modules/proposal/components/ProposalVotes/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './ProposalVotes' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
0a71d81
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nouns-builder – ./apps/web
nouns-builder-git-main-ourzora.vercel.app
zouns-builder.vercel.app
www.nouns.build
nouns-builder-ourzora.vercel.app
nouns.build
0a71d81
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
testnet-nouns-builder – ./apps/web
testnet-nouns-builder-git-main-ourzora.vercel.app
testnet-nouns-builder-ourzora.vercel.app
testnet.nouns.build