Skip to content

Commit

Permalink
level 199
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnaFYZ committed Aug 13, 2023
1 parent f472443 commit 3c67dc3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
26 changes: 19 additions & 7 deletions client/src/AddingItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,24 @@ export default function AddingItem({addVideo, id}) {

const handleSubmit = (e) => {
e.preventDefault();
addVideo(newVideo);
setNewVideo({
id: id + 1,
title: "",
url: "",
rating: 0,
});
const pattern =
/^(https?:\/\/)?(www\.)?youtube\.com\/watch\?v=([a-zA-Z0-9_-]{11})/;
const pattern2 =
/^(https?:\/\/)?(www\.)?youtube\.com\/embed\/[a-zA-Z0-9_-]{11}$/;
// https://www.youtube.com/embed/dQw4w9WgXcQ
if (pattern.test(newVideo.url) || pattern2.test(newVideo.url)) {
const time = new Date();
const formattedTime = time.toLocaleString();
addVideo({...newVideo, dateTime: formattedTime});
setNewVideo({
id: id + 1,
title: "",
url: "",
rating: 0,
});
} else {
alert("Not a valid YouTube URL");
}
};
return (
<div className="adding-item">
Expand All @@ -43,6 +54,7 @@ export default function AddingItem({addVideo, id}) {
<input
type="text"
name="title"
required
value={newVideo.title}
onChange={handleTitleChange}
></input>
Expand Down
7 changes: 7 additions & 0 deletions client/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ body {
margin-left: 3px;
}

.uploaded-time {
display: flex;
align-self: flex-end;
margin-top: 10px;
margin-bottom: 0;
}

.video-form {
background-color: #162232;
border-radius: 10px;
Expand Down
2 changes: 1 addition & 1 deletion client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function App() {
</header>
<AddingItem addVideo = {addVideo} id={videos.length}/>
<div className="video-container">
{videos.map((video) => (
{videos.sort((a, b) => b.rating - a.rating).map((video) => (
<Videocard
key={video.id}
video={video}
Expand Down
4 changes: 3 additions & 1 deletion client/src/Videocard.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ function Videocard({ video, onUpVote, onDownVote, onRemove }) {
Remove
</button>
</div>

</div>
<div className="uploaded-time">
Uploaded: {video.dateTime? video.dateTime : ""}
</div>
</div>
);
Expand Down

0 comments on commit 3c67dc3

Please sign in to comment.