forked from softvar/enhanced-github
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
small optimization, need to do some more later
- Loading branch information
Showing
1 changed file
with
9 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,12 +28,14 @@ const IconImg = styled.img` | |
margin-top: 3px; | ||
`; | ||
|
||
const iconMap = { | ||
const getIconMap = (totalYesVotes, totalNoVotes, prState) => ({ | ||
visible: prState !== 'merge', | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
frozen: LockIcon, | ||
upvote: UpArrow, | ||
downvote: DownArrow | ||
}; | ||
let iconKey; | ||
'pre-open': totalYesVotes >= totalNoVotes ? UpArrow : DownArrow, | ||
open: totalYesVotes >= totalNoVotes ? UpArrow : DownArrow, | ||
merge: null | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jex441
|
||
}); | ||
|
||
|
||
export default function VoteStatusButton({ | ||
user, | ||
|
@@ -53,16 +55,7 @@ export default function VoteStatusButton({ | |
const { prData, loading } = useGetVotes(user, repoID, issueID, contributorID, side, socketEvents, clicked); | ||
const totalYesVotes = prData?.voteData?.voteTotals?.totalYesVotes; | ||
const totalNoVotes = prData?.voteData?.voteTotals?.totalNoVotes; | ||
|
||
if (prData?.state === 'frozen') { | ||
iconKey = 'frozen'; | ||
} else if ((prData?.state === 'pre-open' || prData?.state === 'open') && totalYesVotes >= totalNoVotes) { | ||
iconKey = 'upvote'; | ||
} else if ((prData?.state === 'pre-open' || prData?.state === 'open') && totalYesVotes < totalNoVotes) { | ||
iconKey = 'downvote'; | ||
} else { | ||
iconKey = null; | ||
} | ||
const iconMap = getIconMap(totalYesVotes, totalNoVotes, prData?.state); | ||
|
||
const buttonStyle = { | ||
vote: ['#61D25E', 'vote'], | ||
|
@@ -101,7 +94,7 @@ export default function VoteStatusButton({ | |
return ( | ||
<ButtonVote style={{ background: voteStatusButton.color }} onClick={e => handleClick(e)}> | ||
<SpanVote> | ||
{iconKey && <IconImg src={iconMap[iconKey]} alt={iconKey} />} | ||
{iconMap.visible && <IconImg src={iconMap[prData.state]} alt={prData.state} />} | ||
{voteStatusButton.text} | ||
</SpanVote> | ||
</ButtonVote> | ||
|
This looks a lot better. I am a little confused as to how this works exactly because isn't the icon not visible in other states as well? Here it looks like it's just not visible unless it's merge.
Maybe I'm not understanding correctly.