journal.pl/src/pages/main.tsx

242 lines
6.8 KiB
TypeScript
Raw Normal View History

2022-11-29 21:36:30 +03:00
import React, {useState, useCallback, useRef, useMemo} 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-28 16:14:05 +03:00
Svg,
CircleDiv,
2022-11-29 21:36:30 +03:00
FullScreenButton,
InputHolder,
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-29 21:36:30 +03:00
const fullScreenFeature = getFeatures('hub-video-start')?.fullScreen;
2022-11-27 17:45:32 +03:00
2022-11-27 16:34:37 +03:00
const Input = ({ onStart }) => {
const [value, setValue] = useState('');
2022-11-29 21:36:42 +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]);
2022-11-29 21:36:30 +03:00
const inputRef = useRef<HTMLInputElement>(null);
2022-11-27 16:34:37 +03:00
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)}
2022-11-29 21:36:30 +03:00
ref={inputRef}
onClick={(event) => {
event.preventDefault();
event.stopPropagation();
inputRef.current.blur();
}}
2022-11-27 17:45:32 +03:00
id="input"
autoComplete="off"
/>
2022-11-29 21:36:30 +03:00
<InputHolder onClick={() => setInfocuse(true)} />
2022-11-27 17:45:32 +03:00
<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 [sended, setSend] = useState(false);
const handleCheck = () => {
2022-11-27 21:41:38 +03:00
if (!sended) {
socket.emit('play')
2022-11-27 21:41:38 +03:00
setSend(true)
}
}
2022-11-27 16:34:37 +03:00
return (
<StartWrapper>
2022-11-28 16:14:05 +03:00
{/* <Svg
xmlns="http://www.w3.org/2000/svg"
width="1200"
height="1200"
viewBox="0 0 400 400">
<defs>
<linearGradient id="gradient" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset="50%" stop-color="#f7f7f720" />
<stop offset="100%" stop-color="#4aa9edca" />
</linearGradient>
</defs>
<circle cx="200" cy="-100" r="90" stroke="url(#gradient)" stroke-width="46" fill="none" transform='rotate(90 50 50)'/>
</Svg> */}
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>
2022-11-28 16:14:05 +03:00
<CircleDiv />
2022-11-27 16:34:37 +03:00
</StartWrapper>
)
}
export const MainPage = () => {
const [showStart, setShowStart] = useState(false);
2022-11-29 21:36:30 +03:00
const [isFull, setFull] = useState(false);
const handleFullScreen = useCallback(() => {
const elem = document.documentElement;
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.webkitRequestFullscreen) { /* Safari */
elem.webkitRequestFullscreen();
} else if (elem.msRequestFullscreen) { /* IE11 */
elem.msRequestFullscreen();
}
setFull(true);
}, []);
2022-11-27 16:34:37 +03:00
return (
<MainWrapper>
2022-11-29 21:36:30 +03:00
{fullScreenFeature && !isFull && <FullScreenButton onClick={handleFullScreen}>На весь экран</FullScreenButton>}
2022-11-27 16:34:37 +03:00
<LogoImg src={logo} />
2022-11-28 16:21:03 +03:00
{/* <Start /> */}
{!showStart && <Input onStart={() => setShowStart(true)} />}
{showStart && <Start />}
2022-11-27 16:34:37 +03:00
</MainWrapper>
);
};