-
-
Notifications
You must be signed in to change notification settings - Fork 359
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
NW5 Manchester - Doris Siu - SQL - Week 1 #245
Changes from 7 commits
7363558
f02822c
147d1e8
cf0dedd
97bff6f
1f1d653
f87a366
714aa75
1c987ef
6120538
ba0f114
1c64edd
f5276bb
06e7f78
8fb5f38
a7a577e
5c8bfc6
0322cf2
405759f
6e1bc99
a5abeeb
aa75071
f8c3fd9
7e633cc
6b45626
272475c
982e98a
292a5e7
a663ac9
bc8b65d
b5e069d
1471ce0
16083f4
9a14ecb
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 @@ | ||
node_modules |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React, { useState } from "react"; | ||
|
||
export default function AddVideo({ addVideo }) { | ||
let [input, setInput] = useState({ | ||
title: "", | ||
url: "", | ||
rating: 0, | ||
}); | ||
|
||
const handleChange = (e) => { | ||
setInput({ ...input, [e.target.name]: e.target.value }); | ||
}; | ||
|
||
const onSubmit = (e) => { | ||
e.preventDefault(); | ||
input.id = uuidv4(); | ||
addVideo(input); | ||
}; | ||
|
||
function uuidv4() { | ||
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. maybe you can use the uuid library for this unless there is a valid reason to build your own random character generator, otherwise this looks great, good stuff https://www.npmjs.com/package/uuid if you are using npm |
||
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) => | ||
( | ||
c ^ | ||
(crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4))) | ||
).toString(16) | ||
); | ||
} | ||
|
||
return ( | ||
<form onSubmit={onSubmit}> | ||
<div> | ||
<h3>Add a video</h3> | ||
<label>Title:</label> | ||
<input | ||
id="title" | ||
type="text" | ||
name="title" | ||
value={input.title} | ||
onChange={handleChange} | ||
required | ||
/> | ||
<label>URL:</label> | ||
<input | ||
id="url" | ||
type="text" | ||
name="url" | ||
value={input.url} | ||
onChange={handleChange} | ||
required | ||
/> | ||
<button type="submit" className="btn btn-primary"> | ||
Add | ||
</button> | ||
</div> | ||
</form> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,18 @@ | ||
.App { | ||
text-align: center; | ||
} | ||
|
||
.grid-container { | ||
display: grid; | ||
margin: 20px; | ||
gap: 50px 0px; | ||
grid-template-columns: auto auto auto auto; | ||
} | ||
|
||
button, input { | ||
margin: 10px; | ||
} | ||
|
||
h3 { | ||
color: red; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React, { useState } from "react"; | ||
|
||
export default function Rating({ rating }) { | ||
let [rate, setRate] = useState(rating); | ||
function incrementRate() { | ||
setRate(rate + 1); | ||
} | ||
function decrementRate() { | ||
setRate(rate - 1); | ||
} | ||
|
||
return ( | ||
<div> | ||
Rating: {rate} | ||
<br /> | ||
<button type="button" className="btn btn-primary" onClick={incrementRate}> | ||
Up Vote | ||
</button> | ||
<button type="button" className="btn btn-primary" onClick={decrementRate}> | ||
Down Vote | ||
</button> | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from "react"; | ||
import Rating from "./Rating"; | ||
|
||
export default function VideoCards({ videoList, removeVideo }) { | ||
return ( | ||
<div className="grid-container"> | ||
{videoList.map((element, index) => ( | ||
<span key={index} className="card"> | ||
<iframe | ||
width="560" | ||
height="315" | ||
src={ | ||
"https://www.youtube.com/embed/" + | ||
element.url.replace("https://www.youtube.com/watch?v=", "") | ||
} | ||
title="YouTube video player" | ||
frameborder="0" | ||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" | ||
allowfullscreen | ||
></iframe>{" "} | ||
<div className="card-body"> | ||
<h4>{element.title}</h4> | ||
<Rating rating={element.rating} /> | ||
<button | ||
type="button" | ||
className="btn btn-primary" | ||
onClick={() => { | ||
removeVideo(element.id); | ||
}} | ||
> | ||
Remove video | ||
</button> | ||
</div> | ||
</span> | ||
))} | ||
</div> | ||
); | ||
} |
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.
Looks good, just a minor suggestion, would it be possible to destructure
name
andvalue
from e.target as variables?