diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 2923eaa1c0..0000000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,3 +0,0 @@ -# How to contribute - -The files in this repository are used in the course videos and are the starting point for all students. Because we want all students to have the same experience going through course, if your pull request alters any of the core files, then it (most likely) will _not_ be merged into the project. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000..010d60e6de --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Nenne 'Adora' Nwodo + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index ce4ea2eb85..690082182b 100644 --- a/README.md +++ b/README.md @@ -1,92 +1,53 @@ # MyReads Project -This is the starter template for the final assessment project for Udacity's React Fundamentals course. The goal of this template is to save you time by providing a static example of the CSS and HTML markup that may be used, but without any of the React code that is needed to complete the project. If you choose to start with this template, your job will be to add interactivity to the app by refactoring the static code in this template. - -Of course, you are free to start this project from scratch if you wish! Just be sure to use [Create React App](https://github.com/facebookincubator/create-react-app) to bootstrap the project. - -## TL;DR - -To get started developing right away: - -* install all project dependencies with `npm install` -* start the development server with `npm start` - -## What You're Getting -```bash -├── CONTRIBUTING.md -├── README.md - This file. -├── SEARCH_TERMS.md # The whitelisted short collection of available search terms for you to use with your app. -├── package.json # npm package manager file. It's unlikely that you'll need to modify this. -├── public -│   ├── favicon.ico # React Icon, You may change if you wish. -│   └── index.html # DO NOT MODIFY -└── src - ├── App.css # Styles for your app. Feel free to customize this as you desire. - ├── App.js # This is the root of your app. Contains static HTML right now. - ├── App.test.js # Used for testing. Provided with Create React App. Testing is encouraged, but not required. - ├── BooksAPI.js # A JavaScript API for the provided Udacity backend. Instructions for the methods are below. - ├── icons # Helpful images for your app. Use at your discretion. - │   ├── add.svg - │   ├── arrow-back.svg - │   └── arrow-drop-down.svg - ├── index.css # Global styles. You probably won't need to change anything here. - └── index.js # You should not need to modify this file. It is used for DOM rendering only. -``` - -Remember that good React design practice is to create new JS files for each component and use import/require statements to include them where they are needed. - -## Backend Server - -To simplify your development process, we've provided a backend server for you to develop against. The provided file [`BooksAPI.js`](src/BooksAPI.js) contains the methods you will need to perform necessary operations on the backend: - -* [`getAll`](#getall) -* [`update`](#update) -* [`search`](#search) - -### `getAll` - -Method Signature: - -```js -getAll() -``` - -* Returns a Promise which resolves to a JSON object containing a collection of book objects. -* This collection represents the books currently in the bookshelves in your app. - -### `update` - -Method Signature: - -```js -update(book, shelf) -``` - -* book: `` containing at minimum an `id` attribute -* shelf: `` contains one of ["wantToRead", "currentlyReading", "read"] -* Returns a Promise which resolves to a JSON object containing the response data of the POST request - -### `search` - -Method Signature: - -```js -search(query) -``` - -* query: `` -* Returns a Promise which resolves to a JSON object containing a collection of a maximum of 20 book objects. -* These books do not know which shelf they are on. They are raw results only. You'll need to make sure that books have the correct state while on the search page. - -## Important -The backend API uses a fixed set of cached search results and is limited to a particular set of search terms, which can be found in [SEARCH_TERMS.md](SEARCH_TERMS.md). That list of terms are the _only_ terms that will work with the backend, so don't be surprised if your searches for Basket Weaving or Bubble Wrap don't come back with any results. - -## Create React App - -This project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app). You can find more information on how to perform common tasks [here](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md). - -## Contributing - -This repository is the starter code for _all_ Udacity students. Therefore, we most likely will not accept pull requests. - -For details, check out [CONTRIBUTING.md](CONTRIBUTING.md). +MyReads is an app built with Reactjs to track a users books. A book on the shelf can be in any of these 3 categories: + + 1. Want to Read + 2. Currently Reading + 3. Read + +The application consists of two pages. + 1. **Home Page** : The Home Page consists of all the books currently in your shelf. Here you can move books between the 3 categories mentioned above or completely take them off your shelf. + + + + 2. **Search Page** : The Search Page consists of a search input where users can type in a search query and books that match the query will be returned. If there are no matching books, an appropriate error message is shown. Users can add search results to their homepage and if the search result is already on the shelf, users can move between shelves or completely take the book off the shelf. + + + + + + + # Installation + + Step 1: Clone this project + ```git clone https://github.com/AdoraNwodo/reactnd-project-myreads-starter.git``` + + Step 2: Install all project dependencies (via npm) + ```npm install``` + + Step 3: Start the development server + ```npm start``` + + **N.B: Internet access is important for the search page to work as the API is not hosted locally** + + + + + # Security + +If you discover any security related issues, please email nennenwodo@gmail.com instead of using the issue tracker. + + + + + # Credits + +Udacity React Nanodegree ❤️❤️ + + + + + # License + +MIT. Please see the [license file](LICENSE) for more information. diff --git a/home1.png b/home1.png new file mode 100644 index 0000000000..e22e545164 Binary files /dev/null and b/home1.png differ diff --git a/home2.png b/home2.png new file mode 100644 index 0000000000..8c793afcaf Binary files /dev/null and b/home2.png differ diff --git a/package-lock.json b/package-lock.json index 91581f4c35..a60d204df4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6175,6 +6175,28 @@ "resolved": "https://registry.npmjs.org/hex-color-regex/-/hex-color-regex-1.1.0.tgz", "integrity": "sha512-l9sfDFsuqtOqKDsQdqrMRk0U85RZc0RtOR9yPI7mRVOa4FsR/BVnZ0shmQRM96Ji99kYZP/7hn1cedc1+ApsTQ==" }, + "history": { + "version": "4.7.2", + "resolved": "https://registry.npmjs.org/history/-/history-4.7.2.tgz", + "integrity": "sha512-1zkBRWW6XweO0NBcjiphtVJVsIQ+SXF29z9DVkceeaSLVMFXHool+fdCZD4spDCfZJCILPILc3bm7Bc+HRi0nA==", + "requires": { + "invariant": "^2.2.1", + "loose-envify": "^1.2.0", + "resolve-pathname": "^2.2.0", + "value-equal": "^0.4.0", + "warning": "^3.0.0" + }, + "dependencies": { + "warning": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/warning/-/warning-3.0.0.tgz", + "integrity": "sha1-MuU3fLVy3kqwR1O9+IIcAe1gW3w=", + "requires": { + "loose-envify": "^1.0.0" + } + } + } + }, "hmac-drbg": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", @@ -6190,6 +6212,11 @@ "resolved": "http://registry.npmjs.org/hoek/-/hoek-4.2.1.tgz", "integrity": "sha512-QLg82fGkfnJ/4iy1xZ81/9SIJiq1NGFUMGs6ParyjBZr6jW2Ufj/snDqTHixNlHdPNwN2RLVD0Pi3igeK9+JfA==" }, + "hoist-non-react-statics": { + "version": "2.5.5", + "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-2.5.5.tgz", + "integrity": "sha512-rqcy4pJo55FTTLWt+bU8ukscqHeE/e9KWvsOW2b/a3afxQZhwkQdT1rPPCJ0rYXdj4vNcasY8zHTH+jF/qStxw==" + }, "home-or-tmp": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/home-or-tmp/-/home-or-tmp-2.0.0.tgz", @@ -11222,6 +11249,48 @@ "resolved": "https://registry.npmjs.org/react-error-overlay/-/react-error-overlay-5.1.0.tgz", "integrity": "sha512-akMy/BQT5m1J3iJIHkSb4qycq2wzllWsmmolaaFVnb+LPV9cIJ/nTud40ZsiiT0H3P+/wXIdbjx2fzF61OaeOQ==" }, + "react-router": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/react-router/-/react-router-4.3.1.tgz", + "integrity": "sha512-yrvL8AogDh2X42Dt9iknk4wF4V8bWREPirFfS9gLU1huk6qK41sg7Z/1S81jjTrGHxa3B8R3J6xIkDAA6CVarg==", + "requires": { + "history": "^4.7.2", + "hoist-non-react-statics": "^2.5.0", + "invariant": "^2.2.4", + "loose-envify": "^1.3.1", + "path-to-regexp": "^1.7.0", + "prop-types": "^15.6.1", + "warning": "^4.0.1" + }, + "dependencies": { + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=" + }, + "path-to-regexp": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.7.0.tgz", + "integrity": "sha1-Wf3g9DW62suhA6hOnTvGTpa5k30=", + "requires": { + "isarray": "0.0.1" + } + } + } + }, + "react-router-dom": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-4.3.1.tgz", + "integrity": "sha512-c/MlywfxDdCp7EnB7YfPMOfMD3tOtIjrQlj/CKfNMBxdmpJP8xcz5P/UAFn3JbnQCNUxsHyVVqllF9LhgVyFCA==", + "requires": { + "history": "^4.7.2", + "invariant": "^2.2.4", + "loose-envify": "^1.3.1", + "prop-types": "^15.6.1", + "react-router": "^4.3.1", + "warning": "^4.0.1" + } + }, "react-scripts": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/react-scripts/-/react-scripts-2.1.1.tgz", @@ -11880,6 +11949,11 @@ "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-3.0.0.tgz", "integrity": "sha1-six699nWiBvItuZTM17rywoYh0g=" }, + "resolve-pathname": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/resolve-pathname/-/resolve-pathname-2.2.0.tgz", + "integrity": "sha512-bAFz9ld18RzJfddgrO2e/0S2O81710++chRMUxHjXOYKF6jTAMrUNZrEZ1PvV0zlhfjidm08iRPdTLPno1FuRg==" + }, "resolve-url": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/resolve-url/-/resolve-url-0.2.1.tgz", @@ -13857,6 +13931,11 @@ "spdx-expression-parse": "^3.0.0" } }, + "value-equal": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/value-equal/-/value-equal-0.4.0.tgz", + "integrity": "sha512-x+cYdNnaA3CxvMaTX0INdTCN8m8aF2uY9BvEqmxuYp8bL09cs/kWVQPVGcA35fMktdOsP69IgU7wFj/61dJHEw==" + }, "vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", @@ -13911,6 +13990,14 @@ "makeerror": "1.0.x" } }, + "warning": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/warning/-/warning-4.0.2.tgz", + "integrity": "sha512-wbTp09q/9C+jJn4KKJfJfoS6VleK/Dti0yqWSm6KMvJ4MRCXFQNapHuJXutJIrWV0Cf4AhTdeIe4qdKHR1+Hug==", + "requires": { + "loose-envify": "^1.0.0" + } + }, "watch": { "version": "0.18.0", "resolved": "https://registry.npmjs.org/watch/-/watch-0.18.0.tgz", diff --git a/package.json b/package.json index 579d515885..d26ea5d1ff 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "prop-types": "^15.6.2", "react": "^16.6.3", "react-dom": "^16.6.3", + "react-router-dom": "^4.3.1", "react-scripts": "2.1.1" }, "scripts": { diff --git a/search1.png b/search1.png new file mode 100644 index 0000000000..70aea8fc19 Binary files /dev/null and b/search1.png differ diff --git a/search2.png b/search2.png new file mode 100644 index 0000000000..198115293b Binary files /dev/null and b/search2.png differ diff --git a/src/App.css b/src/App.css index 28960adf8f..88ad7d0dd7 100644 --- a/src/App.css +++ b/src/App.css @@ -1,9 +1,12 @@ +@import url('https://fonts.googleapis.com/css?family=Raleway|Work+Sans:700'); + html, body, .root { height: 100%; } body { line-height: 1.5; + font-family: 'Raleway', sans-serif !important; } body, .app { @@ -14,14 +17,18 @@ body, .app { .list-books-title { padding: 10px 0; - background: #2e7c31; + background: #c6edf7; text-align: center; } .list-books-title h1 { font-weight: 400; + font-family: 'Work Sans', sans-serif; + font-weight: 700; + text-transform: uppercase; + letter-spacing: 3px; margin: 0; - color: white; + color: black; } .list-books-content { @@ -41,6 +48,9 @@ body, .app { .bookshelf-title { border-bottom: 1px solid #dedede; + text-align: center; + font-size: 20px; + } .bookshelf-books { @@ -53,12 +63,12 @@ body, .app { bottom: 25px; } -.open-search button { +.open-search a { display: block; width: 50px; height: 50px; border-radius: 50%; - background: #2e7d32; + background: #c6edf7; background-image: url('./icons/add.svg'); background-repeat: no-repeat; background-position: center; @@ -106,6 +116,7 @@ body, .app { height: 53px; background-image: url('./icons/arrow-back.svg'); background-position: center; + background-color: white; background-repeat: no-repeat; background-size: 28px; font-size: 0; @@ -169,7 +180,7 @@ button:active { width: 40px; height: 40px; border-radius: 50%; - background: #60ac5d; + background: #000000; background-image: url('./icons/arrow-drop-down.svg'); background-repeat: no-repeat; background-position: center; @@ -196,3 +207,11 @@ button:active { text-align: center; font-size: 0.8em; } + +/* Handle empty search results */ +.no-results-div p{ + text-align: center; + padding-top: 25vh; + font-size: 30px; + color: #999; +} diff --git a/src/App.js b/src/App.js index 785820d5df..e00f3bd894 100644 --- a/src/App.js +++ b/src/App.js @@ -1,203 +1,59 @@ import React from 'react' -// import * as BooksAPI from './BooksAPI' +import * as BooksAPI from './BooksAPI' import './App.css' +import { BrowserRouter as Router, Route } from 'react-router-dom' +import Main from './Main' +import Search from './Search' class BooksApp extends React.Component { state = { - /** - * TODO: Instead of using this state variable to keep track of which page - * we're on, use the URL in the browser's address bar. This will ensure that - * users can use the browser's back and forward buttons to navigate between - * pages, as well as provide a good URL they can bookmark and share. - */ - showSearchPage: false + showSearchPage: false, + books:[] } - render() { - return ( -
- {this.state.showSearchPage ? ( -
-
- -
- {/* - NOTES: The search from BooksAPI is limited to a particular set of search terms. - You can find these search terms here: - https://github.com/udacity/reactnd-project-myreads-starter/blob/master/SEARCH_TERMS.md + componentDidMount(){ + BooksAPI.getAll() + .then((books) => { + //console.log(books); + this.setState(() => ({ + books + })) + }) + } + + updateShelf = (book, shelf) => { - However, remember that the BooksAPI.search method DOES search by title or author. So, don't worry if - you don't find a specific author or title. Every search is limited by search terms. - */} - + BooksAPI.update(book, shelf) + .then((result) => { + //update frontend once book is updated from API + book.shelf = shelf + this.setState((currentState) => ({ + books: currentState.books.filter((x) => { + return x.id !== book.id + }).concat([book]) + })) -
-
-
-
    -
    -
    - ) : ( -
    -
    -

    MyReads

    -
    -
    -
    -
    -

    Currently Reading

    -
    -
      -
    1. -
      -
      -
      -
      - -
      -
      -
      To Kill a Mockingbird
      -
      Harper Lee
      -
      -
    2. -
    3. -
      -
      -
      -
      - -
      -
      -
      Ender's Game
      -
      Orson Scott Card
      -
      -
    4. -
    -
    -
    -
    -

    Want to Read

    -
    -
      -
    1. -
      -
      -
      -
      - -
      -
      -
      1776
      -
      David McCullough
      -
      -
    2. -
    3. -
      -
      -
      -
      - -
      -
      -
      Harry Potter and the Sorcerer's Stone
      -
      J.K. Rowling
      -
      -
    4. -
    -
    -
    -
    -

    Read

    -
    -
      -
    1. -
      -
      -
      -
      - -
      -
      -
      The Hobbit
      -
      J.R.R. Tolkien
      -
      -
    2. -
    3. -
      -
      -
      -
      - -
      -
      -
      Oh, the Places You'll Go!
      -
      Seuss
      -
      -
    4. -
    5. -
      -
      -
      -
      - -
      -
      -
      The Adventures of Tom Sawyer
      -
      Mark Twain
      -
      -
    6. -
    -
    -
    -
    -
    -
    - -
    -
    - )} + }) + } + render() { + return ( +
    + +
    + ( +
    + )} /> + ( + + )} /> +
    +
    ) } diff --git a/src/Book.js b/src/Book.js new file mode 100644 index 0000000000..763ab6d132 --- /dev/null +++ b/src/Book.js @@ -0,0 +1,56 @@ +import React, { Component } from 'react' +import PropTypes from 'prop-types' + +class Book extends Component { + + static propTypes = { + book: PropTypes.object.isRequired, + onUpdateShelf: PropTypes.func.isRequired + } + + render() { + + const { onUpdateShelf, book } = this.props + + return( +
  1. +
    +
    + { + //show thumbnail of book exists. If it doesn't show a gray background + book.imageLinks !== undefined ? +
    + :
    + } +
    + + +
    +
    +
    {book.title}
    +
    + { + + book.authors !== undefined && + book.authors.map((author, i) => ( + book.authors.length - 1 !== i ? author + ", " : author + )) + + } +
    + +
    +
  2. + ) + + } + +} + +export default Book \ No newline at end of file diff --git a/src/Main.js b/src/Main.js new file mode 100644 index 0000000000..f1af6154d9 --- /dev/null +++ b/src/Main.js @@ -0,0 +1,102 @@ +import React, { Component } from 'react' +import PropTypes from 'prop-types' +//import * as BooksAPI from './BooksAPI' +import { Link } from 'react-router-dom' +import Book from './Book' + +class Main extends Component { + static propTypes = { + books: PropTypes.array.isRequired, + onUpdateShelf: PropTypes.func.isRequired + } + render() { + + const { books, onUpdateShelf } = this.props + + const currentlyReading = books.filter((book) => ( + book.shelf === "currentlyReading" + )) + const wantToRead = books.filter((book) => ( + book.shelf === "wantToRead" + )) + const read = books.filter((book) => ( + book.shelf === "read" + )) + + return ( +
    +
    +
    +

    MyReads

    +
    +
    +
    + { currentlyReading.length > 0 && + //Display only if there are books on the "currentlyReading" shelf +
    +

    Currently Reading

    +
    +
      + { currentlyReading.map((book) => ( + + ))} +
    +
    +
    + } + + { wantToRead.length > 0 && + //Display only if there are books on the "wantToRead" shelf +
    +

    Want to Read

    +
    +
      + { wantToRead.map((book) => ( + + ))} +
    +
    +
    + } + + { wantToRead.length > 0 && + //Display only if there are books on the "wantToRead" shelf +
    +

    Read

    +
    +
      + { read.map((book) => ( + + ))} +
    +
    +
    + } +
    +
    +
    + + Add a book + +
    +
    +
    + ) + } + +} + +export default Main \ No newline at end of file diff --git a/src/Search.js b/src/Search.js new file mode 100644 index 0000000000..29c51c3de8 --- /dev/null +++ b/src/Search.js @@ -0,0 +1,139 @@ +import React, { Component } from 'react' +import * as BooksAPI from './BooksAPI' +import PropTypes from 'prop-types' +import { Link } from 'react-router-dom' + +class Search extends Component { + static propTypes = { + books: PropTypes.array.isRequired, + onUpdateShelf: PropTypes.func.isRequired + } + + state = { + results: [], + query: '' + } + + updateResult = (result) => { + this.setState(() => ({ + results: result + })) + } + + updateQuery = (q) => { + this.setState(() => ({ + query: q + })) + } + + searchBooks = (query) => { + + this.updateResult([]) + this.updateQuery(query) + //reset state on every search. That's how I could get search to work properly + + if(query.trim().length > 0){ + + BooksAPI.search(query) + .then((results) => { + //console.log(results) + this.updateResult(results) + + }) + + }else{ + this.updateResult([]) + } + + } + + render() { + + const { onUpdateShelf, books } = this.props + + const { results, query } = this.state + + return ( +
    +
    + + Close + +
    + + this.searchBooks(event.target.value)} + /> + +
    +
    +
    +
      + { + //Show only if results are returned and there is a valid query string + results.length > 0 && + query.length > 0 && + results.map((book) => ( +
    1. +
      +
      + { + book.imageLinks !== undefined ? +
      + :
      + } +
      + +
      +
      +
      {book.title}
      +
      + { + book.authors !== undefined && + book.authors.map((author, i) => ( + book.authors.length - 1 !== i ? author + ", " : author + )) + } +
      + +
      +
    2. + )) + } +
    + + { + //Show only if results are not returned + results.error === "empty query" && +
    +

    No Results

    +
    + + } +
    +
    + ) + } +} + +export default Search \ No newline at end of file diff --git a/src/icons/add.svg b/src/icons/add.svg index ed289e430b..ccca374424 100644 --- a/src/icons/add.svg +++ b/src/icons/add.svg @@ -1,3 +1,3 @@ - +