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

NW5 Manchester - Doris Siu - SQL - Week 1 #245

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7363558
Inserting .gitignore form a correctly forked repo
Doris-Siu Feb 8, 2023
f02822c
Level 100 - insert back all the back-up codes
Doris-Siu Feb 8, 2023
147d1e8
Update AddVideo.js
Doris-Siu Feb 8, 2023
cf0dedd
Add Rating component and vote buttons, and respective handler functions
Doris-Siu Feb 8, 2023
97bff6f
Create GUIDs to each added input video
Doris-Siu Feb 8, 2023
1f1d653
Update the remove button
Doris-Siu Feb 8, 2023
f87a366
Level 100- Add layout and simple CSS design
Doris-Siu Feb 9, 2023
714aa75
Complete Level 200 - Week 2 - Back End
Doris-Siu Feb 13, 2023
1c987ef
Complete Level 250 - Week 2 - Connecting Front End and Back End
Doris-Siu Feb 13, 2023
6120538
Complete Level 300 - Setting up Database
Doris-Siu Feb 20, 2023
ba0f114
config .env file & connect to aws rds db
Doris-Siu Mar 2, 2024
1c64edd
minor update to frontend
Doris-Siu Mar 2, 2024
f5276bb
create GitHub Actions workflow yaml file for client
Doris-Siu Mar 2, 2024
06e7f78
fix yaml formatting
Doris-Siu Mar 2, 2024
8fb5f38
update yaml file
Doris-Siu Mar 2, 2024
a7a577e
create GitHub Actions workflow yaml file for server
Doris-Siu Mar 2, 2024
5c8bfc6
Update server.js
Doris-Siu Mar 2, 2024
0322cf2
fix push path
Doris-Siu Mar 2, 2024
405759f
Update App.js
Doris-Siu Mar 2, 2024
6e1bc99
Update server.js
Doris-Siu Mar 2, 2024
a5abeeb
move the yaml file to correct dir
Doris-Siu Mar 2, 2024
aa75071
update server yaml
Doris-Siu Mar 2, 2024
f8c3fd9
server yaml
Doris-Siu Mar 2, 2024
7e633cc
server js
Doris-Siu Mar 3, 2024
6b45626
fix server yaml
Doris-Siu Mar 3, 2024
272475c
write key without remove \r
Doris-Siu Mar 3, 2024
982e98a
update with pem
Doris-Siu Mar 3, 2024
292a5e7
fix yaml bug
Doris-Siu Mar 3, 2024
a663ac9
ignore host key checking
Doris-Siu Mar 3, 2024
bc8b65d
fix dir path bug
Doris-Siu Mar 3, 2024
b5e069d
upload Dockerfile
Doris-Siu Mar 3, 2024
1471ce0
create terraform s3
Doris-Siu Mar 3, 2024
16083f4
create terraform ec2
Doris-Siu Mar 3, 2024
9a14ecb
create terraform rds
Doris-Siu Mar 3, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
14,560 changes: 46 additions & 14,514 deletions client/package-lock.json

Large diffs are not rendered by default.

57 changes: 57 additions & 0 deletions client/src/AddVideo.js
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 });
Copy link

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 and value from e.target as variables?

};

const onSubmit = (e) => {
e.preventDefault();
input.id = uuidv4();
addVideo(input);
};

function uuidv4() {
Copy link

@Craques Craques Feb 9, 2023

Choose a reason for hiding this comment

The 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
https://yarnpkg.com/package/uuidv4 uf you are using yarn

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>
);
}
15 changes: 15 additions & 0 deletions client/src/App.css
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;
}
16 changes: 16 additions & 0 deletions client/src/App.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
import "./App.css";
import React, { useState } from "react";
import VideoCards from "./VideoCards";
import AddVideo from "./AddVideo";
import data from "./exampleresponse.json";

function App() {
let [videos, setVideos] = useState(data);

function addVideo(video) {
setVideos([...videos, video]);
}

function removeVideo(id) {
setVideos(videos.filter((video) => video.id !== id));
}

return (
<div className="App">
<header className="App-header">
<h1>Video Recommendation</h1>
</header>
<AddVideo addVideo={addVideo} />
<VideoCards videoList={videos} removeVideo={removeVideo} />
</div>
);
}
Expand Down
24 changes: 24 additions & 0 deletions client/src/Rating.js
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>
);
}
38 changes: 38 additions & 0 deletions client/src/VideoCards.js
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>
);
}
10 changes: 10 additions & 0 deletions exampleresponse.json → client/src/exampleresponse.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,70 @@
"id": 523523,
"title": "Never Gonna Give You Up",
"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
"vid": "dQw4w9WgXcQ",
"rating": 23
},
{
"id": 523427,
"title": "The Coding Train",
"url": "https://www.youtube.com/watch?v=HerCR8bw_GE",
"vid": "HerCR8bw_GE",
"rating": 230
},
{
"id": 82653,
"title": "Mac & Cheese | Basics with Babish",
"url": "https://www.youtube.com/watch?v=FUeyrEN14Rk",
"vid": "FUeyrEN14Rk",
"rating": 2111
},
{
"id": 858566,
"title": "Videos for Cats to Watch - 8 Hour Bird Bonanza",
"url": "https://www.youtube.com/watch?v=xbs7FT7dXYc",
"vid": "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",
"vid": "4As0e4de-rI",
"rating": 3211
},
{
"id": 283634,
"title": "Learn Unity - Beginner's Game Development Course",
"url": "https://www.youtube.com/watch?v=gB1F9G0JXOo",
"vid": "gB1F9G0JXOo",
"rating": 211
},
{
"id": 562824,
"title": "Cracking Enigma in 2021 - Computerphile",
"url": "https://www.youtube.com/watch?v=RzWB5jL5RX0",
"vid": "RzWB5jL5RX0",
"rating": 111
},
{
"id": 442452,
"title": "Coding Adventure: Chess AI",
"url": "https://www.youtube.com/watch?v=U4ogK0MIzqk",
"vid": "U4ogK0MIzqk",
"rating": 671
},
{
"id": 536363,
"title": "Coding Adventure: Ant and Slime Simulations",
"url": "https://www.youtube.com/watch?v=X-iSQQgOd1A",
"vid": "X-iSQQgOd1A",
"rating": 76
},
{
"id": 323445,
"title": "Why the Tour de France is so brutal",
"url": "https://www.youtube.com/watch?v=ZacOS8NBK6U",
"vid": "ZacOS8NBK6U",
"rating": 73
}
]