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

Branches - Emily and Mira #18

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
49009b3
files for components + listing customers
eaball35 Dec 16, 2019
987f4b2
moved api calls to app.js and added movieslist component
eaball35 Dec 16, 2019
15da082
nav, home, and proptypes
eaball35 Dec 17, 2019
cb07b2e
added styling to tables, added additional customer/movie props
eaball35 Dec 17, 2019
7dfcc97
nav bar styling
eaball35 Dec 17, 2019
2fc7eed
minor update - forgot to delete css file we don't need
eaball35 Dec 17, 2019
c337e17
last removal from uneccesary nav css
eaball35 Dec 17, 2019
a320502
Merge pull request #1 from eaball35/emily-consumer-branch
calopter Dec 17, 2019
4e4f2c0
changed movies to cards, cleaned up props
eaball35 Dec 17, 2019
25ea563
refactor customer to cards
calopter Dec 17, 2019
ad68ea3
Merge pull request #2 from eaball35/emily-consumer-branch
calopter Dec 17, 2019
538d056
select customer and movie, display in checkout
calopter Dec 17, 2019
6c4b6e3
conditionally render movie and customer cards in checkout
calopter Dec 17, 2019
473feee
layout css
calopter Dec 17, 2019
6f1b44a
conditional rendering for checkout
calopter Dec 17, 2019
6c69ab7
sticky
calopter Dec 17, 2019
bdee426
refactor to functional
calopter Dec 17, 2019
1402a22
formatting and props fixes
calopter Dec 17, 2019
e29e57b
added checkout button
eaball35 Dec 18, 2019
81950d1
checkout styling
eaball35 Dec 18, 2019
b31b81b
checkout styling
eaball35 Dec 18, 2019
cd45aa4
error/success message alert
eaball35 Dec 18, 2019
544020f
fixed warnings, imports, prop types
eaball35 Dec 18, 2019
63a2b0e
Merge pull request #3 from eaball35/checkout
calopter Dec 18, 2019
ab2485c
create search component and route
calopter Dec 18, 2019
0c380e9
basic search functionality
calopter Dec 18, 2019
1006b7d
Merge branch 'master' into search
calopter Dec 18, 2019
3f1ebfb
add movie to library
calopter Dec 18, 2019
34e5e5a
messages on adding to lib
calopter Dec 18, 2019
b86c3e6
reset messages on timer
calopter Dec 18, 2019
e0ec1ee
remove selected from checkout
calopter Dec 18, 2019
a92a180
check for duplicates in lib when adding
calopter Dec 18, 2019
f82aaf5
fix button text for search
calopter Dec 18, 2019
e30970f
Merge pull request #4 from eaball35/search
calopter Dec 18, 2019
6342447
css styling
eaball35 Dec 19, 2019
9735cc3
updated home
eaball35 Dec 19, 2019
73619d5
styling:
eaball35 Dec 19, 2019
a20ef58
Merge pull request #5 from eaball35/wed-styling
calopter Dec 20, 2019
e919ee5
remove extra click listener
calopter Dec 20, 2019
1e6091c
added links and moved router around app
eaball35 Dec 20, 2019
3b1aa58
Merge branch 'master' of https://github.com/eaball35/video-store-cons…
eaball35 Dec 20, 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
7,229 changes: 4,276 additions & 2,953 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 19 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,30 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1"
"axios": "^0.19.0",
"bootstrap": "^4.4.1",
"react": "^16.12.0",
"react-bootstrap": "^1.0.0-beta.16",
"react-dom": "^16.12.0",
"react-router-dom": "^5.1.2",
"react-scripts": "^3.3.0"
},
"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"
]
}
}
118 changes: 103 additions & 15 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,28 +1,116 @@
@import url('https://fonts.googleapis.com/css?family=Lato&display=swap');

.App {
display: grid;
grid-template: 3fr 1fr;
font-family: 'Lato', sans-serif;
background-color: rgb(63, 80, 114);
}

.App-header {
grid-column-start: span 2;
text-align: center;
padding: 1%;
background-color: white;
}

.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 80px;
.checkout {
grid-row: auto / span 2;
background-color: rgb(201, 201, 201);
min-height: 100vh;
min-width: 30vw;
}

.App-header {
background-color: #222;
height: 150px;
padding: 20px;
color: white;
.checkout h2 {
text-align: center;
margin-bottom: 5%;
margin-top: 5%;
text-align: center;
}

.checkout h4 {
margin: 5%;
margin-top: 0;
}

.App-title {
font-size: 1.5em;
.checkout-customer .card, .checkout-customer p, .checkout-movie .card, .checkout-movie p {
max-width: 90%;
margin-bottom: 3%;
text-align: center;
}

.App-intro {
font-size: large;
.checkout-movie, .checkout-customer, .checkout-btn {
display: flex;
justify-content: center;
}

@keyframes App-logo-spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
.checkout-btn {
margin-bottom: 2em;
}

.navbar {
grid-column-start: span 2;
font-size: 1.5rem;
}

.navbar li {
margin-left: 2rem;
margin-right: 2rem;
}

.card {
width: 14rem;
padding: 1em;
padding-bottom: 0em;
margin: 1.5%;
text-align: center;
}

.cards-container {
padding-top: .5rem;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
}

.homepage, .searchpage, .moviepage, .customerpage {
min-width: 70vw;
}

.homepage {
display: flex;
justify-content: center;
}

.homepage header {
margin-top: 5%;
margin-bottom: 5%;
text-align: center;
color: white;
max-width: 90%;
}

.searchpage {
padding-left: 3rem;
padding-right: 3rem;
text-align: center;
}

.search-bar {
background: #fff;
padding: 1em;
width: 95%;
border-radius: 10em;
transition: box-shadow 300ms ease;
border-radius: 6px;
border: 1px solid rgba(137, 149, 199, .2);
box-shadow: inset 0 2px 0 0 rgba(0, 0, 0, .075) !important;
margin-right: 10px;
margin-bottom: 2rem;
}

.searchpage h2 {
color: white;
padding: 1rem;
}
168 changes: 160 additions & 8 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,171 @@
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import Nav from './components/Nav';
import Checkout from './components/Checkout';
import MovieList from './components/MovieList';
import CustomerList from './components/CustomerList';
import Search from './components/Search';
import Home from './components/Home';
import axios from 'axios';
import 'bootstrap/dist/css/bootstrap.min.css';
import {
BrowserRouter as Router,
Switch,
Route,
Link
} from "react-router-dom";

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

this.state = {
customers: [],
movies: [],
messages: {},
currentCustomer: '',
currentMovie: '',
};
}

componentDidMount() {
this.fetchCustomers();
this.fetchMovies();
}

fetchMovies() {
axios.get('http://localhost:3000/movies')
.then((response) => {
this.setState({
movies: response.data
})
})
.catch((error) => {
this.setState({
errors: error
});
});
}

fetchCustomers() {
axios.get('http://localhost:3000/customers')
.then((response) => {
this.setState({
customers: response.data
})
})
.catch((error) => {
this.setState({
messages: {error}
});
});
}

onCheckout = () => {
const params = {customer_id: this.state.currentCustomer.id,
due_date: '20-1-1' }

axios.post(`http://localhost:3000/rentals/${this.state.currentMovie.title}/check-out`, params)
.then((response) => {
this.setState({
messages: {success: `${this.state.currentCustomer.name} successfully checked out ${this.state.currentMovie.title}!`},
currentCustomer: '',
currentMovie: '',
})
this.resetMessages()
})
.catch((error) => {
this.setState({
messages: {error: 'Please select both a customer and a movie to checkout.'},
});
this.resetMessages()
});
}

onSelect = (selected) => {
if (selected.title) {
this.setState({currentMovie: selected})
}
else if (selected.name) {
this.setState({currentCustomer: selected})
}
}

onRemove = (toRemove) => {
if (toRemove.title) {
this.setState({currentMovie: ''})
}
else if (toRemove.name) {
this.setState({currentCustomer: ''})
}
}

onAddToLib = (movie) => {
if (this.state.movies.find(({external_id}) => external_id === movie.external_id)) {
this.setState({
messages: {error: `${movie.title} is already in the library`}
})
this.resetMessages();
return;
}
axios.post('http://localhost:3000/movies', {movie})
.then(response => {
const movies = [...this.state.movies]
movies.push(movie)
this.setState({movies, messages: { success: `${movie.title} added to library` }})
this.resetMessages();
}).catch(console.log)
}

messages = () => {
if (this.state.messages) {
if (this.state.messages.success) {
return <div className="alert alert-success" role="alert"> {this.state.messages.success} </div>
} else if (this.state.messages.error) {
return <div className="alert alert-danger" role="alert"> {this.state.messages.error} </div>
}
}
}

resetMessages = () => {
setTimeout(() => this.setState({messages: {}}), 4000)
}

render() {
const { movies, customers, currentCustomer, currentMovie, messages } = this.state
return (
<div className="App">
<section className="App">
<Router>
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h1 className="App-title">Welcome to React</h1>
<img src='https://live.staticflickr.com/65535/49240969981_a84cd27b76_m.jpg'alt='Movie Rentalz'/>
{this.messages()}
</header>
<p className="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p>
</div>
<Nav onSelect={this.onSelect}
onAddToLib={this.onAddToLib}
movies={movies}
customers={customers}
messages={messages}/>
<Checkout movie={currentMovie}
customer={currentCustomer}
onCheckout={this.onCheckout}
onRemove={this.onRemove}/>

<Switch>
<Route path="/library">
<MovieList className='list' onSelect={this.onSelect} movies={this.state.movies} buttonText='Select'/>
</Route>
<Route path="/customers">
<CustomerList className='list' onSelect={this.onSelect} customers={this.state.customers} />
</Route>
<Route path="/search">
<Search onAddToLib={this.onAddToLib}/>
</Route>
<Route path="/">
<Home />
</Route>
</Switch>
</Router>
</section>
);
}
}
Expand Down
Loading