Skip to content

Commit

Permalink
Increase timer limit and add +5min option
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Fosco committed Dec 12, 2023
1 parent 3768a98 commit 34ef457
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 24 deletions.
1 change: 0 additions & 1 deletion examples/breakout-rooms/src/components/Timer/Timer.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
align-items: center;
gap: 0.5em;
padding-right: 0.5em;
border-right: 1px solid var(--indigo400);
}

.timer-display {
Expand Down
55 changes: 40 additions & 15 deletions examples/breakout-rooms/src/components/Timer/Timer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,20 @@ export const DEFAULT_MIN_TIME = convertTime(1, "milliseconds", "minutes");
/**
* 10 mins
*/
export const DEFAULT_MAX_TIME = convertTime(10, "milliseconds", "minutes");
export const DEFAULT_MAX_TIME = convertTime(90, "milliseconds", "minutes");
/**
* 15 seconds
* 30 seconds
*/
export const DEFAULT_STEP = convertTime(15, "milliseconds", "seconds");
export const DEFAULT_STEP = convertTime(30, "milliseconds", "seconds");
/**
* 5 mins
*/
export const BIG_STEP = convertTime(5, "milliseconds", "minutes");
/**
* 5 mins
*/
export const BIG_STEP_MAX_TIME = convertTime(86, "milliseconds", "minutes");


type Props = {
/**
Expand All @@ -46,6 +55,14 @@ type Props = {
* Inc/Dec step in milliseconds
*/
step?: number;
/**
* Inc/Dec step in milliseconds
*/
bigStep?: number;
/**
* Inc/Dec step in milliseconds
*/
bigStepMaxTime?: number;
/**
* Set chosen time in milliseconds
*/
Expand All @@ -57,6 +74,8 @@ export const Timer: React.FunctionComponent<Props> = ({
minTime = DEFAULT_MIN_TIME,
maxTime = DEFAULT_MAX_TIME,
step = DEFAULT_STEP,
bigStep = BIG_STEP,
bigStepMaxTime = BIG_STEP_MAX_TIME,
onSet,
}) => {
const [time, setTime] = React.useState<number>(defaultTime);
Expand All @@ -70,14 +89,18 @@ export const Timer: React.FunctionComponent<Props> = ({
setTime((time) => (time > minTime ? time - step : time));
};

const handleBigAdd = () => {
setTime((time) => (time <= bigStepMaxTime ? time + bigStep : time));
};

const handleSetTime = () => {
onSet(time);
setTimeChanged(true);
};

return (
<>
<DropdownMenu>
<DropdownMenu onClose={() => handleSetTime()}>
<DropdownMenu.Trigger asChild>
<Button variant="outline-prominent" rounded>
<Button.IconSlot>
Expand All @@ -92,8 +115,8 @@ export const Timer: React.FunctionComponent<Props> = ({
<div className="timer-container">
<div className="timer-control">
<Button
variant="outline-subtle"
size="small"
variant="solid-subtle"
size="medium"
rounded
disabled={time <= minTime}
onClick={() => handleDecrease()}
Expand All @@ -104,22 +127,24 @@ export const Timer: React.FunctionComponent<Props> = ({
<div className="timer-display">{formatDisplayTime(time)}</div>

<Button
variant="outline-subtle"
size="small"
variant="solid-subtle"
size="medium"
rounded
disabled={time >= maxTime}
onClick={() => handleAdd()}
>
<IconPlus />
</Button>
<Button
variant="solid-subtle"
size="medium"
rounded
disabled={time >= bigStepMaxTime}
onClick={() => handleBigAdd()}
>
+5m
</Button>
</div>
<button
className="button button-primary button-small"
type="button"
onClick={() => handleSetTime()}
>
Set
</button>
</div>
</DropdownMenu.Content>
</DropdownMenu>
Expand Down
17 changes: 9 additions & 8 deletions examples/breakout-rooms/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ export const formatTime = (
formattedValue = seconds / 60;
formattedUnit = "minutes";
}
if (formattedValue >= 60) {
formattedValue = formattedValue / 60;
formattedUnit = "hours";
}
if (formattedValue >= 24) {
formattedValue = formattedValue / 24;
formattedUnit = "days";
}
// Commented for possible future use
// if (formattedValue >= 60) {
// formattedValue = formattedValue / 60;
// formattedUnit = "hours";
// }
// if (formattedValue >= 24) {
// formattedValue = formattedValue / 24;
// formattedUnit = "days";
// }

return formatter.format(formattedValue, formattedUnit);
};
Expand Down

0 comments on commit 34ef457

Please sign in to comment.