Added history API
This commit is contained in:
1803
package-lock.json
generated
1803
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,12 +1,13 @@
|
|||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"babel-cli": "^6.26.0",
|
||||||
|
"babel-preset-env": "^1.6.1",
|
||||||
|
"babel-preset-react": "^6.24.1",
|
||||||
|
"history": "^4.7.2",
|
||||||
"prop-types": "^15.5.8",
|
"prop-types": "^15.5.8",
|
||||||
"react": "^15.5.4",
|
"react": "^15.5.4",
|
||||||
"react-dom": "^15.5.4",
|
"react-dom": "^15.5.4",
|
||||||
"react-router-dom": "^4.2.2",
|
"react-router-dom": "^4.2.2",
|
||||||
"babel-cli": "^6.26.0",
|
|
||||||
"babel-preset-env": "^1.6.1",
|
|
||||||
"babel-preset-react": "^6.24.1",
|
|
||||||
"react-scripts": "0.9.5"
|
"react-scripts": "0.9.5"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
16
src/App.js
16
src/App.js
@@ -1,11 +1,15 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { BrowserRouter, Link, Route } from 'react-router-dom'
|
import { Router } from 'react-router-dom'
|
||||||
|
import { Link, Route } from 'react-router-dom'
|
||||||
// import * as BooksAPI from './BooksAPI'
|
// import * as BooksAPI from './BooksAPI'
|
||||||
import Bookshelf from './Bookshelf'
|
import Bookshelf from './Bookshelf'
|
||||||
|
import createHistory from 'history/createBrowserHistory'
|
||||||
import { getAll, search } from './BooksAPI'
|
import { getAll, search } from './BooksAPI'
|
||||||
import SearchPage from './SearchPage'
|
import SearchPage from './SearchPage'
|
||||||
import './App.css'
|
import './App.css'
|
||||||
|
|
||||||
|
export const history = createHistory();
|
||||||
|
|
||||||
class BooksApp extends React.Component {
|
class BooksApp extends React.Component {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -22,6 +26,11 @@ class BooksApp extends React.Component {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onResultSelect = (e) => {
|
||||||
|
console.log("onResultSelect")
|
||||||
|
this.history.push('/');
|
||||||
|
}
|
||||||
|
|
||||||
onSelectChange = (e) => {
|
onSelectChange = (e) => {
|
||||||
const id = e.target.name
|
const id = e.target.name
|
||||||
const newShelf = e.target.value
|
const newShelf = e.target.value
|
||||||
@@ -44,7 +53,7 @@ class BooksApp extends React.Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<BrowserRouter>
|
<Router history={history}>
|
||||||
|
|
||||||
<div className="app">
|
<div className="app">
|
||||||
|
|
||||||
@@ -59,6 +68,7 @@ class BooksApp extends React.Component {
|
|||||||
<SearchPage
|
<SearchPage
|
||||||
results={this.state.results}
|
results={this.state.results}
|
||||||
onSearch={this.onSearch}
|
onSearch={this.onSearch}
|
||||||
|
onSelect={this.onResultSelect}
|
||||||
/>
|
/>
|
||||||
)}/>
|
)}/>
|
||||||
|
|
||||||
@@ -68,7 +78,7 @@ class BooksApp extends React.Component {
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</BrowserRouter>
|
</Router>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ class SearchPage extends Component {
|
|||||||
|
|
||||||
const onSearch = this.props.onSearch
|
const onSearch = this.props.onSearch
|
||||||
const results = this.props.results
|
const results = this.props.results
|
||||||
|
const onSelect = this.props.onSelect
|
||||||
|
|
||||||
console.log("RESULTS", results)
|
console.log("RESULTS", results)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -31,7 +33,7 @@ class SearchPage extends Component {
|
|||||||
<div className="book-top">
|
<div className="book-top">
|
||||||
<div className="book-cover" style={{ width: 128, height: 193, backgroundImage: `url("${ result.imageLinks.thumbnail }")` }}></div>
|
<div className="book-cover" style={{ width: 128, height: 193, backgroundImage: `url("${ result.imageLinks.thumbnail }")` }}></div>
|
||||||
<div className="book-shelf-changer">
|
<div className="book-shelf-changer">
|
||||||
<select name={result.id}>
|
<select name={result.id} onChange={onSelect}>
|
||||||
<option value="none">Move to...</option>
|
<option value="none">Move to...</option>
|
||||||
<option value="currentlyReading">Currently Reading</option>
|
<option value="currentlyReading">Currently Reading</option>
|
||||||
<option value="wantToRead">Want to Read</option>
|
<option value="wantToRead">Want to Read</option>
|
||||||
|
|||||||
Reference in New Issue
Block a user