Skip to content

Commit

Permalink
feat: add timer events in the retroContext
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Lehé committed Dec 5, 2023
1 parent aee32f5 commit 45e82a8
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
19 changes: 19 additions & 0 deletions packages/frontend/src/retro/context/RetroContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
RetroAction,
SetRetroStateAction,
SortCardsByVotesDescendingAction,
StartTimerAction,
ToggleCardDiscussedAction,
ToggleColumnBlurAction,
UnhighlightCardAction,
Expand Down Expand Up @@ -47,6 +48,9 @@ const initialState: RetroState = {
participants: {},
waitingList: {},
isVotingEnabled: false,
isTimerPaused: false,
isTimerRunning: false,
timerDuration: 0,
};

export interface RetroContextValues {
Expand Down Expand Up @@ -79,6 +83,9 @@ export interface RetroContextValues {
handleAcceptJoinUser: (userId: string) => void;
handleAddToWaitingList: (payload: AddToWaitingListAction["payload"]) => void;
handleIsVotingEnabledChanged: (isEnabled: boolean) => void;
handleStartTimer: (duration: number) => void;
handlePauseTimer: () => void;
handleStopTimer: () => void;
}

export const RetroContext = React.createContext<RetroContextValues>(undefined!);
Expand Down Expand Up @@ -221,6 +228,15 @@ export function RetroContextProvider(props: RetroContextProviderProps) {
dispatchAndBroadcast({ type: "IS_VOTING_ENABLED_CHANGED", isEnabled });
}

function handleStartTimer(duration: StartTimerAction["duration"]) {
dispatchAndBroadcast({ type: "START_TIMER", duration });
}
function handlePauseTimer() {
dispatchAndBroadcast({ type: "PAUSE_TIMER" });
}
function handleStopTimer() {
dispatchAndBroadcast({ type: "STOP_TIMER" });
}
const resetRetroState = useCallback(() => {
dispatch({ type: "SET_RETRO_STATE", payload: initialState });
}, []);
Expand Down Expand Up @@ -255,6 +271,9 @@ export function RetroContextProvider(props: RetroContextProviderProps) {
handleAcceptJoinUser: acceptJoinUser,
handleAddToWaitingList,
handleIsVotingEnabledChanged,
handleStartTimer,
handlePauseTimer,
handleStopTimer,
};

return <RetroContext.Provider value={value}>{props.children}</RetroContext.Provider>;
Expand Down
12 changes: 12 additions & 0 deletions packages/frontend/src/retro/reducers/retroReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,18 @@ export const retroReducer = (state: RetroState, action: RetroAction): RetroState
case "IS_VOTING_ENABLED_CHANGED": {
return { ...state, isVotingEnabled: action.isEnabled };
}
case "START_TIMER": {
console.log("START TIMER");
return { ...state, timerDuration: action.duration, isTimerRunning: true };
}
case "STOP_TIMER": {
console.log("STOP TIMER");
return { ...state, isTimerRunning: false };
}
case "PAUSE_TIMER": {
console.log("PAUSE TIMER");
return { ...state, isTimerPaused: false };
}
case "DISCONNECT": {
const { participants, waitingList } = state;
const disconnectedUserId = action.payload;
Expand Down
16 changes: 15 additions & 1 deletion packages/frontend/src/retro/types/retroActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ export interface IsVotingEnabledChangedAction extends BaseAction {
isEnabled: boolean;
}

export interface StartTimerAction extends BaseAction {
type: "START_TIMER";
duration: number;
}
export interface PauseTimerAction extends BaseAction {
type: "PAUSE_TIMER";
}
export interface StopTimerAction extends BaseAction {
type: "STOP_TIMER";
}

export type RetroAction =
| PeerToPeerAction<RetroState>
| CardUpvoteAction
Expand All @@ -115,4 +126,7 @@ export type RetroAction =
| ToggleCardDiscussedAction
| ChangeRetroFormatAction
| SortCardsByVotesDescendingAction
| IsVotingEnabledChangedAction;
| IsVotingEnabledChangedAction
| StartTimerAction
| PauseTimerAction
| StopTimerAction;
3 changes: 3 additions & 0 deletions packages/frontend/src/retro/types/retroTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export interface RetroState {
participants: UserByUserId;
waitingList: UserByUserId;
isVotingEnabled: boolean;
isTimerPaused: boolean;
isTimerRunning: boolean;
timerDuration: number;
}

export type VotesByUserId = Record<string, number>;
Expand Down

0 comments on commit 45e82a8

Please sign in to comment.