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

Submit 8-0-react-crud-lab #44

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
12df1ce
Update fetch getAllShows function and call to process response in Sho…
bowersjuan Nov 2, 2022
5fa78e7
Create state and controlled search input for ShowsIndex component
bowersjuan Nov 3, 2022
cbe8825
Add search function to ShowsIndex
bowersjuan Nov 3, 2022
ef6209d
Add show page for individual shows and create fetch call
bowersjuan Nov 3, 2022
de315e3
Add delete single show functionality
bowersjuan Nov 3, 2022
7aed03b
Initial commit
bowersjuan Nov 3, 2022
5773bca
Update MoviesIndex component
bowersjuan Nov 3, 2022
cfb1c1f
Create fetch call for movies data and update MoviesIndex
bowersjuan Nov 3, 2022
94a0bb7
Create helper function handle-text-change
bowersjuan Nov 4, 2022
5448a1f
Delete helpers
bowersjuan Nov 4, 2022
7229b68
Update MovieIndex and Movie Listing
bowersjuan Nov 4, 2022
72c88f5
Update MoviesIndex
bowersjuan Nov 4, 2022
2af8526
Initial commit
bowersjuan Nov 4, 2022
52bf404
Add MoviesIndex styling
bowersjuan Nov 4, 2022
ac8ed41
git add MoviesListing.css
bowersjuan Nov 4, 2022
08a85d1
Update MovieListing Styling
bowersjuan Nov 4, 2022
abdde98
Add fetch calls for getOneMovie and destroyMovie
bowersjuan Nov 4, 2022
6b1f905
Create Movie.js and add new Route to App
bowersjuan Nov 4, 2022
91790e2
Update fetch call for getOneMovie
bowersjuan Nov 4, 2022
605891d
Update Movie.js
bowersjuan Nov 4, 2022
4fcf2f3
Update Movie.js
bowersjuan Nov 4, 2022
d41117b
Create and Update MoviesNewForm component and add Link at Add a new m…
bowersjuan Nov 4, 2022
0399315
Create and update MoviesEditForm component and create Route path for …
bowersjuan Nov 4, 2022
406d97d
Add create new movie and show functionality, new movie form needs fur…
bowersjuan Nov 4, 2022
c13c86e
Update component function names
bowersjuan Nov 4, 2022
fd4accb
Update App component
bowersjuan Nov 4, 2022
c0f4c54
Update Movie component
bowersjuan Nov 4, 2022
36dc830
Update MoviesIndex, MoviesListing and ShowsListing components
bowersjuan Nov 4, 2022
10fa739
Update fetch with show edit functionality
bowersjuan Nov 4, 2022
e3c074a
Update fetch.js and MoviesNEwForm.js for bugs
bowersjuan Nov 9, 2022
f469c6c
Add post and edit functionality
bowersjuan Nov 10, 2022
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
18 changes: 17 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";

// Components
// Common Components
import Footer from "./components/common/Footer";
import Home from "./components/home/Home";
import Nav from "./components/common/Nav";

// Shows Components
import Show from "./components/shows/Show";
import ShowsEditForm from "./components/shows/ShowsEditForm";
import ShowsIndex from "./components/shows/ShowsIndex";
import ShowsNewForm from "./components/shows/ShowsNewForm";

// Movies Components
import Movie from "./components/movies/Movie";
import MoviesEditForm from "./components/movies/MoviesEditForm";
import MoviesIndex from "./components/movies/MoviesIndex";
import MoviesNewForm from "./components/movies/MoviesNewForm";

function App() {
return (
<div className="wrapper">
<Router>
<Nav />

<Routes>
<Route path="/" element={<Home />} />

<Route path="/shows" element={<ShowsIndex />} />
<Route path="/shows/new" element={<ShowsNewForm />} />
<Route path="/shows/:id" element={<Show />} />
<Route path="/shows/:id/edit" element={<ShowsEditForm />} />

<Route path="/movies" element={<MoviesIndex />} />
<Route path="/movies/new" element={<MoviesNewForm />} />
<Route path="/movies/:id" element={<Movie />} />
<Route path="/movies/:id/edit" element={<MoviesEditForm />} />
</Routes>

<Footer />
</Router>
</div>
Expand Down
89 changes: 73 additions & 16 deletions src/api/fetch.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,89 @@
// Shows
const URL = process.env.REACT_APP_API_BASE_URL;

// Create
export function createShow(show) {
return;
}
// SHOWS

// Delete
export function destroyShow(id) {
return;
// CREATE SHOW
export function createShow(show) {
const options = {
method: "Post",
body: JSON.stringify(show),
headers: { "Content-Type": "application/json" },
};
return fetch(`${URL}/shows/`, options).then((response) => {
return response.json();
});
}

// Index/Get all
// Index/Get all (READ SHOWS)
export function getAllShows() {
return;
return fetch(`${URL}/shows`).then((response) => response.json());
}

// Show/Get one
// Show/Get one (READ SHOW)
export function getOneShow(id) {
return;
return fetch(`${URL}/shows/${id}`).then((response) => response.json());
}

// Update
// UPDATE SHOW
export function updateShow(id, show) {
return;
const options = {
method: "PUT",
body: JSON.stringify(show),
headers: { "Content-Type": "application/json" },
};
return fetch(`${URL}/shows/${id}`, options).then((response) => {
return response.json();
});
}

// Movies
// DELETE SHOW
export function destroyShow(id) {
const options = {
method: "DELETE",
};
return fetch(`${URL}/shows/${id}`, options);
}

// MOVIES

// CREATE MOVIE
export function createMovie(movie) {
const options = {
method: "POST",
body: JSON.stringify(movie),
headers: { "Content-Type": "application/json" },
};
return fetch(`${URL}/movies/`, options).then((response) => {
return response.json();
});
}

// Index/Get all (READ MOVIES)
export function getAllMovies() {
return;
return fetch(`${URL}/movies`).then((response) => response.json());
}

// Movie/Get one (READ MOVIE)
export function getOneMovie(id) {
return fetch(`${URL}/movies/${id}`).then((response) => response.json());
}

// UPDATE MOVIE
export function updateMovie(id, movie) {
const options = {
method: "PUT",
body: JSON.stringify(movie),
headers: { "Content-Type": "application/json" },
};
return fetch(`${URL}/movies/${id}`, options).then((response) => {
return response.json();
});
}

// DELETE
export function destroyMovie(id) {
const options = {
method: "DELETE",
};
return fetch(`${URL}/movies/${id}`, options);
}
47 changes: 47 additions & 0 deletions src/components/movies/Movie.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
.movies-movie-wrapper {
margin: 0 auto;
width: 70%;
}

.movies-movie {
border: 1px solid var(--primary);
border-radius: 3px;
color: var(--gray);
display: grid;
grid-template-rows: auto 1fr auto;
}

.movies-movie article {
padding: 10px 25px;
}

.movies-movie aside {
background: var(--primary);
color: var(--light);
}

.movies-movie aside p {
display: inline-block;
font-size: 14px;
margin: 10px 25px;
padding: 0;
width: auto;
}

.movies-movie aside span {
font-weight: bold;
}

.movies-movie aside button {
background: none;
border: none;
color: var(--light);
cursor: pointer;
margin: 10px 25px;
text-decoration: underline;
}

.movies-movie aside button:hover {
text-decoration: none;
}

125 changes: 125 additions & 0 deletions src/components/movies/MoviesEditForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { useState, useEffect } from "react";
import { useNavigate, useParams } from "react-router-dom";

import "./MoviesForm.css";

import { getOneMovie, updateMovie } from "../../api/fetch";

export default function MoviesEditForm() {
const [movie, setMovie] = useState({
type: "",
title: "",
country: "",
dateAdded: "",
description: "",
duration: "",
listedIn: "",
rating: "",
releaseYear: "",
});

const navigate = useNavigate();
const { id } = useParams();

function handleSubmit(event) {
event.preventDefault();
updateMovie(id, movie)
.then((response) => navigate(`/movies/${response.id}`))
.catch((error) => {
console.log(error);
});
}

function handleTextChange(event) {
setMovie({
...movie,
[event.target.id]: event.target.value,
});
}

useEffect(() => {
getOneMovie(id)
.then((response) => setMovie(response))
.catch((error) => console.log(error));
}, [id]);

return (
<form onSubmit={handleSubmit}>
<label htmlFor="title">Title:</label>
<input
type="text"
id="title"
value={movie.title}
onChange={handleTextChange}
/>

<label htmlFor="description">Description:</label>
<input
type="text"
id="description"
value={movie.description}
onChange={handleTextChange}
/>

<label htmlFor="type">Type</label>
<input
type="text"
id="type"
value={movie.type}
onChange={handleTextChange}
/>

<label htmlFor="rating">Rating:</label>
<input
type="text"
id="rating"
value={movie.rating}
onChange={handleTextChange}
/>

<label htmlFor="listedIn">Listed in</label>
<input
type="text"
id="listedIn"
value={movie.listedIn}
onChange={handleTextChange}
/>

<label htmlFor="duration">Duration</label>
<input
type="text"
id="duration"
value={movie.duration}
onChange={handleTextChange}
/>

<label htmlFor="releaseYear">Release Year</label>
<input
type="text"
id="releaseYear"
value={movie.releaseYear}
onChange={handleTextChange}
/>

<label htmlFor="country">Country</label>
<input
type="text"
id="country"
value={movie.country}
onChange={handleTextChange}
/>

<label htmlFor="dateAdded">Date added:</label>
<input
type="text"
id="dateAdded"
value={movie.dateAdded}
onChange={handleTextChange}
/>

<br />

<input type="submit" />
</form>
);
}
Loading