Skip to content

Commit

Permalink
refactor: remove unnecessary setting the timer again when pausing the…
Browse files Browse the repository at this point in the history
… timer
  • Loading branch information
Ben Willenbring committed Dec 15, 2023
1 parent 5f2b7a7 commit b53383f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
12 changes: 2 additions & 10 deletions packages/frontend/src/retro/components/dialogs/TimerDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function TimerDialog({
handleResumeTimer,
handleChangeTimer,
} = useRetroContext();
const { timerStatus, timerDuration } = retroState;
const { timerStatus } = retroState;
const isTimerRunning = timerStatus === TimerStatus.RUNNING;
const isTimerPaused = timerStatus === TimerStatus.PAUSED;
const isTimerStopped = timerStatus === TimerStatus.STOPPED;
Expand Down Expand Up @@ -98,15 +98,7 @@ export function TimerDialog({
</DialogContent>
<DialogActions>
<Button onClick={close}>Cancel</Button>
{isTimerRunning && (
<Button
onClick={() => {
handlePauseTimer(timerDuration);
}}
>
Pause
</Button>
)}
{isTimerRunning && <Button onClick={handlePauseTimer}>Pause</Button>}
{isTimerPaused && <Button onClick={handleResumeTimer}>Resume</Button>}
<CallToActionButton
onClick={isTimerStopped ? handleStartClick : handleStopClick}
Expand Down
6 changes: 3 additions & 3 deletions packages/frontend/src/retro/context/RetroContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export interface RetroContextValues {
handleAddToWaitingList: (payload: AddToWaitingListAction["payload"]) => void;
handleIsVotingEnabledChanged: (isEnabled: boolean) => void;
handleStartTimer: (duration: number) => void;
handlePauseTimer: (duration: number) => void;
handlePauseTimer: () => void;
handleChangeTimer: (duration: number) => void;
handleStopTimer: () => void;
handleResumeTimer: () => void;
Expand Down Expand Up @@ -233,8 +233,8 @@ export function RetroContextProvider(props: RetroContextProviderProps) {
dispatchAndBroadcast({ type: "START_TIMER", duration });
}

function handlePauseTimer(duration: StartTimerAction["duration"]) {
dispatchAndBroadcast({ type: "PAUSE_TIMER", duration });
function handlePauseTimer() {
dispatchAndBroadcast({ type: "PAUSE_TIMER" });
}

function handleStopTimer() {
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/retro/reducers/retroReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export const retroReducer = (state: RetroState, action: RetroAction): RetroState
return { ...state, timerDuration: 0, timerStatus: TimerStatus.STOPPED };
}
case "PAUSE_TIMER": {
return { ...state, timerDuration: action.duration, timerStatus: TimerStatus.PAUSED };
return { ...state, timerStatus: TimerStatus.PAUSED };
}
case "CHANGE_TIMER": {
return { ...state, timerDuration: action.duration };
Expand Down
4 changes: 3 additions & 1 deletion packages/frontend/src/retro/types/retroActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,15 @@ export interface StartTimerAction extends BaseAction {
type: "START_TIMER";
duration: number;
}

export interface PauseTimerAction extends BaseAction {
type: "PAUSE_TIMER";
duration: number;
}

export interface StopTimerAction extends BaseAction {
type: "STOP_TIMER";
}

export interface ChangeTimerAction extends BaseAction {
type: "CHANGE_TIMER";
duration: number;
Expand Down

0 comments on commit b53383f

Please sign in to comment.