Skip to content

Commit

Permalink
fix display of votes
Browse files Browse the repository at this point in the history
  • Loading branch information
mateo-ivc committed Nov 11, 2024
1 parent 1848af3 commit 7de9f60
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/components/Votes/Votes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export const Votes: FC<VotesProps> = (props) => {

return voting || allPastVotes > 0 ? (
<div role="none" className={classNames("votes", props.className)} onClick={(e) => e.stopPropagation()}>
{/* standard display for votes */}
{!voting && allPastVotes > 0 && <VoteButtons.Remove noteId={props.noteId} numberOfVotes={allPastVotes} disabled />}
{/* display for votes when voting is open */}
{voting && ongoingVotes.note > 0 && <VoteButtons.Remove disabled={boardLocked && !isModerator} noteId={props.noteId} numberOfVotes={ongoingVotes.note} />}
{voting && (isModerator || !boardLocked) && (
<VoteButtons.Add noteId={props.noteId} disabled={ongoingVotes.total === voting.voteLimit || (ongoingVotes.note > 0 && !voting.allowMultipleVotes)} />
Expand Down
5 changes: 4 additions & 1 deletion src/store/features/votes/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import {createReducer} from "@reduxjs/toolkit";
import {VotesState} from "./types";
import {initializeBoard} from "../board";
import {createdVote, deletedVote, updatedVotes} from "./actions";
import {createdVoting, updatedVoting} from "../votings";

const initialState: VotesState = [];

export const votesReducer = createReducer(initialState, (builder) =>
builder
.addCase(initializeBoard, (_state, action) => action.payload.fullBoard.votes)
.addCase(createdVote, (state, action) => {
state.push(action.payload);
state.unshift(action.payload);
})
.addCase(updatedVoting, (_state, action) => action.payload.notes?.map((n) => ({voting: action.payload.voting.id, note: n.id})))
.addCase(updatedVotes, (_state, action) => action.payload)
.addCase(deletedVote, (state, action) => state.filter((v) => !(v.voting === action.payload.voting && v.note === action.payload.note)))
.addCase(createdVoting, () => [])
);
2 changes: 1 addition & 1 deletion src/store/features/votings/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ export const votingsReducer = createReducer(initialState, (builder) =>
})
.addCase(updatedVoting, (state, action) => {
state.open = undefined;
state.past.push(action.payload.voting);
state.past.unshift(action.payload.voting);
})
);

0 comments on commit 7de9f60

Please sign in to comment.