1- import { FormFields } from '../components/FormFields/FormFields' ;
21import { timerMachine , timerStates } from '@interval-timer/core' ;
32import { useMachine } from '@xstate/react' ;
43import * as React from 'react' ;
4+ import { StateValue } from 'xstate' ;
5+
56import { Counter } from '../components/Counter/Counter' ;
7+ import { FormFields } from '../components/FormFields/FormFields' ;
68import { useBeep } from '../hooks/useBeep' ;
79
10+ const getActiveTimeTotal = ( {
11+ breakInterval,
12+ prepareTime,
13+ value,
14+ workInterval,
15+ } : {
16+ value : StateValue ;
17+ breakInterval : Date ;
18+ workInterval : Date ;
19+ prepareTime : Date ;
20+ } ) => {
21+ if ( value === timerStates . WORK ) {
22+ return workInterval ;
23+ }
24+
25+ if ( value === timerStates . BREAK ) {
26+ return breakInterval ;
27+ }
28+
29+ return prepareTime ;
30+ } ;
31+
832export default function Home ( ) {
933 const { beepBreak, beepBreakLong, beepWork, beepWorkLong } = useBeep ( ) ;
1034 const [ state , send , service ] = useMachine ( timerMachine , {
@@ -72,15 +96,21 @@ export default function Home() {
7296 } ) ;
7397 } ;
7498
75- const { breakInterval, rounds, workInterval, timeLeft, roundsLeft } =
76- state . context ;
99+ const {
100+ breakInterval,
101+ rounds,
102+ workInterval,
103+ timeLeft,
104+ roundsLeft,
105+ prepareTime,
106+ } = state . context ;
77107
78108 return (
79109 < >
80110 < header />
81111 < main className = "flex-1" >
82112 < div className = "h-full flex flex-col items-stretch bg-blue-600" >
83- < div className = "flex flex-col justify-center flex-1 bg-white rounded-b-3xl" >
113+ < div className = "flex flex-col justify-center items-center flex-1 bg-white rounded-b-3xl" >
84114 { state . value === timerStates . STOPPED ? (
85115 < FormFields
86116 rounds = { rounds }
@@ -92,6 +122,12 @@ export default function Home() {
92122 > </ FormFields >
93123 ) : (
94124 < Counter
125+ timeTotal = { getActiveTimeTotal ( {
126+ breakInterval,
127+ prepareTime,
128+ value : state . value ,
129+ workInterval,
130+ } ) }
95131 timeLeft = { timeLeft }
96132 roundsLeft = { roundsLeft }
97133 rounds = { rounds }
0 commit comments