Skip to content

Commit 520fe83

Browse files
Manage mobile when format time is 00:00
1 parent 17318aa commit 520fe83

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/components/countdowntimer/CountdownTimer.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useRef } from 'react';
22
import { IconButton, Grid, Switch, TextField, styled } from '@mui/material';
33
import { HighlightOff as HighlightOffIcon, Pause as PauseIcon, PlayArrow as PlayArrowIcon } from '@mui/icons-material';
4+
import moment from 'moment';
45
import { useAppDispatch, useAppSelector } from '../../store/hooks';
56
import * as countdownTimerActions from '../../store/actions/countdownTimerActions';
67
import {
@@ -58,15 +59,19 @@ const CountdownTimer = () : JSX.Element => {
5859
autoFocus={!isMobile}
5960
sx={{ flexGrow: '1' }}
6061
variant='outlined'
61-
label='timer (hh:mm:ss)'
62+
label={(isMobile) ? 'timer (HH:mm)' : 'timer (HH:mm:ss)'}
6263
disabled={!isEnabled || (isStarted && remainingTime !== '00:00:00')}
6364
type='time'
6465
value={remainingTime}
6566
size='small'
6667
InputLabelProps={{ shrink: true }}
6768
inputProps={{ step: '1' }}
6869
onChange={(e) => {
69-
dispatch(countdownTimerActions.setCountdownTimerInitialTime(e.target.value));
70+
const time = (isMobile && moment(e.target.value, 'HH:mm', true).isValid())
71+
? moment(`${e.target.value}:00`, 'HH:mm:ss').format('HH:mm:ss')
72+
: moment(`${e.target.value}`, 'HH:mm:ss').format('HH:mm:ss');
73+
74+
dispatch(countdownTimerActions.setCountdownTimerInitialTime(time));
7075
}}
7176
onKeyDown={(e) => {
7277
if (remainingTime !== '00:00:00') {

0 commit comments

Comments
 (0)