26
loading...
This website collects cookies to deliver better user experience
function App() {
return (
<div>
<NavBar />
<Switch>
<Route exact path = "/rank-songs">
<RankSongs />
</Route>
<Route exact path ="/live">
<Live />
</Route>
<Route exact path ="/moments">
<Moments />
</Route>
<Route exact path="/">
<Home />
</Route>
</Switch>
</div>
);
}
function randomLyric(array) {
let random = array[Math.floor(Math.random()*array.length)];
if (lyric !== random) {
setLyric(random);
} else {
randomLyric(array)
}
}
useEffect(() => randomLyric(lyricArray), []);
useEffect(() => {
setTimeout(() => randomLyric(lyricArray), 5000)
})
function onVote(e){
const voteClass = e.target.className;
const votedSong = e.target.parentElement.parentElement.id;
const currentIndex = rankedSongs.indexOf(votedSong);
const updatedSongs = [...rankedSongs];
if (voteClass === "up") {
if (currentIndex === 0) {
return updatedSongs;
} else {
[updatedSongs[currentIndex], updatedSongs[currentIndex - 1]] = [updatedSongs[currentIndex - 1], updatedSongs[currentIndex]];
}
} else {
if (currentIndex === 9) {
return updatedSongs;
} else {
[updatedSongs[currentIndex], updatedSongs[currentIndex + 1]] = [updatedSongs[currentIndex + 1], updatedSongs[currentIndex]];
}
}
setRankedSongs(updatedSongs);
}