Poll creation modal changes (#27)

This commit is contained in:
Maria Rushkova 2021-08-30 15:35:29 +02:00 committed by GitHub
parent f93cb82a2f
commit 3ad13cceaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 104 additions and 55 deletions

View File

@ -1,4 +1,4 @@
import React, { useState } from 'react' import React, { useEffect, useState } from 'react'
import { Wallet } from 'ethers' import { Wallet } from 'ethers'
import { JsonRpcSigner } from '@ethersproject/providers' import { JsonRpcSigner } from '@ethersproject/providers'
import styled from 'styled-components' import styled from 'styled-components'
@ -25,65 +25,100 @@ type PollCreationProps = {
export function PollCreation({ signer, wakuVoting, setShowPollCreation }: PollCreationProps) { export function PollCreation({ signer, wakuVoting, setShowPollCreation }: PollCreationProps) {
const [answers, setAnswers] = useState<string[]>(['', '']) const [answers, setAnswers] = useState<string[]>(['', ''])
const [question, setQuestion] = useState('') const [question, setQuestion] = useState('')
const [showCreateConfirmation, setShowCreateConfirmation] = useState(false)
const [selectedType, setSelectedType] = useState(PollType.NON_WEIGHTED) const [selectedType, setSelectedType] = useState(PollType.NON_WEIGHTED)
const [endTimePicker, setEndTimePicker] = useState(new Date(new Date().getTime() + 10000000)) const [endTimePicker, setEndTimePicker] = useState(new Date(new Date().getTime() + 10000000))
const body = document.getElementById('root')
useEffect(() => {
if (body) {
body.style.position = 'fixed'
return () => {
body.style.position = 'static'
}
}
}, [])
return ( return (
<NewPollBoxWrapper onClick={(e) => e.stopPropagation()}> <NewPollBoxWrapper
<NewPollBox> onClick={() => {
setShowPollCreation(false)
}}
>
<NewPollBox onClick={(e) => e.stopPropagation()}>
<NewPollBoxTitle> <NewPollBoxTitle>
Create a poll Create a poll
<CloseNewPollBoxButton onClick={() => setShowPollCreation(false)} /> <CloseNewPollBoxButton onClick={() => setShowPollCreation(false)} />
</NewPollBoxTitle> </NewPollBoxTitle>
<PollForm> {!showCreateConfirmation && (
<Input <PollForm>
label={'Question or title of the poll'} <Input
placeholder={'E.g. What is your favourite color?'} label={'Question or title of the poll'}
value={question} placeholder={'E.g. What is your favourite color?'}
onChange={(e) => setQuestion(e.target.value)} value={question}
/> onChange={(e) => setQuestion(e.target.value)}
/>
<AnswersWraper> <AnswersWraper>
{answers.map((answer, idx) => ( {answers.map((answer, idx) => (
<Input <Input
key={idx} key={idx}
label={`Option ${idx + 1}`} label={`Option ${idx + 1}`}
value={answer} value={answer}
onChange={(e) => onChange={(e) =>
setAnswers((answers) => { setAnswers((answers) => {
const newAnswers = [...answers] const newAnswers = [...answers]
newAnswers[idx] = e.target.value newAnswers[idx] = e.target.value
return newAnswers return newAnswers
}) })
} }
/> />
))} ))}
</AnswersWraper> </AnswersWraper>
<NewOptionButton <NewOptionButton
onClick={(e) => { onClick={(e) => {
e.preventDefault() e.preventDefault()
setAnswers((answers) => [...answers, '']) setAnswers((answers) => [...answers, ''])
}} }}
> >
Add another option Add another option
</NewOptionButton> </NewOptionButton>
<SmallButton <SmallButton
onClick={async (e) => { onClick={async (e) => {
e.preventDefault() e.preventDefault()
await wakuVoting?.createTimedPoll( await wakuVoting?.createTimedPoll(
signer, signer,
question, question,
answers, answers,
selectedType, selectedType,
undefined, undefined,
endTimePicker.getTime() endTimePicker.getTime()
) )
setShowPollCreation(false) setShowCreateConfirmation(true)
}} }}
> >
Create a poll Create a poll
</SmallButton> </SmallButton>
</PollForm> </PollForm>
)}
{showCreateConfirmation && (
<Confirmation>
<ConfirmationText>
Your poll has been created!
<br />
It will appear at the top of the poll list.
</ConfirmationText>
<SmallButton
onClick={(e) => {
e.preventDefault()
setShowPollCreation(false)
}}
>
Close
</SmallButton>
</Confirmation>
)}
</NewPollBox> </NewPollBox>
</NewPollBoxWrapper> </NewPollBoxWrapper>
) )
@ -156,16 +191,20 @@ const NewPollBox = styled.div`
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: space-between; justify-content: space-between;
width: 468px;
max-height: 90vh;
background-color: white; background-color: white;
margin: 20vh auto 2vh;
padding: 24px 24px 32px; padding: 24px 24px 32px;
box-shadow: 10px 10px 31px -2px #a3a1a1; box-shadow: 10px 10px 31px -2px #a3a1a1;
border-radius: 5px; border-radius: 5px;
overflow: auto; overflow: scroll;
z-index: 9998; z-index: 9998;
width: 468px; width: 468px;
@media (max-width: 600px) { @media (max-width: 600px) {
padding: 16px 16px 32px; padding: 16px 16px 32px;
margin: 0;
} }
` `
@ -175,16 +214,16 @@ const NewPollBoxWrapper = styled.div`
position: fixed; position: fixed;
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: flex-start;
top: 0; top: 0;
left: 0; left: 0;
background-color: rgba(0, 0, 0, 0.4); background-color: rgba(0, 0, 0, 0.4);
z-index: 9999; z-index: 9999;
transition: all 0.3s; transition: all 0.3s;
overflow: auto;
@media (max-width: 600px) { @media (max-width: 600px) {
padding: 16px; padding: 16px;
align-items: center;
} }
` `
const PollForm = styled.form` const PollForm = styled.form`
@ -194,3 +233,13 @@ const PollForm = styled.form`
font-size: 15px; font-size: 15px;
line-height: 22px; line-height: 22px;
` `
const Confirmation = styled.div`
display: flex;
flex-direction: column;
align-items: center;
`
const ConfirmationText = styled.div`
text-align: center;
margin: 32px 0;
`

View File

@ -21,7 +21,7 @@ function WakuPolling({ appName, signer }: WakuPollingProps) {
}, []) }, [])
return ( return (
<Wrapper onClick={() => showPollCreation && setShowPollCreation(false)}> <Wrapper>
{showPollCreation && signer && ( {showPollCreation && signer && (
<PollCreation signer={signer} wakuVoting={wakuVoting} setShowPollCreation={setShowPollCreation} /> <PollCreation signer={signer} wakuVoting={wakuVoting} setShowPollCreation={setShowPollCreation} />
)} )}