Make some little improvements to the UI

This commit is contained in:
Chigozirim Igweamaka 2024-05-09 20:46:28 +01:00
parent 0f4bbddd96
commit 316d8c036b
6 changed files with 45 additions and 56 deletions

View file

@ -1,15 +1,16 @@
import React, { useRef } from "react"; import React, { useEffect, useRef } from "react";
import YouTube from "react-youtube"; import YouTube from "react-youtube";
import styles from "./styles/CarouselSliders.module.css"; import styles from "./styles/CarouselSliders.module.css";
const CarouselSliders = (props) => { const CarouselSliders = (props) => {
const [activeIdx, setActiveIdx] = React.useState(0); const [activeVideoID, setActiveVideoID] = React.useState(null);
const players = useRef({}); const players = useRef({});
const opts = { const activeVid = props.matches.length ? props.matches[0].YouTubeID : "";
// width: "420",
// height: "210", useEffect(() => {
}; setActiveVideoID(activeVid);
}, [props.matches]);
const onReady = (event, videoId) => { const onReady = (event, videoId) => {
players.current[videoId] = event.target; players.current[videoId] = event.target;
@ -17,6 +18,8 @@ const CarouselSliders = (props) => {
const onPlay = (event) => { const onPlay = (event) => {
const videoId = event.target.getVideoData().video_id; const videoId = event.target.getVideoData().video_id;
setActiveVideoID(videoId);
// Pause other videos // Pause other videos
Object.values(players.current).forEach((player) => { Object.values(players.current).forEach((player) => {
const otherVideoId = player.getVideoData().video_id; const otherVideoId = player.getVideoData().video_id;
@ -35,24 +38,21 @@ const CarouselSliders = (props) => {
{!props.matches.length ? null : ( {!props.matches.length ? null : (
<div className={styles.Slider}> <div className={styles.Slider}>
{props.matches.map((match, index) => { {props.matches.map((match, index) => {
const [h, m, s] = match.timestamp.split(":"); const start = (parseInt(match.Timestamp) / 1000) | 0;
const timestamp =
parseInt(h, 10) * 360 + parseInt(m, 10) * 60 + parseInt(s, 10);
return ( return (
<div <div
key={index} key={index}
id={`slide-${index}`} id={`slide-${match.YouTubeID}`}
className={styles.SlideItem} className={styles.SlideItem}
> >
<YouTube <YouTube
videoId={match.youtubeid} videoId={match.YouTubeID}
opts={{ opts={{
...opts, playerVars: { start: start, rel: 0 },
playerVars: { start: timestamp, rel: 0 },
}} }}
iframeClassName={styles.Iframe} iframeClassName={styles.Iframe}
onReady={(event) => onReady(event, match.youtubeid)} onReady={(event) => onReady(event, match.YouTubeID)}
onPlay={onPlay} onPlay={onPlay}
/> />
</div> </div>
@ -62,18 +62,18 @@ const CarouselSliders = (props) => {
)} )}
<div className={styles.Circles}> <div className={styles.Circles}>
{props.matches.map((_, index) => { {props.matches.map((match, _) => {
return ( return (
<a <a
key={index} key={match.YouTubeID}
className={ className={
index !== activeIdx match.YouTubeID !== activeVideoID
? styles.Link ? styles.Link
: `${styles.Link} ${styles.ActiveLink}` : `${styles.Link} ${styles.ActiveLink}`
} }
href={`#slide-${index}`} href={`#slide-${match.YouTubeID}`}
onClick={() => { onClick={() => {
setActiveIdx(index); setActiveVideoID(match.YouTubeID);
}} }}
></a> ></a>
); );

View file

@ -17,13 +17,11 @@ const Form = ({ socket }) => {
} }
socket.emit("newDownload", spotifyUrl); socket.emit("newDownload", spotifyUrl);
console.log("newDownload: ", spotifyUrl);
setFormState(initialState); setFormState(initialState);
}; };
const spotifyURLisValid = (url) => { const spotifyURLisValid = (url) => {
if (url.length === 0) { if (url.length === 0) {
console.log("Spotify URL required");
return false; return false;
} }

View file

@ -14,7 +14,7 @@ const ListenButton = ({ isListening, onClick, disable }) => {
: `${styles.ListenButton} ${styles.Enabled}` : `${styles.ListenButton} ${styles.Enabled}`
} }
> >
{disable ? "Loading..." : isListening ? "Listening..." : "Listen"} {isListening ? "Listening..." : "Listen"}
</button> </button>
); );
}; };

View file

@ -3,14 +3,12 @@
} }
.Slider { .Slider {
/* height: 90vmin; */
width: 100%;
/* background-color: #c1c1c1; */
display: flex; display: flex;
overscroll-behavior-inline: contain; overscroll-behavior-inline: contain;
scroll-snap-type: inline mandatory; scroll-snap-type: inline mandatory;
overflow-x: scroll; overflow-x: scroll;
scroll-behavior: smooth; scroll-behavior: smooth;
} }
.Slider::-webkit-scrollbar { .Slider::-webkit-scrollbar {
@ -35,7 +33,6 @@
height: 100%; height: 100%;
width: 100%; width: 100%;
margin-left: 20px; margin-left: 20px;
flex-grow: 1;
scroll-snap-align: center; scroll-snap-align: center;
} }
@ -43,21 +40,17 @@
.SlideItem:nth-child(2) { background-color: dodgerblue;} .SlideItem:nth-child(2) { background-color: dodgerblue;}
.SlideItem:nth-child(3) { background-color: greenyellow;} .SlideItem:nth-child(3) { background-color: greenyellow;}
.Iframe {
width: 500px;
height: 300px;
}
@media screen and (max-width: 500px) {
@media (min-width: 768px) {
.Iframe { .Iframe {
width: 420px; width: 450px;
height: 200px; height: 300px;
} }
}
.Slider {
overflow-x: hidden;
}
@media screen and (min-width: 768px) {
.Circles { .Circles {
display: flex; display: flex;
align-items: center; align-items: center;
@ -71,25 +64,10 @@
display: inline-block; display: inline-block;
border-radius: 50%; border-radius: 50%;
background-color: #c1c1c1; background-color: #c1c1c1;
transition: all 0.5s ease-in-out;
} }
.Link.ActiveLink { .Link.ActiveLink {
background-color: #6a0dad; background-color: #6a0dad;
} }
} }
@media screen and (max-width: 600px) {
.Iframe {
width: 820px;
height: 400px;
}
}
@media screen and (max-width: 700px) {
.Iframe {
width: 420px;
height: 210px;
}
/* .SlideItem {
width: 20;
} */
}

View file

@ -4,7 +4,7 @@ Form {
margin-bottom: 30px; margin-bottom: 30px;
display: flex; display: flex;
gap: 12px; gap: 12px;
align-items: end; align-items: flex-end;
justify-content: center; justify-content: center;
} }
@ -14,7 +14,7 @@ Form {
margin: auto; margin: auto;
display: flex; display: flex;
gap: 12px; gap: 12px;
align-items: end; align-items: flex-end;
justify-content: center; justify-content: center;
} }
} }

View file

@ -48,11 +48,24 @@ main {
} }
.App { .App {
width: 65%; width: 55%;
margin: auto; margin: auto;
padding-bottom: 20px; padding-bottom: 20px;
} }
.TopHeader {
display: flex;
justify-content: space-between;
align-items: center;
}
@media screen and (max-width: 600px) {
.App {
width: 80%;
}
}
.songs { .songs {
text-align: right; text-align: right;
} }