This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function useInterval(callback, delay) { | |
| const savedCallback = useRef(); | |
| useEffect(() => { | |
| savedCallback.current = callback; | |
| }); | |
| useEffect(() => { | |
| function tick() { | |
| savedCallback.current(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function useCurrentTime(delay = 1000){ | |
| const [currentTime, setCurrentTime] = useState(moment()); | |
| useInterval(() => { | |
| setCurrentTime(moment()) | |
| }, delay) | |
| return currentTime; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function useCurrentTime(){ | |
| const [currentTime, setCurrentTime] = useState(moment()); | |
| return currentTime; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function useCurrentTime(){ | |
| const [currentTime, setCurrentTime] = useState(moment()); | |
| useInterval(() => { | |
| setCurrentTime(moment()) | |
| }), 1000) | |
| return currentTime; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function useCurrentTime(){ | |
| const [currentTime, setCurrentTime] = useState(moment()); | |
| useInterval(() => { | |
| setCurrentTime(moment()) | |
| }, 1000) | |
| return currentTime; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const CurrentTime = () => { | |
| const time = useCurrentTime(); | |
| return ( | |
| <Text> | |
| {time.format("HH : mm : ss")} | |
| </Text> | |
| ) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const shiftSlice = createSlice({ | |
| name: 'shifts', | |
| initialState: [], | |
| reducers: { | |
| startShift: state => [ | |
| ...state, | |
| { | |
| startTime: moment().valueOf(), | |
| endTime: moment() | |
| .add(DEFAULT_SHIFT_DURATION, 'h') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const shiftSlice = createSlice({ | |
| name: 'shifts', | |
| initialState: [], | |
| reducers: { | |
| startShift: state => [ | |
| ...state, | |
| { | |
| startTime: moment().valueOf(), | |
| endTime: moment() | |
| .add(DEFAULT_SHIFT_DURATION, 'h') |