import {useEffect, useState, useRef} from "react";
import React from 'react';
import './App.scss';
import ClockFace from './pics/ClockFace.png'
import ClockSec from './pics/ClockFace_S.png'
import ClockMin from './pics/ClockFace_M.png'
import ClockHour from './pics/ClockFace_H.png'
const Spoiler = ({header="+", open=true, children}) => {
const [open2, setOpen] = useState(open);
return(
<>
setOpen(open2===true?false:true)}>
{header}
{open2 && children}
>
)
}
const RangeInput = ({min=0, max=0}) => {
//const [min2, setMin] = useState(min);
//const [max2, setMax] = useState(max);
const [length, setLength] = useState(0);
return(
<>
max)?'red':'green'}}
onChange={e=>setLength(+e.target.value.length)} />
>
)
}
const PasswordConfirm = ({min=0}) => {
const [val, setVal] = useState('');
const [secVal, setSecVal] = useState('');
const [length, setLength] = useState(0);
return(
<>
{setVal(e.target.value); setLength(e.target.value.length)}}
style={{backgroundColor: length
{val}
>
)
}
const Timer = ({startSec, onDelete, c}) => {
const [sec, setSec] = useState(startSec);
const [stop, setStop] = useState(false);
const [add, setAdd] =useState(0);
const [min,setMin] = useState(0);
const [hour, setHour] = useState(0);
const [err, setErr] = useState('');
const [count, setCount] = useState(c);
useEffect(() => {
if(!stop) {
if(sec === 0) return;
const interval = setInterval(() => {
setSec(sec => sec - 1)
}, 1000)
return () => {
clearInterval(interval)
}
}
}, [stop, sec, add])
return (
{count}
{new Date(new Date().setHours(hour, min, sec)).toLocaleString().split (", ")[1]}
setAdd(+e.target.value)} placeholder='add' />
{err}
)
}
//доделать: как сделать чтобы count совподал с текущей позицией
const TimerControl = ({hours, minutes, seconds}) => {
const [timers, setTimers] = useState([]);
const [count, setCount] = useState(0);
let [h, setH] = useState(hours);
let [m, setM] = useState(minutes);
let [s, setS] = useState(seconds);
let item=0;
let res = (h * 3600) + (m * 60) + +s;
console.log(timers);
return (
<>
setH(+e.target.value)}/>
setM(+e.target.value)}/>
setS(+e.target.value)}/>
{timers.map(i => {setCount(count-1); setTimers(timers.filter(t=>t!==i));}}/>)}
>
)
}
const SecondsTimer = ({seconds}) => {seconds || 0}
const TimerContainer = ({seconds, refresh, render:Tag}) => {
const [count, setCount] = useState(seconds);
useEffect(()=>{
if(count<=0) return;
let interval = setInterval(()=>{
setCount(count=>count-1);
}, refresh)
return ()=> clearInterval(interval);
}, [count, refresh])
return(
<>
>
)
}
const Timer2 = ({startSec}) => {
return (
)
}
const TimerContainer2 = ({startSec, refresh, render:Tag}) => {
const [count, setCount] = useState(startSec);
useEffect(()=>{
if(count<=0) return;
let interval = setInterval(()=>{
setCount(count=>count-1);
}, refresh)
return ()=> clearInterval(interval);
}, [count, refresh])
return(
<>
0?(count<10?'0'+count:count):'00'}/>
>
)
}
const Watch = ({ seconds = 1000 }) =>
const TimerContainer3 = ({ seconds = 0, refresh = 10, render: Tag}) => {
const [time, setTime] = useState(seconds * 1000)
let [isPause, setIsPause] = useState(false)
useEffect(() => {
setTime(seconds * 1000)
}, [seconds])
useEffect(() => {
let interval = null
let now = performance.now()
if (time > 0) {
interval = setInterval(() => {
if(!isPause){
console.log('1:'+`${isPause}`)
time > 0 ? setTime(time => time - (performance.now() - now)) : clearInterval(interval)
}else{
console.log('2:'+`${isPause}`)
}
}, refresh)
}
return () => clearInterval(interval)
})
return (
0 ? time / 1000 : 0} />
)
}
const Timer_Control_Container = ({h=0, m=0, s=0, render:Tag, refresh=10}) => {
const [sec, setSec] = useState(s)
const [min, setMin] = useState(m)
const [hour, setHour] = useState(h)
const [work, setWork] = useState(null)
const [active, setActive] = useState(false)
return (
setHour(+e.target.value)}
/>
setMin(+e.target.value)}
/>
setSec(+e.target.value)}
/>
{active===false ? :
}
{work ? :
}
)
}
function App() {
return (
Spoiler
Заголовок} open>
Контент 1
лорем ипсум траливали и тп.
Контент 2
лорем ипсум траливали и тп.
RangeInput
PasswordConfirm
Timer
TimerControl
TimerContainer
LCD
Watch
);
}
export default App;