From c94970d2029ffc273dca0586d6808c0c27ccd995 Mon Sep 17 00:00:00 2001 From: ernietrevino Date: Tue, 28 Mar 2017 19:14:22 -0500 Subject: [PATCH] BookList --- advanced-final-project-starter | 1 + client/src/App.js | 77 ++++++++++++++++++++++++++++++++++ client/src/BookList.js | 26 ++++++++++++ client/src/book.js | 29 +++++++++++++ 4 files changed, 133 insertions(+) create mode 160000 advanced-final-project-starter create mode 100644 client/src/BookList.js create mode 100644 client/src/book.js diff --git a/advanced-final-project-starter b/advanced-final-project-starter new file mode 160000 index 0000000..47e2605 --- /dev/null +++ b/advanced-final-project-starter @@ -0,0 +1 @@ +Subproject commit 47e2605c33fe2279ced47dfa6d8641e89be87942 diff --git a/client/src/App.js b/client/src/App.js index d03f4a8..eb2f20e 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -1,13 +1,90 @@ import React, { Component } from 'react'; +import { BrowserRouter, Match, Miss } from 'react-router'; +import axios from 'axios'; +import './App.css'; +import SignUpSignIn from './SignUpSignIn'; +import TopNavbar from './TopNavbar'; +import Secret from './Secret'; +/* Before we started +import React, { Component } from 'react'; import { BrowserRouter, Route } from 'react-router-dom'; import './App.css'; import SignUpSignIn from './SignUpSignIn'; import TopNavbar from './TopNavbar'; import Secret from './Secret'; import axios from 'axios'; +*/ + + class App extends Component { + constructor() { + super(); + + this.state = { + signUpSignInError: '', + authenticated: localStorage.getItem('token') + }; + } + + handleSignUp(credentials) { + const { username, password, confirmPassword } = credentials; + if (!username.trim() || !password.trim() || password.trim() !== confirmPassword.trim()) { + this.setState({ + ...this.state, + signUpSignInError: 'Must Provide All Fields' + }); + } else { + axios.post('/api/signup', credentials) + .then(resp => { + const { token } = resp.data; + localStorage.setItem('token', token); + + this.setState({ + ...this.state, + signUpSignInError: '', + authenticated: token + }); + }); + } + } + + handleSignIn(credentials) { + // Handle Sign Up + const {username, password} = credentials; + } + + handleSignOut() { + localStorage.removeItem('token'); + this.setState({ + authenticated: false + }); + } + + renderSignUpSignIn() { + return + } + + renderApp() { + return ( +
+

I am protected!

} /> + +

NOT FOUND!

} /> +
+ ); + } + render() { + return ( + +
+ + {this.state.authenticated ? this.renderApp() : this.renderSignUpSignIn()} +
+
+ ); + } } export default App; diff --git a/client/src/BookList.js b/client/src/BookList.js new file mode 100644 index 0000000..d37023e --- /dev/null +++ b/client/src/BookList.js @@ -0,0 +1,26 @@ +import React, {Component} from 'react'; +import Book from './Book'; + +class BookList extends Component { + render() { + let val =
No movies here!
; + if (this.props.books.length) { + const books = this.props.books.map((book) => + + + ); + val =
+ + + {books} + +
+
; + } + return val; + } +} + +export default BookList; diff --git a/client/src/book.js b/client/src/book.js new file mode 100644 index 0000000..9d3134a --- /dev/null +++ b/client/src/book.js @@ -0,0 +1,29 @@ +import React, {Component} from 'react'; + +class Book extends Component { + render() { + let addButton = ''; + let removeButton = ''; + if (this.props.addable === "true") { + addButton = ; + } + else if (this.props.removeable === "true") { + removeButton = ; + } + return ( +
+ +
{this.props.title}
+
+ {addButton} + {removeButton} +
+ ); + } +} + +export default Book;