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

Ampers: Zheng, Alex; #2

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ee83a03
movie collection and movie components created
brownav Jun 18, 2018
d0d113e
Show Movie List when button clicked
2020dream Jun 19, 2018
e09f53b
Run npm install --save react-router
2020dream Jun 19, 2018
c50930c
Use route to show MovieCollection
2020dream Jun 19, 2018
fc22f66
customer and search movies components added
brownav Jun 19, 2018
40d1c39
fixed url for customers
brownav Jun 19, 2018
52bad55
Show selectedMovie on Header
2020dream Jun 19, 2018
6e7bb74
Merge branch 'master' of https://github.com/brownav/video-store-consumer
2020dream Jun 19, 2018
b6bb6e7
Show selectedCustomer and SearchMovie component
2020dream Jun 19, 2018
6226f2c
searchMovie component renders movies based on query
brownav Jun 19, 2018
4c4d6c5
Add movie to library
2020dream Jun 19, 2018
ebec424
Fix spaceing bug
2020dream Jun 19, 2018
2a9e8c8
creates new rental
brownav Jun 19, 2018
ca9be32
Style App, MovieCollection, CustomerCollection
2020dream Jun 19, 2018
45a59a1
movie styling
brownav Jun 19, 2018
3de8425
customer styling
brownav Jun 19, 2018
fed7d06
Adjust style for Movie
2020dream Jun 19, 2018
84314d3
Resolve merge conflict
2020dream Jun 19, 2018
d5bab9e
moved styling for card from cardcollection to card
brownav Jun 19, 2018
38debcf
More styling
2020dream Jun 20, 2018
b08ae18
removed unnecessary logging
brownav Jun 20, 2018
b665b77
Merge branch 'master' of https://github.com/brownav/video-store-consumer
brownav Jun 20, 2018
f437598
static header when page is scrolled and flash message when user makes…
brownav Jun 20, 2018
58d19a5
Show message and clear movie title and customer name after making a r…
2020dream Jun 20, 2018
c4653cd
Merge branch 'master' of https://github.com/brownav/video-store-consumer
2020dream Jun 20, 2018
9376d58
rental notification and static header
brownav Jun 20, 2018
62c1cd5
Clear selectedMovie and selectedCustomer after making a rental
2020dream Jun 20, 2018
f280d02
minor styling
brownav Jun 20, 2018
a5466e1
Merge branch 'master' of https://github.com/brownav/video-store-consumer
brownav Jun 20, 2018
381a17a
Refactor codes
2020dream Jun 20, 2018
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
81 changes: 81 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.18.0",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"react-scripts": "1.1.4"
},
"scripts": {
Expand All @@ -13,4 +16,4 @@
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
}
54 changes: 39 additions & 15 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,51 @@
text-align: center;
}

.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 80px;
header {
display: grid;
grid-template-columns: 1fr 1fr 1fr 2.5fr 2.5fr 150px;
grid-gap: 15px;
align-items: center;
padding: 10px;
background: #7d9174;
}

.App-header {
background-color: #222;
height: 150px;
padding: 20px;
color: white;
.fixed-header {
position: fixed;
top: 0;
left: 0;
width: 100%;
z-index: 99;
}

.movie-selection {
margin-left: 50px;
}

header p {
text-align: center;
font-size: 20px;
margin: 5px 10px;
}

.App-title {
font-size: 1.5em;
.button, button {
text-align: center;
text-decoration: none;
font-size: 20px;
color: white;
background: #97c689;
border: none;
padding: 8px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

.App-intro {
font-size: large;
.button:hover, button:hover {
color: #24700d;
}

@keyframes App-logo-spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
.notification {
display: flex;
justify-content: center;
margin: 0px;
background: #ffcc5e;
}
106 changes: 96 additions & 10 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,107 @@
import React, { Component } from 'react';
import logo from './logo.svg';
import {
BrowserRouter as Router,
Route,
Link
} from 'react-router-dom';
import axios from 'axios';

import SearchMovie from './components/SearchMovie';
import MovieCollection from './components/MovieCollection';
import CustomerCollection from './components/CustomerCollection';
import './App.css';

const URL = "http://localhost:3001/rentals/check-out"

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

this.state = {
selectedMovie: "",
selectedCustomer: "",
selectedCustomerId: "",
}
}

setSelectedMovie = (title) => {
this.setState({
selectedMovie: title,
});
}

setSelectedCustomer = (name, id) => {
this.setState({
selectedCustomer: name,
selectedCustomerId: id,
});
}

makeRental = () => {
axios.post(URL + `?customer_id=${this.state.selectedCustomerId}&title=${this.state.selectedMovie}`)
.then((response) => {
this.setState({
notification: "Rental successfully added.",
selectedMovie: "",
selectedCustomer: "",
selectedCustomerId: "",
})
})
.catch((error) => {
this.setState({
notification: error.message
})
})
}

displayNotification = () => {
setTimeout(this.notificationTimer, 6000);
return this.state.notification
}

notificationTimer = () => {
this.setState({ notification: ""})
}

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>
<Router>
<article>
<section className="fixed-header">
<header>
<Link className="button" to="/">Search</Link>
<Link className="button" to="/library">Library</Link>
<Link className="button" to="/customers">Customers</Link>
<section className="movie-selection">
<p><strong>Selected Movie</strong></p>
<p>{this.state.selectedMovie}</p>
</section>
<section className="customer-selection">
<p><strong>Selected Customer</strong></p>
<p>{this.state.selectedCustomer}</p>
</section>
<button className="button" onClick={this.makeRental}>Make Rental</button>
</header>
<p className="notification">{this.displayNotification()}</p>
</section>

<section>
<Route exact path="/" component={SearchMovie} />
<Route exact path="/search" component={SearchMovie} />
<Route
path="/library"
render={(props) => <MovieCollection {...props} selectedMovieCallback={this.setSelectedMovie} />}
/>
<Route
path="/customers"
render={(props) => <CustomerCollection {...props} selectedCustomerCallback={this.setSelectedCustomer} />}
/>
</section>
</article>
</Router>
);
}

}

export default App;
22 changes: 22 additions & 0 deletions src/components/Customer.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.customer-container {
background-color: #f4f9f2;
display: flex;
flex-direction: column;
align-items: center;
padding: 2em;
margin: 1em 1em 0em 1em;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

.customer-container > p {
padding: .5em;
margin: 0px;
}

.card-header {
margin-top: 0px;
}

.customer-container > button {
margin-top: 1em;
}
33 changes: 33 additions & 0 deletions src/components/Customer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import css from './Customer.css';

class Customer extends Component {

static propTypes = {
name: PropTypes.string.isRequired,
phone: PropTypes.string.isRequired,
accountCredit: PropTypes.string.isRequired,
id: PropTypes.number,
checkedOutMoviesCount: PropTypes.number.isRequired,
selectedCustomerCallback: PropTypes.func.isRequired,
}

selectedCustomerCallback = () => {
this.props.selectedCustomerCallback(this.props.name, this.props.id);
}

render () {
return (
<article className="customer-container">
<h2 className="card-header">{this.props.name}</h2>
<p><strong>Phone:</strong> {this.props.phone}</p>
<p><strong>Account Credit:</strong> ${this.props.accountCredit}</p>
<p><strong>Checked Out Movies Count:</strong> {this.props.checkedOutMoviesCount}</p>
<button onClick={this.selectedCustomerCallback} >Select This Customer</button>
</article>
);
}
}

export default Customer;
6 changes: 6 additions & 0 deletions src/components/CustomerCollection.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.collection {
display: flex;
flex-flow: row wrap;
justify-content: center;
margin-top: 100px;
}
Loading