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

Leaves - Emily and Raisah #4

Open
wants to merge 51 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
85974c2
App set up
rvesteinsdottir Dec 16, 2019
1700e92
setup
emilyvomacka Dec 16, 2019
8956ca4
routes added
emilyvomacka Dec 16, 2019
faefedc
Merged changes
rvesteinsdottir Dec 16, 2019
ea6ab1b
Added displays to Customer and CustomerList components
rvesteinsdottir Dec 16, 2019
bf8b168
Formatted Customer display and added select function
rvesteinsdottir Dec 16, 2019
c77db17
selected movie and customer in nav bar
emilyvomacka Dec 16, 2019
30dee64
Merge pull request #1 from rvesteinsdottir/library
emilyvomacka Dec 16, 2019
46619b1
Merge branch 'master' into rav/customers
rvesteinsdottir Dec 16, 2019
62c06dd
Merge pull request #2 from rvesteinsdottir/rav/customers
rvesteinsdottir Dec 16, 2019
5e7c21a
Able to create rental with movie and customer selected
rvesteinsdottir Dec 17, 2019
0510646
search results displaying
emilyvomacka Dec 17, 2019
a9f9b74
button edits
emilyvomacka Dec 17, 2019
ef343a0
Rental creation resets state
rvesteinsdottir Dec 17, 2019
51704fe
add movie to db functions sketched out
emilyvomacka Dec 17, 2019
4b101d2
merging with master
emilyvomacka Dec 17, 2019
62d1d0d
Added bootstrap and formatted sidebar
rvesteinsdottir Dec 17, 2019
0e75087
Added styling to Movie Library
rvesteinsdottir Dec 17, 2019
c639c36
add movie is up and running
emilyvomacka Dec 17, 2019
c0b823f
Style Customer LIst
rvesteinsdottir Dec 17, 2019
5bc8f56
Style rentals and nav bar
rvesteinsdottir Dec 17, 2019
312f82c
Merge branch 'rav/bootstrap'
rvesteinsdottir Dec 17, 2019
39f8823
Search bar fully merged
rvesteinsdottir Dec 17, 2019
c1ae01f
deleted console logs
emilyvomacka Dec 17, 2019
398819a
Merge branch 'master' of https://github.com/rvesteinsdottir/video-sto…
emilyvomacka Dec 17, 2019
8371fb2
added proptypes lol
emilyvomacka Dec 17, 2019
d3c2ef1
Added styling to nav bar
rvesteinsdottir Dec 17, 2019
6e64d14
Fixed styling in nav bar
rvesteinsdottir Dec 17, 2019
4970178
Changes merged
rvesteinsdottir Dec 17, 2019
eb42515
added alerts
emilyvomacka Dec 17, 2019
3788c4e
Merge branch 'master' of https://github.com/rvesteinsdottir/video-sto…
emilyvomacka Dec 17, 2019
3f83a22
Refactored selectedItemClass method
rvesteinsdottir Dec 18, 2019
dc5d038
responsive css for selected movie
emilyvomacka Dec 18, 2019
a4a3805
rows are working
emilyvomacka Dec 18, 2019
0b64a12
Merged
rvesteinsdottir Dec 18, 2019
c2b5bc1
Removed weird format
rvesteinsdottir Dec 18, 2019
b57ad79
Formatted columns
rvesteinsdottir Dec 18, 2019
82da40d
Fixed home formatting
rvesteinsdottir Dec 18, 2019
d3eec5b
details view for movie search
emilyvomacka Dec 18, 2019
35e3f24
Home format
rvesteinsdottir Dec 18, 2019
a39ff92
Merge branch 'master' of https://github.com/rvesteinsdottir/video-sto…
emilyvomacka Dec 18, 2019
4ddd524
styling
emilyvomacka Dec 18, 2019
f902c98
more styling
emilyvomacka Dec 18, 2019
7f0ac2c
rows centered
emilyvomacka Dec 18, 2019
79d97b3
edit movie content
emilyvomacka Dec 18, 2019
50bc229
final edit
emilyvomacka Dec 19, 2019
4d2e67c
fixed search movie views
emilyvomacka Dec 19, 2019
785b97a
Refactored App.js
rvesteinsdottir Dec 19, 2019
9b54e94
Merge branch 'master' of https://github.com/rvesteinsdottir/video-sto…
rvesteinsdottir Dec 19, 2019
b657761
Refactored Customer, CustomerList, Movie
rvesteinsdottir Dec 19, 2019
492daf4
Refactored Movie, MovieLib, MovieSearch
rvesteinsdottir Dec 19, 2019
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
350 changes: 338 additions & 12 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 20 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,32 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.8.6",
"react-dom": "^16.8.6",
"axios": "^0.19.0",
"bootstrap": "^4.4.1",
"react": "^16.12.0",
"react-bootstrap": "^1.0.0-beta.16",
"react-bootstrap-sidebar": "0.0.1",
"react-dom": "^16.12.0",
"react-router": "^5.1.2",
"react-router-dom": "^5.1.2",
"react-scripts": "3.0.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"
]
}
}
55 changes: 41 additions & 14 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,28 +1,55 @@
.App {
text-align: center;
background-color: rgb(58, 41, 58);
}

.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 80px;
.sidenav {
height: 100%;
width: 160px;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: rgb(99, 116, 192);
overflow-x: hidden;
padding-top: 20px;
}

.App-header {
background-color: #222;
height: 150px;
padding: 20px;
.sidenav a {
padding: 6px 8px 6px 8px;
text-decoration: none;
font-size: 25px;
color: white;
display: block;
}

.sidenav ul {
margin: 0;
padding: 0;
}

.App-title {
font-size: 1.5em;
.sidenav li{
list-style-type: none;

}

.App-intro {
font-size: large;
.sidenav a:hover {
color: #b9b4b4;
text-decoration: none;
}

@keyframes App-logo-spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
.main {
margin-left: 160px;
padding: 20px 10px;
}

.items-selected {
background-color: rgb(58, 173, 154);
color: rgb(56, 53, 53);
padding: 20px;
text-align: left;
}

.span{
font-weight: bold;
}
227 changes: 217 additions & 10 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,226 @@
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import {
BrowserRouter as Router,
Switch,
Route,
Link
} from "react-router-dom";
import Home from './components/Home';
import CustomerList from './components/CustomerList';
import MovieSearch from './components/MovieSearch';
import MovieLib from './components/MovieLib';
import axios from 'axios';
import Button from 'react-bootstrap/Button';
import Alert from 'react-bootstrap/Alert';

const BASE_URL = 'http://localhost:3000'

class App extends Component {
constructor() {
super();

this.state = {
movies: [],
selectedMovie: undefined,
customers: [],
selectedCustomer: undefined,
error: undefined,
alertText: undefined,
alertVariant: undefined,
detailsMovie: undefined,
};
}

componentDidMount() {
axios.get(`${BASE_URL}/customers`)
.then((response) => {
const customers = response.data;
this.setState({
customers,
error: undefined
});
})
.catch((error) => {
this.setState({ error: error.message });
});

axios.get(`${BASE_URL}/movies`)
.then((response) => {
const movies = response.data;
this.setState({
movies,
error: undefined
});
})
.catch((error) => {
this.setState({ error: error.message });
});
}

addMovie = (movieToAdd) => {
if (!this.state.movies.find(movie => movie.external_id === movieToAdd.external_id)) {
axios.post(`${BASE_URL}/movies`, movieToAdd)
.then((response) => {
const { movies } = this.state;
movies.push(movieToAdd)
this.setState({
movies,
alertText: "Movie successfully added to your rental library",
alertVariant: "success"
});
})
.catch((error) => {
this.setState({
error: error.message,
alertText: `${error.message}`,
alertVariant: "danger"
});
});
} else {
this.setState({
alertText: "Movie already exists in library",
alertVariant: "danger"
})
}
}

selectMovie = (movieId) => {
const { movies } = this.state;
const selectedMovie = movies.find((movie) => {
return movie.external_id === movieId;
})

this.setState({ selectedMovie })
}

selectCustomer(customerId) {
const { customers } = this.state;
const selectedCustomer = customers.find((customer) => {
return customer.id === customerId;
})

this.setState({ selectedCustomer })
}

createRental() {
if(this.state.selectedMovie) {
const movieTitle = this.state.selectedMovie.title
const customerId = this.state.selectedCustomer.id

// Sets due date to the day after rental is created
let dueDate = new Date()
dueDate.setDate(new Date().getDate() + 1);

const params = {
customer_id: customerId,
due_date: dueDate.toISOString(),
}

axios.post(`${BASE_URL}/rentals/${movieTitle}/check-out`, params)
.then(() => {
this.setState({
selectedMovie: undefined,
selectedCustomer: undefined,
error: undefined,
alertText: "Movie successfully rented",
alertVariant: "success"
})
})
.catch((error) => {
this.setState({
error: error.message,
alertText: `An error occurred: ${error.message}`,
alertVariant: "danger"
});
});
}
}

detailsCallback(movieId) {
const { movies, detailsMovie } = this.state;

if (detailsMovie && detailsMovie.external_id === movieId) {
this.setState({ detailsMovie: undefined })
} else {
const detailsMovie = movies.find((movie) => {
return movie.external_id === movieId;
})

this.setState({ detailsMovie })
}
}

selectedItemClass() {
return ((this.state.selectedCustomer || this.state.selectedMovie) ? "items-selected" : "no-items-selected" )
}

render() {

const videoAlert = () => {
return(
<Alert
variant={this.state.alertVariant}
onClose={() => this.setState({alertText: undefined, alertVariant: undefined})}
dismissible
>
{this.state.alertText}
</Alert>
)
}

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>
<Router>
<div className="App">
<div className="sidenav">

<ul>
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/customers">Customers</Link>
</li>
<li>
<Link to="/search">Movie Search</Link>
</li>
<li>
<Link to="/library">Library</Link>
</li>
</ul>

<div className={this.selectedItemClass()}>
{this.state.selectedMovie ? ("Selected Movie: \n" + this.state.selectedMovie.title) : "" }
<br />
{this.state.selectedCustomer ? ("Selected Customer: \n" + this.state.selectedCustomer.name) : "" }
<br />
{(this.state.selectedMovie && this.state.selectedCustomer )? <Button onClick={() => this.createRental()}>Create a Rental</Button> : ''}
</div>

</div>

<div className="main">

{this.state.alertText ? videoAlert() : "" }

<Switch>
<Route exact path="/">
<Home />
</Route>
<Route path="/customers">
<CustomerList customerList={this.state.customers} selectCustomer={(id) => this.selectCustomer(id)} />
</Route>
<Route path="/search">
<MovieSearch url={BASE_URL} selectMovie={(movie) => this.addMovie(movie)} detailsCallback={(id) => this.detailsCallback(id)} detailsMovie={this.state.detailsMovie} />
</Route>
<Route path="/library">
<MovieLib movieList={this.state.movies} selectMovie={(id) => this.selectMovie(id)} detailsCallback={(id) => this.detailsCallback(id)} detailsMovie={this.state.detailsMovie} />
</Route>
</Switch>

</div>
</div>
</Router>
);
}
}
Expand Down
41 changes: 41 additions & 0 deletions src/components/Customer.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.customer-card-container {
margin: 10px;
}

h3 {
color: black;
}


.customer-card {
margin: 10px;
display: grid;
grid-template-columns: 200px 1fr 100px;
align-items: center;
}

.customer-name{
grid-column-start: 1;
text-align: left;
color: black;
}

.customer-name h3 {
color: black
}


.customer-info{
grid-column-start: 2;
text-align: left;
}

ul{
margin: 0;
padding: 0;
}

li{
list-style-type: none;
}

Loading