Add tablet removal button (#100)

This commit is contained in:
Maria Rushkova 2021-07-13 10:53:23 +02:00 committed by GitHub
parent 43a7a4e131
commit d1fd8e04a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 30 deletions

View File

@ -1,21 +1,25 @@
import React, { useState } from 'react' import React, { useState } from 'react'
import styled from 'styled-components' import styled from 'styled-components'
import { Colors } from '../../constants/styles' import { Colors } from '../../constants/styles'
import { CommunityDetail } from '../../models/community' import { CommunityDetail, CurrentVoting } from '../../models/community'
import { LinkExternal, LinkInternal } from '../Link' import { LinkExternal, LinkInternal } from '../Link'
import { Modal } from '../Modal' import { Modal } from '../Modal'
import { VoteConfirmModal } from './VoteConfirmModal' import { VoteConfirmModal } from './VoteConfirmModal'
import binIcon from '../../assets/images/bin.svg' import binIcon from '../../assets/images/bin.svg'
import { RemoveModal } from './RemoveModal' import { RemoveModal } from './RemoveModal'
import { CardHeading } from '../Card' import { CardHeading } from '../Card'
import { useEthers } from '@usedapp/core'
interface CardCommunityProps { interface CardCommunityProps {
community: CommunityDetail community: CommunityDetail
showRemoveButton?: boolean showRemoveButton?: boolean
customHeading?: string customHeading?: string
currentVoting?: CurrentVoting
} }
export const CardCommunity = ({ community, showRemoveButton, customHeading }: CardCommunityProps) => { export const CardCommunity = ({ community, showRemoveButton, customHeading, currentVoting }: CardCommunityProps) => {
const { account } = useEthers()
const [showHistoryModal, setShowHistoryModal] = useState(false) const [showHistoryModal, setShowHistoryModal] = useState(false)
const [showRemoveModal, setShowRemoveModal] = useState(false) const [showRemoveModal, setShowRemoveModal] = useState(false)
const [showConfirmModal, setShowConfirmModal] = useState(false) const [showConfirmModal, setShowConfirmModal] = useState(false)
@ -76,7 +80,9 @@ export const CardCommunity = ({ community, showRemoveButton, customHeading }: Ca
<CommunityInfo> <CommunityInfo>
<CardTop> <CardTop>
<CardHeading>{customHeading ? customHeading : community.name}</CardHeading> <CardHeading>{customHeading ? customHeading : community.name}</CardHeading>
{community.directoryInfo && showRemoveButton && <RemoveBtn onClick={() => setShowRemoveModal(true)} />} {community.directoryInfo && showRemoveButton && !currentVoting && (
<RemoveBtn onClick={() => setShowRemoveModal(true)} disabled={!account} />
)}
</CardTop> </CardTop>
<CardText>{community.description}</CardText> <CardText>{community.description}</CardText>
<CardTags> <CardTags>
@ -162,9 +168,14 @@ const RemoveBtn = styled.button`
` `
const RemoveBtnMobile = styled(RemoveBtn)` const RemoveBtnMobile = styled(RemoveBtn)`
display: none;
@media (max-width: 768px) { @media (max-width: 768px) {
display: block; display: block;
margin-left: 0; margin-left: 0;
&:disabled {
filter: grayscale(1);
} }
` `

View File

@ -3,17 +3,15 @@ import styled from 'styled-components'
import { Colors, ColumnFlexDiv } from '../../constants/styles' import { Colors, ColumnFlexDiv } from '../../constants/styles'
import { addCommas } from '../../helpers/addCommas' import { addCommas } from '../../helpers/addCommas'
import { CardHeading, CardVoteBlock } from '../Card' import { CardHeading, CardVoteBlock } from '../Card'
import { CommunityDetail } from '../../models/community' import { CommunityDetail, CurrentVoting } 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' import { OngoingVote } from './OngoingVote'
import { useEthers } from '@usedapp/core' import { useEthers } from '@usedapp/core'
import { useContracts } from '../../hooks/useContracts'
import { useContractCall } from '@usedapp/core'
import { votingFromRoom } from '../../helpers/voting'
import { VoteSubmitButton } from './VoteSubmitButton' import { VoteSubmitButton } from './VoteSubmitButton'
import { VoteSendingBtn, VoteBtn } from '../Button' import { VoteSendingBtn, VoteBtn } from '../Button'
import { VotingRoom } from '../../models/smartContract'
interface CardFeatureProps { interface CardFeatureProps {
community: CommunityDetail community: CommunityDetail
@ -21,9 +19,11 @@ interface CardFeatureProps {
icon: string icon: string
sum?: number sum?: number
timeLeft?: string timeLeft?: string
currentVoting?: CurrentVoting
room?: VotingRoom
} }
export const CardFeature = ({ community, heading, icon, sum, timeLeft }: CardFeatureProps) => { export const CardFeature = ({ community, heading, icon, sum, timeLeft, currentVoting, room }: CardFeatureProps) => {
const { account } = useEthers() const { account } = useEthers()
const [showFeatureModal, setShowFeatureModal] = useState(false) const [showFeatureModal, setShowFeatureModal] = useState(false)
const [showConfirmModal, setShowConfirmModal] = useState(false) const [showConfirmModal, setShowConfirmModal] = useState(false)
@ -34,23 +34,6 @@ export const CardFeature = ({ community, heading, icon, sum, timeLeft }: CardFea
setShowFeatureModal(false) setShowFeatureModal(false)
} }
const { votingContract } = useContracts()
let votingRoom = useContractCall({
abi: votingContract.interface,
address: votingContract.address,
method: 'getCommunityVoting',
args: [community.publicKey],
}) as any
if (votingRoom && (votingRoom.roomNumber.toNumber() === 0 || votingRoom.finalized == true)) {
votingRoom = undefined
}
let currentVoting
if (votingRoom) {
currentVoting = votingFromRoom(votingRoom)
}
return ( return (
<CardVoteBlock style={{ backgroundColor: `${Colors.GrayLight}` }}> <CardVoteBlock style={{ backgroundColor: `${Colors.GrayLight}` }}>
<CardHeading style={{ fontWeight: timeLeft ? 'normal' : 'bold', fontSize: timeLeft ? '15px' : '17px' }}> <CardHeading style={{ fontWeight: timeLeft ? 'normal' : 'bold', fontSize: timeLeft ? '15px' : '17px' }}>
@ -84,11 +67,9 @@ export const CardFeature = ({ community, heading, icon, sum, timeLeft }: CardFea
</FeatureBtn> </FeatureBtn>
</div> </div>
{currentVoting && ( {currentVoting && room && (
<FeatureBottom> <FeatureBottom>
{showOngoingVote && ( {showOngoingVote && <OngoingVote community={community} setShowOngoingVote={setShowOngoingVote} room={room} />}
<OngoingVote community={community} setShowOngoingVote={setShowOngoingVote} room={votingRoom} />
)}
<VoteSendingBtn onClick={() => setShowOngoingVote(true)}>Removal vote in progress</VoteSendingBtn> <VoteSendingBtn onClick={() => setShowOngoingVote(true)}>Removal vote in progress</VoteSendingBtn>
{currentVoting && currentVoting.timeLeft > 0 && <VoteSubmitButton vote={currentVoting} />} {currentVoting && currentVoting.timeLeft > 0 && <VoteSubmitButton vote={currentVoting} />}
</FeatureBottom> </FeatureBottom>

View File

@ -14,6 +14,9 @@ import { useConfig } from '../../providers/config'
import { Colors } from '../../constants/styles' import { Colors } from '../../constants/styles'
import { WeeklyFeature } from '../WeeklyFeature' import { WeeklyFeature } from '../WeeklyFeature'
import { DirectoryCardSkeleton } from './DirectoryCardSkeleton' import { DirectoryCardSkeleton } from './DirectoryCardSkeleton'
import { useContracts } from '../../hooks/useContracts'
import { useContractCall } from '@usedapp/core'
import { votingFromRoom } from '../../helpers/voting'
interface DirectoryCardProps { interface DirectoryCardProps {
community: CommunityDetail community: CommunityDetail
@ -28,11 +31,28 @@ function DirectoryCard({ community }: DirectoryCardProps) {
timeLeft = `${community.directoryInfo.untilNextFeature / (3600 * 24 * 7)} weeks left` timeLeft = `${community.directoryInfo.untilNextFeature / (3600 * 24 * 7)} weeks left`
} }
const { votingContract } = useContracts()
let votingRoom = useContractCall({
abi: votingContract.interface,
address: votingContract.address,
method: 'getCommunityVoting',
args: [community.publicKey],
}) as any
if (votingRoom && (votingRoom.roomNumber.toNumber() === 0 || votingRoom.finalized == true)) {
votingRoom = undefined
}
let currentVoting
if (votingRoom) {
currentVoting = votingFromRoom(votingRoom)
}
return ( return (
<Card> <Card>
<CardCommunityWrap> <CardCommunityWrap>
&nbsp; &nbsp;
<CardCommunity community={community} showRemoveButton={true} /> <CardCommunity community={community} showRemoveButton={true} currentVoting={currentVoting} />
</CardCommunityWrap> </CardCommunityWrap>
<CardVoteWrap style={{ backgroundColor: `${Colors.GrayLight}` }}> <CardVoteWrap style={{ backgroundColor: `${Colors.GrayLight}` }}>
<CardFeature <CardFeature
@ -41,6 +61,8 @@ function DirectoryCard({ community }: DirectoryCardProps) {
icon={timeLeft ? '⏳' : '⭐'} icon={timeLeft ? '⏳' : '⭐'}
sum={community.directoryInfo.featureVotes?.toNumber()} sum={community.directoryInfo.featureVotes?.toNumber()}
timeLeft={timeLeft} timeLeft={timeLeft}
currentVoting={currentVoting}
room={votingRoom}
/> />
</CardVoteWrap> </CardVoteWrap>
</Card> </Card>