Skip to content

Commit

Permalink
Merge pull request #26 from RbAvci/RB/New_video_form
Browse files Browse the repository at this point in the history
NW6 | Rabia Avci | Full-Stack-Project | Week-2 |  New video form
  • Loading branch information
RbAvci authored May 18, 2024
2 parents 58b9975 + 046903f commit 8743e0c
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 1 deletion.
4 changes: 3 additions & 1 deletion client/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import NewVideoForm from "./NewVideoForm.jsx";
import VideoList from "./VideoRecommendations";

const App = () => {
return (
<>
<h1>Video Recommendations</h1>
<VideoList />
<VideoList />
<NewVideoForm />
</>
);
};
Expand Down
55 changes: 55 additions & 0 deletions client/src/NewVideoForm.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* CSS for NewVideoForm component */
div {
max-width: 500px;
margin: 0 auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
background-color: #f9f9f9;
}

h2 {
text-align: center;
color: #333;
margin-bottom: 20px;
}

form {
display: flex;
flex-direction: column;
gap: 15px;
}

div > div {
display: flex;
flex-direction: column;
}

label {
font-weight: bold;
margin-bottom: 5px;
color: #555;
}

input {
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 16px;
}

button {
padding: 10px 20px;
border: none;
border-radius: 5px;
background-color: #007bff;
color: #fff;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s;
}

button:hover {
background-color: #0056b3;
}
58 changes: 58 additions & 0 deletions client/src/NewVideoForm.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React, { useState } from "react";

import "./NewVideoForm.css";
const NewVideoForm = () => {
const [title, setTitle] = useState("");
const [src, setSrc] = useState("");

const handleSubmit = (e) => {
e.preventDefault();

fetch("/api/videos", {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({ title, src }),
})
.then((response) => response.json())
.then((data) => {
console.log(JSON.stringify(data));
})
.catch((error) => {
console.error(error);
});
};

return (
<div>
<h2>Add New Video</h2>
<form onSubmit={handleSubmit}>
<div>
<label htmlFor="title">Video Title: </label>
<input
type="text"
id="title"
value={title}
onChange={(e) => setTitle(e.target.value)}
required
/>
</div>
<div>
<label htmlFor="src">Video URL: </label>
<input
type="url"
id="src"
value={src}
onChange={(e) => setSrc(e.target.value)}
required
/>
</div>
<button type="submit">Submit</button>
</form>
</div>
);
};

export default NewVideoForm;

0 comments on commit 8743e0c

Please sign in to comment.