Created
October 10, 2022 08:13
-
-
Save PaulieScanlon/5fd5953371102ae37e34812b96617717 to your computer and use it in GitHub Desktop.
Adding the Interface
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
import React, { Fragment, useState } from 'react'; | |
... | |
const Page = () => { | |
... | |
- return | |
+ return ( | |
+ <section> | |
+ <div> | |
+ {!hasVoted ? ( | |
+ <Fragment> | |
+ {config.map((item, index) => { | |
+ const { name, id } = item; | |
+ return ( | |
+ <button key={index} onClick={() => handleClick(id)} disabled={isSubmitting || error}> | |
+ <span>{name}</span> | |
+ </button> | |
+ ); | |
+ })} | |
+ </Fragment> | |
+ ) : ( | |
+ <Fragment> | |
+ {results.data.map((result, index) => { | |
+ const { percent, isMax } = result; | |
+ const name = config[index].name; | |
+ return ( | |
+ <div key={index}> | |
+ <span | |
+ style={{ | |
+ backgroundColor: isMax ? 'blue' : 'gray', | |
+ width: `${percent}%` | |
+ }} | |
+ /> | |
+ <span>{name}</span> | |
+ <span>{`${percent}%`}</span> | |
+ </div> | |
+ ); | |
+ })} | |
+ </Fragment> | |
+ )} | |
+ </div> | |
+ {hasVoted ? <p>{`${results.total} votes`}</p> : null} | |
+ {error ? <p>{error.message}</p> : null} | |
+ </section> | |
+ ); | |
}; | |
export default Page; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment