journal.pl/src/pages/main.tsx

204 lines
5.2 KiB
TypeScript
Raw Normal View History

import React, {useState, useCallback, useRef} from 'react';
2022-11-27 17:45:32 +03:00
import { getFeatures } from '@ijl/cli';
2022-11-27 16:34:37 +03:00
import logo from '../assets/logo-white.svg';
import arrow from '../assets/36-arrow-right.svg';
2022-11-27 17:45:32 +03:00
import { Keyboard } from '../components/keyboard';
2022-11-27 16:34:37 +03:00
import {
MainWrapper,
InputElement,
InputLabel,
InputWrapper,
LogoImg,
ArrowImg,
IconButton,
StartWrapper,
StartI,
StartInput,
StartLabel,
2022-11-27 21:41:38 +03:00
HalfLine,
HideGroup,
Circle,
LineSvg,
2022-11-27 16:34:37 +03:00
} from './style';
2022-11-27 21:41:38 +03:00
import { socket } from "../socket";
2022-11-27 16:34:37 +03:00
2022-11-27 17:45:32 +03:00
const keyboardFeature = getFeatures('hub-video-start')?.keyboard;
2022-11-27 16:34:37 +03:00
const Input = ({ onStart }) => {
const [value, setValue] = useState('');
2022-11-27 17:45:32 +03:00
const [inFocuse, setInfocuse] = useState(false);
2022-11-27 16:34:37 +03:00
const handleChange = useCallback(event => {
setValue(event.target.value.toUpperCase())
}, [setValue]);
const handleSubmit = useCallback((event) => {
event.preventDefault();
if (value === 'SBER') {
onStart()
}
}, [value])
return (
2022-11-27 17:45:32 +03:00
<>
<form onSubmit={handleSubmit}>
<InputWrapper>
<InputLabel
htmlFor='input'
>
Ввод:
</InputLabel>
<InputElement
value={value}
onChange={handleChange}
onFocus={() => setInfocuse(true)}
id="input"
autoComplete="off"
/>
<IconButton type="submit">
<ArrowImg src={arrow} />
</IconButton>
</InputWrapper>
</form>
{keyboardFeature && inFocuse && (
<Keyboard onChange={setValue} />
)}
</>
2022-11-27 16:34:37 +03:00
)
}
2022-11-27 21:41:38 +03:00
export const Line = ({ hide, reverse, speed, delay, radius, progress, width, color }) => (
<LineSvg
delay={delay}
reverse={reverse}
animationSpeed={speed}
width={(radius * 2) + 20 + width}
height={(radius * 2) + 20 + width}
>
<HideGroup hide={hide} delay={delay}>
<Circle
percent={progress}
circumference={radius * 2 * Math.PI}
stroke={color}
strokeWidth={width}
fill="transparent"
r={radius}
cx={radius + 10 + width/2}
cy={radius + 10 + width/2}
/>
</HideGroup>
</LineSvg>
)
Line.defaultProps = {
reverse: false
}
2022-11-27 16:34:37 +03:00
const Start = () => {
2022-11-27 21:41:38 +03:00
// const socketRef = useRef({ sent: false });
const [sended, setSend] = useState(false);
const handleCheck = () => {
2022-11-27 21:41:38 +03:00
// if (!socketRef.current.sent) {
if (!sended) {
socket.emit('play')
2022-11-27 21:41:38 +03:00
// socketRef.current.sent = true
setSend(true)
}
}
2022-11-27 16:34:37 +03:00
return (
<StartWrapper>
2022-11-27 21:41:38 +03:00
<Line
hide={sended}
speed={24}
delay={3}
radius={122}
progress={2}
width={3}
reverse
color="white"
/>
<Line
hide={sended}
speed={12}
delay={9}
radius={122}
progress={2}
width={3}
color="white"
/>
<Line
hide={sended}
speed={53}
radius={220}
delay={6}
progress={22}
width={12}
color="#92de22"
/>
<Line
hide={sended}
speed={53}
radius={220}
delay={17.8}
progress={.5}
width={12}
color="#92de22"
/>
<Line
hide={sended}
speed={53}
radius={220}
delay={18.3}
progress={.2}
width={12}
color="#92de22"
/>
<Line
hide={sended}
speed={54}
radius={220}
delay={30}
progress={44}
width={15}
color="#92de22"
/>
<Line
hide={sended}
speed={12}
radius={120}
delay={0}
progress={13}
width={6}
color="white"
/>
2022-11-27 16:34:37 +03:00
<StartInput
id="check"
type="checkbox"
onChange={handleCheck}
2022-11-27 16:34:37 +03:00
/>
<StartLabel
htmlFor='check'
>
<StartI>СТАРТ</StartI>
</StartLabel>
</StartWrapper>
)
}
export const MainPage = () => {
const [showStart, setShowStart] = useState(false);
return (
<MainWrapper>
<LogoImg src={logo} />
2022-11-27 21:41:38 +03:00
<Start />
{/* {!showStart && <Input onStart={() => setShowStart(true)} />}
{showStart && <Start />} */}
2022-11-27 16:34:37 +03:00
</MainWrapper>
);
};