Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/freeze voting #84

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 13 additions & 39 deletions src/Components/DOM/VoteStatusButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Skeleton from '@mui/material/Skeleton';

export default function VoteStatusButton({
user,
repo,
repoID,
issueID,
contributorID,
Expand All @@ -15,55 +14,30 @@ export default function VoteStatusButton({
socketEvents
}) {
const [voteStatusButton, setVoteStatusButton] = useState({
color: 'gray',
text: '?',
state: 'vote',
mergeableCodeHost: true
color: 'lightgreen',
text: 'vote'
});
const [voteTotals, setVoteTotals] = useState(0);

const { prData, loading } = useGetVotes(user, repoID, issueID, contributorID, side, socketEvents, clicked);

const buttonStyle = {
vote: ['lightgreen', 'vote'],
'pre-open': ['green', Math.floor(voteTotals) + '%'],
open: ['orchid', Math.floor(voteTotals) + '%'],
'pre-open': ['green', prData?.voteData?.voteTotals?.totalVotePercent + '%'],
open: ['orchid', prData?.voteData?.voteTotals?.totalVotePercent + '%'],
frozen: [
'#BFD4F2',
prData?.voteData?.voteTotals?.totalVotePercent > 0 ? prData?.voteData?.voteTotals?.totalVotePercent + '%' : 'vote'
],
conflict: ['orange', 'conflict'],
merge: ['darkorchid', 'merged'],
close: ['red', 'closed']
};

useEffect(() => {
if (!loading) {
let quorum = prData.voteData.voteTotals.quorum;
const totalVotes = prData.voteData.voteTotals.totalVotes;
const totalPossibleVotes = 1_000_000;
const voteTotals = (totalVotes / totalPossibleVotes) * 100 * (1 / quorum);
setVoteTotals(voteTotals);

let newState = {
color: 'lightgreen',
text: 'vote',
state: prData.state,
mergeableCodeHost: prData.mergeable
};

if (!prData.mergeable) {
newState.state = 'conflict';
} else if (voteTotals === 0) {
newState.state = 'vote';
newState.color = 'lightgreen';
newState.text = 'vote';
newState.mergeableCodeHost = true;
} else {
const buttonColor = buttonStyle[prData.state][0];
const buttonText = buttonStyle[prData.state][1];
newState.color = buttonColor;
newState.text = buttonText;
newState.voteTotals = Math.floor(voteTotals);
}

setVoteStatusButton(newState);
const buttonColor = buttonStyle[prData.state][0];
const buttonText = buttonStyle[prData.state][1];
setVoteStatusButton({ color: buttonColor, text: buttonText });
}
}, [prData, loading, socketEvents]);

Expand All @@ -78,7 +52,7 @@ export default function VoteStatusButton({

return (
<Button style={{ color: 'white', background: voteStatusButton.color, width: '80px' }} onClick={e => handleClick(e)}>
{voteStatusButton.voteTotals < 100 ? voteStatusButton.voteTotals + '%' : voteStatusButton.text}
{voteStatusButton.text}
</Button>
);
}
3 changes: 2 additions & 1 deletion src/Components/Extension/Home/StatusBadge.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const statusMap = {
"new": ['#1ED61B', 'NEW'],
"conflict": ['#FF8A00', 'CONFLICT'],
"close": ['#D33131', 'CLOSED'],
"open": ['#FF6489', 'OPEN']
"open": ['#FF6489', 'OPEN'],
"frozen": ['#BFD4F2', 'FROZEN'],
};
const Wrapper = styled.div`
font-size: 10px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const Results = styled.div`
const SinglePullRequestView = ({ pullRequests, repo_id, repoID, title, votesArray, state, baseBranch, forkBranch, yesPercent, noPercent, createdAt, votePower, alreadyVoted, chosenSide, user, repo, githubToken, defaultHash, childDefaultHash, contributorID, owner, issueID, totalVotes }) => {
const quorum = 0.5;
const voteableStates = new Set(['vote', 'pre-open', 'open']);
const notVoteableStates = new Set(['conflict', 'merge', 'close']);
const notVoteableStates = new Set(['conflict', 'merge', 'close', 'frozen']);
const [disabled, setDisabled] = useState(false);
useEffect(() => {
if (voteableStates.has(state)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Modal/ModalVote.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const ModalVote = props => {
const [quorum, setQuorum] = useState(0.5);
const [userVotedAt, setUserVotedAt] = useState(''); //date
const voteableStates = new Set(['vote', 'pre-open', 'open']);
const notVoteableStates = new Set(['conflict', 'merge', 'close']);
const notVoteableStates = new Set(['conflict', 'merge', 'close', 'frozen']);
const [clickVoteHandler, setClickVoteHandler] = useState(false);
const socketEvents = props.socketEvents
useEffect(() => {
Expand Down
1 change: 1 addition & 0 deletions src/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ async function postGetRepoData(repo_id, contributor_id) {
owner,
contributor_id,
head,
inSession,
quorum,
contributor {
contributor_id,
Expand Down