|
@@ -295,24 +295,25 @@ const Watch = ({ seconds }) => {
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
-const TimerContainerReset = ({ seconds, refresh, render }) => {
|
|
|
|
|
|
+const TimerContainerReset = ({ refresh, render, controls, onClick }) => {
|
|
//Начальные значения состояний
|
|
//Начальные значения состояний
|
|
- const initialState = { resBtn: true, startBtn: false, inCount: seconds }
|
|
|
|
|
|
+ const initialState = { resBtn: true, startBtn: false, inCount: 0 }
|
|
//Состояние таймера
|
|
//Состояние таймера
|
|
const [counter, setCounter] = useState(initialState.inCount);
|
|
const [counter, setCounter] = useState(initialState.inCount);
|
|
// Состояние кнопки Старта/Пауза
|
|
// Состояние кнопки Старта/Пауза
|
|
const [btnState, setBtnState] = useState(initialState.startBtn);
|
|
const [btnState, setBtnState] = useState(initialState.startBtn);
|
|
// Состояние кнопки сброса
|
|
// Состояние кнопки сброса
|
|
- const [btnResetState, setResetState] = useState(initialState.resBtn);
|
|
|
|
- let [hoursMod, minsMod, secsMod] = [Math.floor(counter / (60 * 60)), Math.floor(counter % (60 * 60) / 60), counter % (60 * 60) % 60];
|
|
|
|
|
|
+ // const [btnResetState, setResetState] = useState(initialState.resBtn);
|
|
|
|
+ // let [hoursMod, minsMod, secsMod] = [Math.floor(counter / (60 * 60)), Math.floor(counter % (60 * 60) / 60), counter % (60 * 60) % 60];
|
|
//Состояние инпутов
|
|
//Состояние инпутов
|
|
const [time, setTime] = useState({ hours: '', mins: '', secs: '' });
|
|
const [time, setTime] = useState({ hours: '', mins: '', secs: '' });
|
|
|
|
|
|
let [hoursPart, minsPart, secsPart] = [0, 0, 0];
|
|
let [hoursPart, minsPart, secsPart] = [0, 0, 0];
|
|
let t0;
|
|
let t0;
|
|
- const handleClick = () => { setBtnState(!btnState); setCounter(()=>handleCounter(time)) }
|
|
|
|
- function clearFunc({resBtn, startBtn, inCount }=initialState) {
|
|
|
|
- setResetState( resBtn );
|
|
|
|
|
|
+ const handleClick = () => { console.log(1); setBtnState(!btnState); setCounter(()=>handleCounter(time)) }
|
|
|
|
+ function clearFunc({startBtn, inCount } = initialState) {
|
|
|
|
+ // function clearFunc({resBtn, startBtn, inCount }=initialState) {
|
|
|
|
+ // setResetState( resBtn );
|
|
setBtnState( startBtn );
|
|
setBtnState( startBtn );
|
|
setCounter(inCount);
|
|
setCounter(inCount);
|
|
setTime({ hours:'', mins:'', secs:''});
|
|
setTime({ hours:'', mins:'', secs:''});
|
|
@@ -332,10 +333,14 @@ const TimerContainerReset = ({ seconds, refresh, render }) => {
|
|
return (!counter ? hoursPart + minsPart + secsPart : counter);
|
|
return (!counter ? hoursPart + minsPart + secsPart : counter);
|
|
};
|
|
};
|
|
// console.log(time);
|
|
// console.log(time);
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ useEffect(() => {
|
|
|
|
+
|
|
|
|
+ }, []);
|
|
let pauseState=counter;
|
|
let pauseState=counter;
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
- t0 = performance.now();
|
|
|
|
|
|
+ t0 = performance.now();
|
|
|
|
+
|
|
let interval;
|
|
let interval;
|
|
(pauseState*1000 <= refresh) && (pauseState=initialState.inCount);
|
|
(pauseState*1000 <= refresh) && (pauseState=initialState.inCount);
|
|
setCounter(pauseState);
|
|
setCounter(pauseState);
|
|
@@ -350,15 +355,16 @@ const TimerContainerReset = ({ seconds, refresh, render }) => {
|
|
return () => {clearInterval(interval) }
|
|
return () => {clearInterval(interval) }
|
|
}, [btnState]);
|
|
}, [btnState]);
|
|
const Render = (props) => { return render(props) };
|
|
const Render = (props) => { return render(props) };
|
|
|
|
+ // const Controls = (props) => { return controls(props )};
|
|
pauseState = counter;
|
|
pauseState = counter;
|
|
return <> <Render seconds={counter.toFixed(2)} />
|
|
return <> <Render seconds={counter.toFixed(2)} />
|
|
- <TimerControlInput counter={counter} handleUserInput={handleUserInput} time={time} handleClick={handleClick} clearFunc={clearFunc} btnState={btnState} />
|
|
|
|
-
|
|
|
|
|
|
+ {/* <Controls counter={counter} handleUserInput={handleUserInput} time={time} handleClick={handleClick} clearFunc={clearFunc} btnState={btnState} /> */}
|
|
|
|
+ <TimerControl counter={counter} handleUserInput={handleUserInput} time={time} handleClick={handleClick} clearFunc={clearFunc} btnState={btnState} />
|
|
</>
|
|
</>
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
-const TimerControlInput = ({ counter, handleUserInput, time, handleClick, clearFunc, btnState}) => {
|
|
|
|
|
|
+const TimerControl = ({ counter, handleUserInput, time, handleClick, clearFunc, btnState }) => {
|
|
return <>
|
|
return <>
|
|
<div className='timerBoard ms'>
|
|
<div className='timerBoard ms'>
|
|
<input className="timeCell" name="inputHours" maxLength="2" disabled={!counter ? false : true} value={time.hours} placeholder="hh" onInput={e => { handleUserInput(e.target.value, 'hours') }} />
|
|
<input className="timeCell" name="inputHours" maxLength="2" disabled={!counter ? false : true} value={time.hours} placeholder="hh" onInput={e => { handleUserInput(e.target.value, 'hours') }} />
|
|
@@ -368,7 +374,8 @@ const TimerControlInput = ({ counter, handleUserInput, time, handleClick, clearF
|
|
<input className="timeCell" name="inputSecs" maxLength="2" disabled={!counter ? false : true} value={time.secs} placeholder="ss" onInput={e => {handleUserInput(e.target.value, 'secs') }}/>
|
|
<input className="timeCell" name="inputSecs" maxLength="2" disabled={!counter ? false : true} value={time.secs} placeholder="ss" onInput={e => {handleUserInput(e.target.value, 'secs') }}/>
|
|
</div>
|
|
</div>
|
|
<div className='controlsWrapper'>
|
|
<div className='controlsWrapper'>
|
|
- <button className='timerBtn' onClick={handleClick}> { btnState ? "Pause" : "Start"}</button>
|
|
|
|
|
|
+ {/* <button className='timerBtn' onClick={(e) => { console.log(e); handleClick() }}> { btnState ? "Pause" : "Start"}</button> */}
|
|
|
|
+ <button className='timerBtn' onClick={(e) => { console.log(e); handleClick() }}> { btnState ? "Pause" : "Start"}</button>
|
|
<button className='timerBtn' onClick={() => clearFunc() }> Reset</button>
|
|
<button className='timerBtn' onClick={() => clearFunc() }> Reset</button>
|
|
</div>
|
|
</div>
|
|
</>
|
|
</>
|
|
@@ -421,7 +428,7 @@ function App() {
|
|
<TimerContainer seconds={3467} refresh={50} render={Watch} />
|
|
<TimerContainer seconds={3467} refresh={50} render={Watch} />
|
|
</Section>
|
|
</Section>
|
|
<Section name='task-9 TimerControl + TimerContainer'>
|
|
<Section name='task-9 TimerControl + TimerContainer'>
|
|
- <TimerContainerReset seconds={0} refresh={50} render={LCD} getData={TimerControlInput } />
|
|
|
|
|
|
+ <TimerContainerReset refresh={50} render={LCD} controls={TimerControl } />
|
|
</Section>
|
|
</Section>
|
|
</div>
|
|
</div>
|
|
);
|
|
);
|