Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

London-10_Saqib-Javed_full-stack_level_100_200_300 #379

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
build
528 changes: 528 additions & 0 deletions client/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@testing-library/react": "^11.2.7",
"@testing-library/user-event": "^12.1.10",
"bootstrap": "^5.1.3",
"build": "^0.1.4",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "^5.0.0",
Expand Down
37 changes: 37 additions & 0 deletions client/src/App.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
.App {

text-align: center;
background-color: rgb(9, 12, 15);
color: azure;
}
h1{
font-family: fantasy;
}

.video-container{
padding: 150px auto;
margin: 50px;
font-family:fantasy;
}
.btn-del{
background-color: #f44336;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 12px;
}
.like, .dislike{
background-color: #555555;
color: white;
padding: 15px 32px;
margin:10px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 12px;
}

.footer{
color: orange;
font-size:small;
padding-bottom: 5px;
}
11 changes: 11 additions & 0 deletions client/src/App.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import "./App.css";
import React from 'react'
import Footer from "./Components/Footer";
import Videos from "./Components/Videos";


function App() {

return (
<div className="App">
<header className="App-header">
<h1>Video Recommendation</h1>
<div>
Copy link

@migmow migmow Sep 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI this component does not need to be wrapped in a <div>
but they do need to be wrapped in a single parent element which you did nicely (<div className="App">)

<Videos />
</div>
</header>
<Footer />
</div>
);
}

export default App;


14 changes: 14 additions & 0 deletions client/src/Components/Footer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from "react";


function Footer() {

return (
<div className="footer">
<p>Full Stack Assessment - created by Saqib Javed, London 10 CYF</p>
<p>Date: 18 August 2023</p>
</div>
);
}

export default Footer;
60 changes: 60 additions & 0 deletions client/src/Components/NewVideo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React, { useState } from "react";

function NewVideo(props) {


const [title, setTitle] = useState("");
const [url, setUrl] = useState("");
// const [newVideo, SetNewVideo] = useState({ title: "", url: "" });

const handleSubmit = (e) => {
e.preventDefault();
if (title && url) {

let updatedValue = {
title: title,
url: url,
id: Date.now(),
rating: 0,
};

props.onAddNewVideo(updatedValue)
setTitle("")
setUrl("")
}
};

return (
<div className="new-video">
<p>Add new video to your list</p>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using an <h3> element is also a good choice for the title or heading of a section.

<form className="form">
<label>
Title:{" "}
<input
type="text"
placeholder="enter title"
value={title}
onChange={(e) => setTitle(e.target.value)}
required
/>
</label>{" "}
<br></br>
<label>
URL:{" "}
<input
type="url"
placeholder="enter url address"
value={url}
onChange={(e) => setUrl(e.target.value)}
required
/>
</label>
<br></br>
<button type="submit" onClick={handleSubmit}>
Submit Video{" "}
</button>
</form>
</div>
);
}
export default NewVideo;
50 changes: 50 additions & 0 deletions client/src/Components/VideoCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React, { useState } from "react";


function VideoCard(props) {

const {video, handleDelete} = props
const [rating, setRating] = useState(video.rating);

function like() {
setRating(rating + 1);
}

function dislike() {
setRating(rating - 1);
}

return (
<div>

<div></div>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also you don't need this line I guess.

<div key={video.id}>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key prop should be applied to the outermost element that is part of a list of elements. In your case, it should be applied to the outer <div> that wraps each video card, not the inner div.
FYI this is important for React to efficiently update the component list.

<p>{video.title}</p>
<iframe
width="600"
height="400"
src={video.url.replace("watch?v=", "embed/")}
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
title="Youtube Videos"
allowFullScreen
/>
<p>RATINGS: {rating}</p>
<div>
<button onClick={like} className="like">
Like 👍🏼{" "}
</button>
<button onClick={dislike} className="dislike">
Dislike 👎🏻{" "}
</button>
<button className="btn-del" onClick={() => handleDelete(video.id)}>
Delete 🗑️
</button>
</div>
<hr></hr>
</div>
</div>
);
}


export default VideoCard;
65 changes: 65 additions & 0 deletions client/src/Components/Videos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import React, { useState, useEffect } from "react";
// import videosData from "./exampleresponse.json";
import VideoCard from "./VideoCard";
import NewVideo from "./NewVideo";

function Videos({ newVideos, handleSubmit }) {
const [videos, setVideos] = useState([]);

const url = "https://fullstack-backend-qwia.onrender.com/videos";

const getTheVideos = async () => {
try {
const res = await fetch(url);
const data = await res.json();
setVideos(data);

} catch (err) {
console.error(err.message);
}
}
useEffect(() => {
getTheVideos();
}, [])




const handleDelete = (id) => {
setVideos((prevVideosData) =>
prevVideosData.filter((video) => video.id !== id)
);
};

const addVideos = (video) => {
console.log("this is video", video);
setVideos([video, ...videos]);
console.log("in add videos", videos);
};
Copy link

@migmow migmow Sep 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job in using spread operator! can you also remove unused codes in your PR? console.logs


return (
<div>
<NewVideo
onAddNewVideo={addVideos}
/>
<div className="video-container">
{videos &&
videos
.sort((a, b) => b.rating - a.rating)
.map((video) => {
return (
<VideoCard
key={video.id}
video={video}
handleDelete={handleDelete}
newVideos={newVideos}
handleSubmit={handleSubmit}
/>
);
})}
</div>
</div>
);
}

export default Videos;
62 changes: 62 additions & 0 deletions client/src/Components/exampleresponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[
{
"id": 523523,
"title": "Never Gonna Give You Up",
"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
"rating": 23
},
{
"id": 523427,
"title": "The Coding Train",
"url": "https://www.youtube.com/watch?v=HerCR8bw_GE",
"rating": 230
},
{
"id": 82653,
"title": "Mac & Cheese | Basics with Babish",
"url": "https://www.youtube.com/watch?v=FUeyrEN14Rk",
"rating": 2111
},
{
"id": 858566,
"title": "Videos for Cats to Watch - 8 Hour Bird Bonanza",
"url": "https://www.youtube.com/watch?v=xbs7FT7dXYc",
"rating": 11
},
{
"id": 453538,
"title": "The Complete London 2012 Opening Ceremony | London 2012 Olympic Games",
"url": "https://www.youtube.com/watch?v=4As0e4de-rI",
"rating": 3211
},
{
"id": 283634,
"title": "Learn Unity - Beginner's Game Development Course",
"url": "https://www.youtube.com/watch?v=gB1F9G0JXOo",
"rating": 211
},
{
"id": 562824,
"title": "Cracking Enigma in 2021 - Computerphile",
"url": "https://www.youtube.com/watch?v=RzWB5jL5RX0",
"rating": 111
},
{
"id": 442452,
"title": "Coding Adventure: Chess AI",
"url": "https://www.youtube.com/watch?v=U4ogK0MIzqk",
"rating": 671
},
{
"id": 536363,
"title": "Coding Adventure: Ant and Slime Simulations",
"url": "https://www.youtube.com/watch?v=X-iSQQgOd1A",
"rating": 76
},
{
"id": 323445,
"title": "Why the Tour de France is so brutal",
"url": "https://www.youtube.com/watch?v=ZacOS8NBK6U",
"rating": 73
}
]
Loading