hrllo

parent 0a013cfe
import {useState} from "react" import {useRef, useState} from 'react'
import List from "../components/List/List"
import SendBtn from "../components/SendBtn/SendBtn"
import GuestForm from "../components/GuestForm/GuestForm"
import './App.scss' import './App.scss'
import Modal from "../components/Modal/Modal"
function App() { function App() {
const [guestList, setGuestList] = useState<string[]>(['John', 'Alibek', 'Tramp', 'Jose', 'Aida']) const [playList, setPlayList] = useState([
const [inComeList, setIncomeList] = useState<string[]>([]) {name: '/Imagine Dragons - Believer.mp3', duration: 600, author: 'Кто то'},
const [inpVal, setInpVal] = useState<string>('') {name: '/Imagine Dragons - Believer.mp3', duration: 600, author: 'Кто то'},
const [isModal, setIsModal] = useState<boolean>(false) {name: '/Imagine Dragons - Believer.mp3', duration: 600, author: 'Кто то'},
{name: '/Imagine Dragons - Believer.mp3', duration: 600, author: 'Кто то'},
const onChangeHandler = (e: React.FormEvent<HTMLInputElement>) => { {name: '/Imagine Dragons - Believer.mp3', duration: 600, author: 'Кто то'}
setInpVal(e.currentTarget.value) ])
setIsModal(false)
const auidoRef = useRef<HTMLAudioElement | null>(null)
const playHandler = () => {
auidoRef?.current?.play()
} }
const onSubmitHandler = (e: React.SyntheticEvent<HTMLFormElement>) => { const pauseHandler = () => {
e.preventDefault() auidoRef?.current?.pause()
if(inpVal === '') {
setIsModal(true)
} else {
setGuestList((prevState) => {
prevState.push(inpVal)
return prevState
})
}
} }
const onClickHandler = () => { console.log(auidoRef);
const copyGuestList = [...guestList]
const randomList = copyGuestList.filter(item => {
const random = Math.floor(Math.random() * 100)
if(random > 50) return item
})
setIncomeList(randomList)
}
const onDeleteHandler = (item: string) => {
const index = guestList.findIndex(str => str === item)
const copyGuestList = [...guestList]
copyGuestList.splice(index, 1)
setGuestList(copyGuestList)
}
return ( return (
<div className="App"> <div className="App">
<Modal show={isModal}/>
<div className="Lists">
<List
title="Список основных гостей"
list={guestList.reverse()}
onDelete={onDeleteHandler}
/>
<List
title="Список приглашенных гостей"
list={inComeList}
/>
</div>
<div className="Controllers"> <div style={{height: '10px', width: '40px', backgroundColor: 'white'}}>
<GuestForm
onChange={onChangeHandler}
onSubmit={onSubmitHandler}
value={inpVal}
/>
<SendBtn onClick={onClickHandler}/>
</div> </div>
<button onClick={playHandler}>Play</button>
<button onClick={pauseHandler}>Pause</button>
<audio controls style={{display: 'none'}} ref={auidoRef}>
<source src={playList[4].name} type="audio/mpeg" />
</audio>
</div> </div>
) )
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment