Add OngoingVoteModal (#56)

This commit is contained in:
Maria Rushkova 2021-06-25 10:33:01 +02:00 committed by GitHub
parent ce1437a81b
commit 06cb8559d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 112 additions and 61 deletions

View File

@ -98,9 +98,10 @@ export const CardCommunity = ({ community, showRemoveButton }: CardCommunityProp
interface CardVoteProps { interface CardVoteProps {
community: CommunityDetail community: CommunityDetail
hideModalFunction?: (val: boolean) => void
} }
export const CardVote = ({ community }: CardVoteProps) => { export const CardVote = ({ community, hideModalFunction }: CardVoteProps) => {
const [showVoteModal, setShowVoteModal] = useState(false) const [showVoteModal, setShowVoteModal] = useState(false)
const [showConfirmModal, setShowConfirmModal] = useState(false) const [showConfirmModal, setShowConfirmModal] = useState(false)
@ -111,6 +112,13 @@ export const CardVote = ({ community }: CardVoteProps) => {
setShowVoteModal(false) setShowVoteModal(false)
} }
const hideConfirm = (val: boolean) => {
if (hideModalFunction) {
hideModalFunction(false)
}
setShowConfirmModal(val)
}
const vote = community.currentVoting const vote = community.currentVoting
if (!vote) { if (!vote) {
@ -125,6 +133,21 @@ export const CardVote = ({ community }: CardVoteProps) => {
return ( return (
<CardVoteBlock> <CardVoteBlock>
{showVoteModal && (
<Modal heading={`${vote?.type} ${community.name}?`} setShowModal={setShowVoteModal}>
<VoteModal
vote={vote}
selectedVote={selectedVoted}
availableAmount={65245346}
setShowConfirmModal={setNext}
/>{' '}
</Modal>
)}
{showConfirmModal && (
<Modal setShowModal={hideConfirm}>
<VoteConfirmModal community={community} selectedVote={selectedVoted} setShowModal={hideConfirm} />
</Modal>
)}
{winner ? ( {winner ? (
<CardHeadingEndedVote> <CardHeadingEndedVote>
SNT holders have decided{' '} SNT holders have decided{' '}
@ -133,6 +156,8 @@ export const CardVote = ({ community }: CardVoteProps) => {
</b>{' '} </b>{' '}
this community to the directory! this community to the directory!
</CardHeadingEndedVote> </CardHeadingEndedVote>
) : hideModalFunction ? (
<CardHeading />
) : ( ) : (
<CardHeading>{voteConstants.question}</CardHeading> <CardHeading>{voteConstants.question}</CardHeading>
)} )}
@ -145,21 +170,6 @@ export const CardVote = ({ community }: CardVoteProps) => {
</VoteBtnFinal> </VoteBtnFinal>
) : ( ) : (
<VotesBtns> <VotesBtns>
{showVoteModal && (
<Modal heading={`${vote?.type} ${community.name} ?`} setShowModal={setShowVoteModal}>
<VoteModal
vote={vote}
selectedVote={selectedVoted}
availableAmount={65245346}
setShowConfirmModal={setNext}
/>{' '}
</Modal>
)}
{showConfirmModal && (
<Modal setShowModal={setShowConfirmModal}>
<VoteConfirmModal community={community} selectedVote={selectedVoted} setShowModal={setNext} />
</Modal>
)}
<VoteBtn <VoteBtn
onClick={() => { onClick={() => {
setSelectedVoted(voteConstants.against) setSelectedVoted(voteConstants.against)
@ -184,9 +194,9 @@ export const CardVote = ({ community }: CardVoteProps) => {
} }
export const Card = styled.div` export const Card = styled.div`
margin: 20px;
display: flex; display: flex;
align-items: stretch; align-items: stretch;
margin: 20px;
` `
export const CardCommunityWrap = styled.div` export const CardCommunityWrap = styled.div`
width: 50%; width: 50%;
@ -195,6 +205,14 @@ export const CardCommunityWrap = styled.div`
box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.1); box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.1);
border-radius: 6px 0px 0px 6px; border-radius: 6px 0px 0px 6px;
` `
export const CardVoteWrap = styled.div`
width: 50%;
display: flex;
align-items: stretch;
padding: 24px 24px 32px;
box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.1);
border-radius: 6px 0px 0px 6px;
`
const CardInfoBlock = styled.div` const CardInfoBlock = styled.div`
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -278,16 +296,13 @@ export const CardLinks = styled.div`
` `
export const CardVoteBlock = styled.div` export const CardVoteBlock = styled.div`
width: 50%;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: space-between; justify-content: space-between;
padding: 24px 24px 32px; width: 100%;
box-shadow: 0px 2px 12px rgba(0, 0, 0, 0.15);
border-radius: 6px;
` `
const VotesBtns = styled.div` export const VotesBtns = styled.div`
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
width: 100%; width: 100%;

View File

@ -9,6 +9,7 @@ import { CommunityDetail } from '../../models/community'
import { Modal } from '../Modal' import { Modal } from '../Modal'
import { FeatureModal } from './FeatureModal' import { FeatureModal } from './FeatureModal'
import { VoteConfirmModal } from './VoteConfirmModal' import { VoteConfirmModal } from './VoteConfirmModal'
import { OngoingVote } from './OngoingVote'
interface CardFeatureProps { interface CardFeatureProps {
community: CommunityDetail community: CommunityDetail
@ -23,6 +24,7 @@ interface CardFeatureProps {
export const CardFeature = ({ community, heading, text, icon, sum, timeLeft, voting }: CardFeatureProps) => { export const CardFeature = ({ community, heading, text, icon, sum, timeLeft, voting }: CardFeatureProps) => {
const [showFeatureModal, setShowFeatureModal] = useState(false) const [showFeatureModal, setShowFeatureModal] = useState(false)
const [showConfirmModal, setShowConfirmModal] = useState(false) const [showConfirmModal, setShowConfirmModal] = useState(false)
const [showOngoingVote, setShowOngoingVote] = useState(false)
const setNewModal = (val: boolean) => { const setNewModal = (val: boolean) => {
setShowConfirmModal(val) setShowConfirmModal(val)
@ -33,7 +35,12 @@ export const CardFeature = ({ community, heading, text, icon, sum, timeLeft, vot
<CardVoteBlock style={{ backgroundColor: `${Colors.GrayLight}` }}> <CardVoteBlock style={{ backgroundColor: `${Colors.GrayLight}` }}>
<FeatureTop> <FeatureTop>
<CardHeading>{heading}</CardHeading> <CardHeading>{heading}</CardHeading>
{voting && <CardLinkFeature>Ongoing vote for removal</CardLinkFeature>} {voting && (
<div>
{showOngoingVote && <OngoingVote community={community} setShowOngoingVote={setShowOngoingVote} />}
<CardLinkFeature onClick={() => setShowOngoingVote(true)}>Ongoing vote for removal</CardLinkFeature>
</div>
)}
</FeatureTop> </FeatureTop>
<FeatureVote> <FeatureVote>

View File

@ -0,0 +1,22 @@
import React from 'react'
import { CommunityDetail } from '../../models/community'
import { CardVote, CardVoteBlock } from '../Card'
import { Modal } from '../Modal'
export interface OngoingVoteProps {
community: CommunityDetail
setShowOngoingVote: (show: boolean) => void
}
export function OngoingVote({ community, setShowOngoingVote }: OngoingVoteProps) {
const vote = community.currentVoting
if (!vote) {
return <CardVoteBlock />
}
return (
<Modal heading={`${vote?.type} ${community.name}?`} setShowModal={setShowOngoingVote}>
<CardVote community={community} hideModalFunction={setShowOngoingVote} />
</Modal>
)
}

View File

@ -43,7 +43,7 @@ export function VoteModal({ vote, selectedVote, availableAmount, setShowConfirmM
) )
} }
const CardProposing = styled.div` export const CardProposing = styled.div`
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;

View File

@ -1,5 +1,5 @@
import React, { useState } from 'react' import React, { useState } from 'react'
import { Card, CardCommunity, CardCommunityWrap } from '../Card' import { Card, CardCommunity, CardCommunityWrap, CardVoteWrap } from '../Card'
import { CardFeature } from '../card/CardFeature' import { CardFeature } from '../card/CardFeature'
import styled from 'styled-components' import styled from 'styled-components'
import { CommunityDetail, DirectorySortingEnum } from '../../models/community' import { CommunityDetail, DirectorySortingEnum } from '../../models/community'
@ -11,6 +11,7 @@ import { PageBar } from '../PageBar'
import { DirectorySortingOptions } from '../../constants/SortingOptions' import { DirectorySortingOptions } from '../../constants/SortingOptions'
import { SpinnerIcon } from '../../assets/animatedIcons/spinnerIcon' import { SpinnerIcon } from '../../assets/animatedIcons/spinnerIcon'
import { useConfig } from '../../providers/config' import { useConfig } from '../../providers/config'
import { Colors } from '../../constants/styles'
interface DirectoryCardProps { interface DirectoryCardProps {
community: CommunityDetail community: CommunityDetail
@ -31,15 +32,17 @@ function DirectoryCard({ community }: DirectoryCardProps) {
{' '} {' '}
<CardCommunity community={community} showRemoveButton={true} /> <CardCommunity community={community} showRemoveButton={true} />
</CardCommunityWrap> </CardCommunityWrap>
<CardFeature <CardVoteWrap style={{ backgroundColor: `${Colors.GrayLight}` }}>
community={community} <CardFeature
heading="Feature this community?" community={community}
text={timeLeft ? 'This community has to wait until it can be featured again' : 'Weekly Feature vote'} heading="Feature this community?"
icon={timeLeft ? '⏳' : '⭐'} text={timeLeft ? 'This community has to wait until it can be featured again' : 'Weekly Feature vote'}
sum={community.directoryInfo.featureVotes?.toNumber()} icon={timeLeft ? '⏳' : '⭐'}
voting={Boolean(community.currentVoting)} sum={community.directoryInfo.featureVotes?.toNumber()}
timeLeft={timeLeft} voting={Boolean(community.currentVoting)}
/> timeLeft={timeLeft}
/>
</CardVoteWrap>
</Card> </Card>
) )
} }

View File

@ -1,6 +1,6 @@
import React from 'react' import React from 'react'
import { CommunityDetail } from '../../models/community' import { CommunityDetail } from '../../models/community'
import { Card, CardCommunity, CardCommunityWrap, CardVote } from '../Card' import { Card, CardCommunity, CardCommunityWrap, CardVote, CardVoteWrap } from '../Card'
interface VotingCardProps { interface VotingCardProps {
community: CommunityDetail community: CommunityDetail
@ -12,8 +12,10 @@ export const VotingCard = ({ community }: VotingCardProps) => {
{' '} {' '}
<CardCommunity community={community} /> <CardCommunity community={community} />
</CardCommunityWrap> </CardCommunityWrap>
<CardVoteWrap>
<CardVote community={community} /> {' '}
<CardVote community={community} />
</CardVoteWrap>
</Card> </Card>
) )
} }

View File

@ -1,6 +1,6 @@
import React from 'react' import React from 'react'
import styled from 'styled-components' import styled from 'styled-components'
import { Card, CardCommunityWrap, CardLinks, CardVoteBlock } from '../Card' import { Card, CardCommunityWrap, CardLinks, CardVoteBlock, CardVoteWrap } from '../Card'
import { LinkExternal, LinkInternal } from '../Link' import { LinkExternal, LinkInternal } from '../Link'
import { Skeleton } from '../skeleton/Skeleton' import { Skeleton } from '../skeleton/Skeleton'
import { TagsSkeletonList } from '../skeleton/TagSkeleton' import { TagsSkeletonList } from '../skeleton/TagSkeleton'
@ -24,29 +24,31 @@ export const VotingCardSkeleton = () => {
<StyledInternalink>Voting history </StyledInternalink> <StyledInternalink>Voting history </StyledInternalink>
</CardLinks> </CardLinks>
</CardCommunityWrap> </CardCommunityWrap>
<CardVoteBlock> <CardVoteWrap>
<CardHeader> <CardVoteBlock>
<Skeleton width="50%" /> <CardHeader>
</CardHeader> <Skeleton width="50%" />
<Row> </CardHeader>
<div> <Row>
<span></span> <div>
<Skeleton width="90px" height="16px" /> <span></span>
</div> <Skeleton width="90px" height="16px" />
<div> </div>
<Skeleton width="43px" height="8px" /> <div>
</div> <Skeleton width="43px" height="8px" />
<div> </div>
<span></span> <div>
<Skeleton width="90px" height="16px" /> <span></span>
</div> <Skeleton width="90px" height="16px" />
</Row> </div>
<ProgressSkeleton /> </Row>
<ButtonsRow> <ProgressSkeleton />
<SkeletonButton /> <ButtonsRow>
<SkeletonButton /> <SkeletonButton />
</ButtonsRow> <SkeletonButton />
</CardVoteBlock> </ButtonsRow>
</CardVoteBlock>
</CardVoteWrap>
</Card> </Card>
) )
} }