GoogleBookSearch/client/package.json
{
"name": "google-books",
"version": "0.1.0",
"description": "Google Books",
"private": true,
"proxy": "http:
localhost:3001/",
"dependencies": {
"react": "^16.6.3",
"react-dom": "^16.6.3",
"react-scripts": "^2.1.1",
"react-router-dom": "^5.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"
owserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
GoogleBookSearch/client/public/images/mern.jpg
GoogleBookSearch/client/public/images/screenshot.gif
GoogleBookSearch/client/public/images/screenshot.png
GoogleBookSearch/client/public/index.html
You need to enable JavaScript to run this app.
GoogleBookSearch/client/public/manifest.json
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
GoogleBookSearch/client/src/App.css
.App {
text-align: center;
}
.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 40vmin;
pointer-events: none;
}
.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
GoogleBookSearch/client/src/App.js
import React, { Component } from "react";
import { BrowserRouter as Router, Route } from "react-router-dom";
import NavBar from "./components/NavBar";
import Header from "./components/Header";
import Wrapper from "./components/Wrapper";
import NoMatch from "./pages/NoMatch";
import Search from "./pages/Search";
import Saved from "./pages/Saved";
import "./App.css";
class App extends Component {
render() {
return (
Wrappe
div
Route
)
};
};
export default App;
GoogleBookSearch/client/src/App.test.js
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(
, div);
ReactDOM.unmountComponentAtNode(div);
});
GoogleBookSearch/client/src/components/Form/index.js
import React from "react";
function Form(props){
eturn (
Search for and save Books of Interest
h2
label
onChange={props.handleInputChange}
value={props.search}
name="search"
type="text"
className="form-control"
placeholder="Search a Book"
id="search"
utton onClick={props.handleFormSubmit} className="btn btn-dark mt-3 mb-5"
Search
utton
div
form
div
);
}
export default Form;
GoogleBookSearch/client/src/components/Heade
index.js
import React from "react";
import style from "./style.css";
function Header() {
return (
Google Books Search
h1
div
div
);
}
export default Header;
GoogleBookSearch/client/src/components/Heade
li
ary.png
GoogleBookSearch/client/src/components/Heade
style.css
.jumbotron .text-light{
color: #0c5460 !important;
}
.jumbotron{ background-color:#fff !important;
padding-top: 1% !important;
padding-bottom: 0px !important;}
.search {
border:1px solid #dee2e6;
border-radius:5px;
padding:2%;
margin-bottom:2%;
}
.result {
border:1px solid #dee2e6;
border-radius:5px;
padding:2%;
margin-bottom:2%;
}
.search .btn{background-color:#0c5460;}
.search h2{color:#0c5460;}
GoogleBookSearch/client/src/components/NavBa
index.js
import React from "react";
import { Link } from "react-router-dom";
import "./style.css";
function Navbar() {
return (
Google Books
Link
to="/search"
className={window.location.pathname === "/search" ? "nav-link active" : "nav-link"}
> Search
Link
li
to="/saved"
className={window.location.pathname === "/saved" ? "nav-link active" : "nav-link"}
>Saved
Link
li
ul
div
nav
);
}
export default Navbar;
GoogleBookSearch/client/src/components/NavBa
style.css
nav {
background-color: #0c5460;
}
a {
text-decoration: none;
color: white
}
a:hover {
text-decoration: underline;
color: white
}
.navbar-
and {
font-size: 35px;
}
.nav-item {
font-size: 25px;
}
.nav-link:hover {
background-color:#fff;
color:#0c5460;
}
GoogleBookSearch/client/src/components/Results/index.js
import React, { Component } from "react";
import API from "../../utils/API";
class Results extends Component {
state = {
savedBooks: [],
}
componentDidMount() {
API.savedBooks()
.then(savedBooks => this.setState({ savedBooks: savedBooks }))
.catch(e
=> console.e
or(e
));
}
handleSave = book => {
if (this.state.savedBooks.map(book => book._id).includes(book._id)) {
API.deleteBook(book._id)
.then(deletedBook => this.setState({ savedBooks: this.state.savedBooks.filter(book => book._id !== deletedBook._id) }))
.catch(e
=> console.e
or(e
));
} else {
API.saveBook(book)
.then(savedBook => this.setState({ savedBooks: this.state.savedBooks.concat([savedBook]) }))
.catch(e
=> console.e
or(e
));
}
}
render() {
return (
{!this.props.books.length ? (
No Results to Display
h1
) : (
{this.props.books.map(result => (
...