-
-
Notifications
You must be signed in to change notification settings - Fork 358
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
Changes from all commits
860330b
8ecff3b
60d3171
938bc80
c4fc8df
24cfdbc
ab701ec
f1dadb6
de511fa
88b21e6
75540bb
c30d2d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
build |
Large diffs are not rendered by default.
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; | ||
} |
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> | ||
<Videos /> | ||
</div> | ||
</header> | ||
<Footer /> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; | ||
|
||
|
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; |
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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using an |
||
<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; |
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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
<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; |
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); | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good job in using |
||
|
||
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; |
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 | ||
} | ||
] |
There was a problem hiding this comment.
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">)