Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
e97ef16
Setup React Router DOM
corinna-fab Jun 22, 2020
2ab122a
Built out components
corinna-fab Jun 22, 2020
0ca8090
Added Library index page
corinna-fab Jun 22, 2020
80a8826
Small changes for push
corinna-fab Jun 22, 2020
2d073ea
Added SearchBar component
npogodina Jun 22, 2020
4895683
Added onInputChange to search"
npogodina Jun 22, 2020
71b5192
Lists all customers
corinna-fab Jun 22, 2020
652cdb3
Set up API call to themoviedb
npogodina Jun 23, 2020
249b002
Passed props to SearchResult components
npogodina Jun 23, 2020
7da028a
Fixed images for found movies
npogodina Jun 23, 2020
bd44086
Fixed SearchResults table and added conditional rendering to it
npogodina Jun 23, 2020
5aae2f9
Extracted AddToLibraryButton component
npogodina Jun 23, 2020
90f190e
Added conditional rendering to Button
npogodina Jun 23, 2020
cca7707
Wrote core add to Library functionality
npogodina Jun 23, 2020
3778f67
Fixed a bug in adding to Library
npogodina Jun 23, 2020
1a7ae71
Added button style change on addToLibrary
npogodina Jun 23, 2020
ef5fe01
Some navbar updates but should have switched branches
corinna-fab Jun 23, 2020
63762dd
Added black navbar
npogodina Jun 23, 2020
2a0386a
Added active item functionality using state
npogodina Jun 23, 2020
cac9d96
Styled home page
npogodina Jun 23, 2020
5d2f7bb
Merge pull request #1 from corinna-fab/np-navbar-2
npogodina Jun 23, 2020
31c6003
Merge pull request #2 from corinna-fab/np-search
npogodina Jun 23, 2020
09b37e2
Commiting to switch branches - not functioning currently
corinna-fab Jun 23, 2020
caec4ed
Select Movie button seems to set state but doesn't persist
corinna-fab Jun 23, 2020
e2b3b10
Customers functionality now matches Movies - state changes but doesn'…
corinna-fab Jun 23, 2020
63f4132
Minor updates plus functionality
corinna-fab Jun 23, 2020
377dfd4
Merged pull
corinna-fab Jun 23, 2020
caeda7e
Customer name renders in nav
corinna-fab Jun 23, 2020
af08da1
Fixed merge conflicts
corinna-fab Jun 23, 2020
d7d743e
Cart can be cleared
corinna-fab Jun 23, 2020
9a3e300
Updated customer page CSS
corinna-fab Jun 23, 2020
e88b812
Updated movie list CSS
corinna-fab Jun 23, 2020
456f5cb
Additional CSS
corinna-fab Jun 23, 2020
84c0827
rental submits
corinna-fab Jun 24, 2020
c2725a4
Added errorMessage state to App.js
npogodina Jun 24, 2020
da79a81
Added ErrorCard component ans Switch with routes for it
npogodina Jun 24, 2020
66fb93e
Added setErrorCallback to be able to change state from below
npogodina Jun 24, 2020
408e802
Added setErrorCallback to Navbar to simulate one time flash while swi…
npogodina Jun 24, 2020
0730ffb
Added margin to ErrorCard
npogodina Jun 24, 2020
b08f5e3
Added error handling to addToLibrary in SearchResult
npogodina Jun 24, 2020
45741e0
Merge pull request #3 from corinna-fab/np-error-handling
npogodina Jun 24, 2020
e39bb9b
Added PropTypes to Movie and Customer
corinna-fab Jun 24, 2020
2531367
Fixed merge conflicts
corinna-fab Jun 24, 2020
47569f7
Added PropTypes to components
npogodina Jun 24, 2020
1abbd95
Changed class to className in Home component
npogodina Jun 24, 2020
0f5bc72
Fixed bug in AddToLibraryButton Component
npogodina Jun 24, 2020
c3aa7ed
Changed class to className on multiple components
npogodina Jun 24, 2020
f9331d0
Merge pull request #4 from corinna-fab/np-proptypes
npogodina Jun 24, 2020
4d8f61d
Flashes success message when Rental is created
corinna-fab Jun 24, 2020
5d933fd
Merge branch 'customers'
corinna-fab Jun 24, 2020
5683629
Moved Rental box inside a Switch
npogodina Jun 24, 2020
df19c60
Added setSuccessCallback to Navbar
npogodina Jun 24, 2020
ea8c3c2
Added margin to Search page
npogodina Jun 24, 2020
a7eb6ec
Changed buttons from olive to blue
npogodina Jun 24, 2020
fa592ed
Changed Rental Box button color back to olive
npogodina Jun 24, 2020
27a4bb5
Made a new movie appear in Library right away
npogodina Jun 24, 2020
56e247d
Changed SearchBar placeholder to Star Wars
npogodina Jun 24, 2020
10b7964
Fixed bug with Navbar reload using useLocation
npogodina Jun 24, 2020
1d8dd78
Removed console.log from Navbar
npogodina Jun 24, 2020
bfd8366
Merge pull request #5 from corinna-fab/np-style-fix
npogodina Jun 24, 2020
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
10,054 changes: 5,542 additions & 4,512 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,28 @@
"version": "0.1.1",
"private": true,
"dependencies": {
"axios": "^0.19.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/semantic.min.css">
<title>React App</title>
</head>
<body>
Expand Down
15 changes: 15 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,18 @@
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}

.movie_index_container {
background-color: #222;
width: 250px;
border-radius: 25px;
color: white;
}

.mt {
margin-top: 20px;
}

.mb {
margin-bottom: 20px;
}
206 changes: 187 additions & 19 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,189 @@
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';

class App extends Component {
render() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h1 className="App-title">Welcome to React</h1>
</header>
<p className="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p>
</div>
);
}
}
import React, { useState, useEffect } from "react";
import axios from "axios";
import "./App.css";

import Navbar from "./components/Navbar";
import Library from "./components/Library";
import Search from "./components/Search";
import Home from "./components/Home";
import Customers from "./components/Customers";
import RentalBox from "./components/RentalBox";

import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";

import ErrorCard from "./components/ErrorCard";
import SuccessCard from "./components/SuccessCard";

const LIBRARY_URL = "http://localhost:3000/library";
const CUSTOMERS_URL = "http://localhost:3000/customers";
const RENTALS_URL = "http://localhost:3000/";

const App = () => {
const [library, setLibrary] = useState();
const [customers, setCustomers] = useState();
const [moviePick, setMoviePick] = useState();
const [customerPick, setCustomerPick] = useState();
const [errorMessage, setErrorMessage] = useState(null);
const [successMessage, setSuccessMessage] = useState(null);

const setErrorCallback = (data) => {
setErrorMessage(data);
};

const setSuccessCallback = (data) => {
setSuccessMessage(data);
};

useEffect(() => {
axios
.get(LIBRARY_URL)
.then((response) => {
const apiLibrary = response.data;
setLibrary(apiLibrary);
setErrorMessage(null);
setSuccessMessage(null);
})
.catch((error) => {
setErrorMessage(error.message);
console.log(error);
});
}, []);

useEffect(() => {
axios
.get(CUSTOMERS_URL)
.then((response) => {
const apiCustomers = response.data;
setCustomers(apiCustomers);
setSuccessMessage(null);
})
.catch((error) => {
setErrorMessage(error.message);
console.log(error);
});
}, []);

const addMovieCallback = (newMovie) => {
const updatedLibrary = [newMovie, ...library];
setLibrary(updatedLibrary);
};

const onSelectCustomer = (customer_id) => {
axios.get(CUSTOMERS_URL).then((response) => {
let count = 1;
const customerList = response.data.map((customer) => {
customer["id"] = count;
count += 1;
return customer;
});

const selectedCustomer = customerList.find((customer) => {
return customer.id === customer_id;
});

if (selectedCustomer) {
setCustomerPick(selectedCustomer);
setSuccessMessage(null);
console.log(customerPick);
}
});
};
// I don't really understand this part
const onSelectMovie = (movie_id) => {
axios.get(LIBRARY_URL).then((response) => {
let count = 1;
const movieList = response.data.map((movie) => {
movie["id"] = count;
count += 1;
return movie;
});

const selectedMovie = movieList.find((movie) => {
return movie.id === movie_id;
});

if (selectedMovie) {
setMoviePick(selectedMovie);
setSuccessMessage(null);
console.log(moviePick);
}
});
};

const clearSelections = () => {
setMoviePick(null);
setCustomerPick(null);
setSuccessMessage(null);
};

const submitSelections = () => {
if (moviePick != null && customerPick != null) {
let dueDate = new Date();
dueDate.setDate(new Date().getDate() + 7);
axios
.post(`${RENTALS_URL}rentals/${moviePick.title}/check-out`, {
customer_id: customerPick.id,
due_date: dueDate,
})
.then((response) => {
setMoviePick(null);
setCustomerPick(null);
setSuccessMessage("Rental successfully created.");
console.log(response.message);
})
.catch((error) => {
setErrorMessage(error.message);
console.log(error);
});
}
};

return (
<Router>
<header>
<Navbar setError={setErrorCallback} setSuccess={setSuccessCallback} />
</header>

<main>
<Switch>
<Route exact path="/" />
<Route path="/home" />
<Route path="/">
{errorMessage && <ErrorCard message={errorMessage} />}
{successMessage && <SuccessCard message={successMessage} />}
<RentalBox
moviePick={moviePick}
customerPick={customerPick}
clearSelectionsCallback={clearSelections}
submitSelectionsCallback={submitSelections}
/>
</Route>
</Switch>

<Switch>
<Route path="/library">
<Library library={library} selectMovieCallback={onSelectMovie} />
</Route>
<Route path="/search">
<Search
library={library}
setError={setErrorCallback}
addMovie={addMovieCallback}
/>
</Route>
<Route path="/customers">
<Customers
selectCustomerCallback={onSelectCustomer}
customers={customers}
/>
</Route>
<Route path="/">
<Home moviePick={moviePick} />
</Route>
</Switch>
</main>
</Router>
);
};

export default App;
26 changes: 26 additions & 0 deletions src/components/AddToLibraryButton.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from "react";
import PropTypes from "prop-types";

const AddToLibraryButton = (props) => {
const addToLibrary = (event) => {
event.preventDefault();
props.addToLibraryCallback();
};

if (props.inLibrary) {
return <button className="ui disabled button">Added</button>;
} else {
return (
<button className="ui blue button" onClick={addToLibrary}>
To Library
</button>
);
}
};

AddToLibraryButton.propTypes = {
inLibrary: PropTypes.bool.isRequired,
addToLibraryCallback: PropTypes.func.isRequired,
};

export default AddToLibraryButton;
10 changes: 10 additions & 0 deletions src/components/Customer.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.user_grid {
border-bottom: solid black 3px;
width: fit-content;
text-align: center;
display: flex;
flex-direction: column;
flex-wrap: wrap;
padding: 20px;
align-items: center;
}
42 changes: 42 additions & 0 deletions src/components/Customer.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from "react";
import PropTypes from "prop-types";
import "./Customer.css";

const Customer = (props) => {
// return(
// <div className="cards">
// <div className="card">
// <div>
// <td>{props.name}</td>
// <td>
// <button class="ui blue button" onClick={() => { props.customerCallback(props.id) } }>
// Select Customer
// </button>
// </td>
// </div>
// </div>
// </div>
// )

return (
<div className="user_grid">
<h3 class="ui header"> {props.name} </h3>
<button
class="ui blue button"
onClick={() => {
props.customerCallback(props.id);
}}
>
Select Customer
</button>
</div>
);
};

Customer.propTypes = {
id: PropTypes.number.isRequired,
name: PropTypes.string.isRequired,
customerCallback: PropTypes.func.isRequired,
};

export default Customer;
7 changes: 7 additions & 0 deletions src/components/Customers.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.customerList {
padding: 50px;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
}
30 changes: 30 additions & 0 deletions src/components/Customers.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React, { useState, useEffect } from 'react';
import Customer from './Customer';
import './Customers.css'


const Customers = (props) => {

let customerList = [];

if (props.customers) {
customerList = props.customers.map((customer) => {
return (
<Customer
name={customer.name}
customerCallback={props.selectCustomerCallback}
id={customer.id}
key={customer.id}
/>
);
});
}

return (
<div className="customerList">
{customerList}
</div>
)
}

export default Customers;
Loading