diff --git a/.gitignore b/.gitignore index fd4f2b066b..f1321553eb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules .DS_Store +.vscode/ diff --git a/package-lock.json b/package-lock.json index 91581f4c35..6e4fcb508a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5387,7 +5387,8 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true + "bundled": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -5405,11 +5406,13 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true + "bundled": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -5422,15 +5425,18 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "concat-map": { "version": "0.0.1", - "bundled": true + "bundled": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -5533,7 +5539,8 @@ }, "inherits": { "version": "2.0.3", - "bundled": true + "bundled": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -5543,6 +5550,7 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -5555,17 +5563,20 @@ "minimatch": { "version": "3.0.4", "bundled": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true + "bundled": true, + "optional": true }, "minipass": { "version": "2.2.4", "bundled": true, + "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -5582,6 +5593,7 @@ "mkdirp": { "version": "0.5.1", "bundled": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -5654,7 +5666,8 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true + "bundled": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -5664,6 +5677,7 @@ "once": { "version": "1.4.0", "bundled": true, + "optional": true, "requires": { "wrappy": "1" } @@ -5739,7 +5753,8 @@ }, "safe-buffer": { "version": "5.1.1", - "bundled": true + "bundled": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -5769,6 +5784,7 @@ "string-width": { "version": "1.0.2", "bundled": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -5786,6 +5802,7 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -5824,11 +5841,13 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true + "bundled": true, + "optional": true }, "yallist": { "version": "3.0.2", - "bundled": true + "bundled": true, + "optional": true } } }, @@ -5968,6 +5987,11 @@ "resolved": "https://registry.npmjs.org/growly/-/growly-1.3.0.tgz", "integrity": "sha1-8QdIy+dq+WS3yWyTxrzCivEgwIE=" }, + "gud": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/gud/-/gud-1.0.0.tgz", + "integrity": "sha512-zGEOVKFM5sVPPrYs7J5/hYEw2Pof8KCyOwyhG8sAF26mCAeUFAcYPu1mwB7hhpIP29zOIBaDqwuHdLp0jvZXjw==" + }, "gzip-size": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/gzip-size/-/gzip-size-5.0.0.tgz", @@ -6175,6 +6199,34 @@ "resolved": "https://registry.npmjs.org/hex-color-regex/-/hex-color-regex-1.1.0.tgz", "integrity": "sha512-l9sfDFsuqtOqKDsQdqrMRk0U85RZc0RtOR9yPI7mRVOa4FsR/BVnZ0shmQRM96Ji99kYZP/7hn1cedc1+ApsTQ==" }, + "history": { + "version": "4.10.1", + "resolved": "https://registry.npmjs.org/history/-/history-4.10.1.tgz", + "integrity": "sha512-36nwAD620w12kuzPAsyINPWJqlNbij+hpK1k9XRloDtym8mxzGYl2c17LnV6IAGB2Dmg4tEa7G7DlawS0+qjew==", + "requires": { + "@babel/runtime": "^7.1.2", + "loose-envify": "^1.2.0", + "resolve-pathname": "^3.0.0", + "tiny-invariant": "^1.0.2", + "tiny-warning": "^1.0.0", + "value-equal": "^1.0.1" + }, + "dependencies": { + "@babel/runtime": { + "version": "7.8.4", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.8.4.tgz", + "integrity": "sha512-neAp3zt80trRVBI1x0azq6c57aNBqYZH8KhMm3TaB7wEI5Q4A2SHfBHE8w9gOhI/lrqxtEbXZgQIrHP+wvSGwQ==", + "requires": { + "regenerator-runtime": "^0.13.2" + } + }, + "regenerator-runtime": { + "version": "0.13.3", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.3.tgz", + "integrity": "sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw==" + } + } + }, "hmac-drbg": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", @@ -6190,6 +6242,14 @@ "resolved": "http://registry.npmjs.org/hoek/-/hoek-4.2.1.tgz", "integrity": "sha512-QLg82fGkfnJ/4iy1xZ81/9SIJiq1NGFUMGs6ParyjBZr6jW2Ufj/snDqTHixNlHdPNwN2RLVD0Pi3igeK9+JfA==" }, + "hoist-non-react-statics": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz", + "integrity": "sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==", + "requires": { + "react-is": "^16.7.0" + } + }, "home-or-tmp": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/home-or-tmp/-/home-or-tmp-2.0.0.tgz", @@ -8335,6 +8395,31 @@ "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz", "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==" }, + "mini-create-react-context": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/mini-create-react-context/-/mini-create-react-context-0.3.2.tgz", + "integrity": "sha512-2v+OeetEyliMt5VHMXsBhABoJ0/M4RCe7fatd/fBy6SMiKazUSEt3gxxypfnk2SHMkdBYvorHRoQxuGoiwbzAw==", + "requires": { + "@babel/runtime": "^7.4.0", + "gud": "^1.0.0", + "tiny-warning": "^1.0.2" + }, + "dependencies": { + "@babel/runtime": { + "version": "7.8.4", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.8.4.tgz", + "integrity": "sha512-neAp3zt80trRVBI1x0azq6c57aNBqYZH8KhMm3TaB7wEI5Q4A2SHfBHE8w9gOhI/lrqxtEbXZgQIrHP+wvSGwQ==", + "requires": { + "regenerator-runtime": "^0.13.2" + } + }, + "regenerator-runtime": { + "version": "0.13.3", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.3.tgz", + "integrity": "sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw==" + } + } + }, "mini-css-extract-plugin": { "version": "0.4.3", "resolved": "https://registry.npmjs.org/mini-css-extract-plugin/-/mini-css-extract-plugin-0.4.3.tgz", @@ -11112,6 +11197,27 @@ "whatwg-fetch": "3.0.0" } }, + "react-debounce-input": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/react-debounce-input/-/react-debounce-input-3.2.2.tgz", + "integrity": "sha512-RIBu68Cq/gImKz/2h1cE042REDqyqj3D+7SJ3lnnIpJX0ht9D9PfH7KAnL+SgDz6hvKa9pZS2CnAxlkrLmnQlg==", + "requires": { + "lodash.debounce": "^4", + "prop-types": "^15.7.2" + }, + "dependencies": { + "prop-types": { + "version": "15.7.2", + "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.7.2.tgz", + "integrity": "sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==", + "requires": { + "loose-envify": "^1.4.0", + "object-assign": "^4.1.1", + "react-is": "^16.8.1" + } + } + } + }, "react-dev-utils": { "version": "6.1.1", "resolved": "https://registry.npmjs.org/react-dev-utils/-/react-dev-utils-6.1.1.tgz", @@ -11222,6 +11328,85 @@ "resolved": "https://registry.npmjs.org/react-error-overlay/-/react-error-overlay-5.1.0.tgz", "integrity": "sha512-akMy/BQT5m1J3iJIHkSb4qycq2wzllWsmmolaaFVnb+LPV9cIJ/nTud40ZsiiT0H3P+/wXIdbjx2fzF61OaeOQ==" }, + "react-is": { + "version": "16.12.0", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.12.0.tgz", + "integrity": "sha512-rPCkf/mWBtKc97aLL9/txD8DZdemK0vkA3JMLShjlJB3Pj3s+lpf1KaBzMfQrAmhMQB0n1cU/SUGgKKBCe837Q==" + }, + "react-router": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/react-router/-/react-router-5.1.2.tgz", + "integrity": "sha512-yjEuMFy1ONK246B+rsa0cUam5OeAQ8pyclRDgpxuSCrAlJ1qN9uZ5IgyKC7gQg0w8OM50NXHEegPh/ks9YuR2A==", + "requires": { + "@babel/runtime": "^7.1.2", + "history": "^4.9.0", + "hoist-non-react-statics": "^3.1.0", + "loose-envify": "^1.3.1", + "mini-create-react-context": "^0.3.0", + "path-to-regexp": "^1.7.0", + "prop-types": "^15.6.2", + "react-is": "^16.6.0", + "tiny-invariant": "^1.0.2", + "tiny-warning": "^1.0.0" + }, + "dependencies": { + "@babel/runtime": { + "version": "7.8.4", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.8.4.tgz", + "integrity": "sha512-neAp3zt80trRVBI1x0azq6c57aNBqYZH8KhMm3TaB7wEI5Q4A2SHfBHE8w9gOhI/lrqxtEbXZgQIrHP+wvSGwQ==", + "requires": { + "regenerator-runtime": "^0.13.2" + } + }, + "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.8.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz", + "integrity": "sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==", + "requires": { + "isarray": "0.0.1" + } + }, + "regenerator-runtime": { + "version": "0.13.3", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.3.tgz", + "integrity": "sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw==" + } + } + }, + "react-router-dom": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-5.1.2.tgz", + "integrity": "sha512-7BPHAaIwWpZS074UKaw1FjVdZBSVWEk8IuDXdB+OkLb8vd/WRQIpA4ag9WQk61aEfQs47wHyjWUoUGGZxpQXew==", + "requires": { + "@babel/runtime": "^7.1.2", + "history": "^4.9.0", + "loose-envify": "^1.3.1", + "prop-types": "^15.6.2", + "react-router": "5.1.2", + "tiny-invariant": "^1.0.2", + "tiny-warning": "^1.0.0" + }, + "dependencies": { + "@babel/runtime": { + "version": "7.8.4", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.8.4.tgz", + "integrity": "sha512-neAp3zt80trRVBI1x0azq6c57aNBqYZH8KhMm3TaB7wEI5Q4A2SHfBHE8w9gOhI/lrqxtEbXZgQIrHP+wvSGwQ==", + "requires": { + "regenerator-runtime": "^0.13.2" + } + }, + "regenerator-runtime": { + "version": "0.13.3", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.3.tgz", + "integrity": "sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw==" + } + } + }, "react-scripts": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/react-scripts/-/react-scripts-2.1.1.tgz", @@ -11880,6 +12065,11 @@ "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-3.0.0.tgz", "integrity": "sha1-six699nWiBvItuZTM17rywoYh0g=" }, + "resolve-pathname": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/resolve-pathname/-/resolve-pathname-3.0.0.tgz", + "integrity": "sha512-C7rARubxI8bXFNB/hqcp/4iUeIXJhJZvFPFPiSPRnhU5UPxzMFIl+2E6yY6c4k9giDJAhtV+enfA+G89N6Csng==" + }, "resolve-url": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/resolve-url/-/resolve-url-0.2.1.tgz", @@ -13342,6 +13532,16 @@ "resolved": "https://registry.npmjs.org/timsort/-/timsort-0.3.0.tgz", "integrity": "sha1-QFQRqOfmM5/mTbmiNN4R3DHgK9Q=" }, + "tiny-invariant": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/tiny-invariant/-/tiny-invariant-1.1.0.tgz", + "integrity": "sha512-ytxQvrb1cPc9WBEI/HSeYYoGD0kWnGEOR8RY6KomWLBVhqz0RgTwVO9dLrGz7dC+nN9llyI7OKAgRq8Vq4ZBSw==" + }, + "tiny-warning": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tiny-warning/-/tiny-warning-1.0.3.tgz", + "integrity": "sha512-lBN9zLN/oAf68o3zNXYrdCt1kP8WsiGW8Oo2ka41b2IM5JL/S1CTyX1rW0mb/zSuJun0ZUrDxx4sqvYS2FWzPA==" + }, "tmp": { "version": "0.0.33", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", @@ -13857,6 +14057,11 @@ "spdx-expression-parse": "^3.0.0" } }, + "value-equal": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/value-equal/-/value-equal-1.0.1.tgz", + "integrity": "sha512-NOJ6JZCAWr0zlxZt+xqCHNTEKOsrks2HQd4MqhP1qy4z1SkbEP467eNx6TgDKXMvUOb+OENfJCZwM+16n7fRfw==" + }, "vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", diff --git a/package.json b/package.json index 579d515885..bfac9392b2 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,9 @@ "dependencies": { "prop-types": "^15.6.2", "react": "^16.6.3", + "react-debounce-input": "^3.2.2", "react-dom": "^16.6.3", + "react-router-dom": "^5.1.2", "react-scripts": "2.1.1" }, "scripts": { diff --git a/src/App.js b/src/App.js index 785820d5df..598e4a341a 100644 --- a/src/App.js +++ b/src/App.js @@ -1,203 +1,134 @@ import React from 'react' -// import * as BooksAPI from './BooksAPI' +import * as BooksAPI from './BooksAPI' import './App.css' +import Shelfs from './Shelfs' +import { Link } from 'react-router-dom' +import { Route } from 'react-router-dom' +import SearchMain from './SearchMain' 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: [] + } + componentDidMount() { + BooksAPI.getAll() + .then((books) => { + this.setState(() => ({ + books + }) + ) + }) + } + groupBy(objeectArray, property) { + return objeectArray.reduce(function (acc, obj) { + var key = obj[property]; + if (!acc[key]) { + acc[key] = []; + } + acc[key].push(obj); + return acc; + }, {}); } + shelfNames = { + 'currentlyReading': 'Currently Reading', + 'wantToRead': 'Want To Read', + 'read': 'Read' + } + + addNewBook = (book, shelf) => { + BooksAPI.update(book, shelf) + .then((bookResponse) => { + book.shelf = shelf + let newBooks = this.state.books.concat([book]) + this.setState({ + books: newBooks + }) + }) + } + + changeSelf = (bookItem, shelfId) => { + let { books } = this.state; + let isNewBook = true; + let newBooks = books.map(book => { + if (book.id === bookItem.id) { + book.shelf = shelfId; + isNewBook = false; //is not a new book wee found it on the shelfs + } + return book; + }) + if (isNewBook) { + this.addNewBook(bookItem, shelfId) + } else { + BooksAPI.update(bookItem, shelfId).then((bookResponse) => { + this.setState({ + books: newBooks + }) + }) + } + } + + //
{shelves }
render() { + + const groupedBooks = this.groupBy(this.state.books, 'shelf'); + + const shelves = Object.keys(groupedBooks).map(key => { + + return ( + + + + + ) + }); + + 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 - - 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. - */} - - -
-
-
-
    -
    -
    - ) : ( + (

    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. -
    -
    -
    -
    + {shelves}
    +
    - + + +
    - )} + )} /> + ( + + + )} /> +
    ) } diff --git a/src/AppTemplate.js b/src/AppTemplate.js new file mode 100644 index 0000000000..887e00b529 --- /dev/null +++ b/src/AppTemplate.js @@ -0,0 +1,224 @@ +import React from 'react' +// import * as BooksAPI from './BooksAPI' +import './App.css' + +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 + } + + 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 + + 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. + */} + + +
    +
    +
    +
      +
      +
      + ) : ( +
      +
      +

      MyReads

      +
      +
      +
      +
      +

      Currently Reading

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

      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. +
      +
      +
      +
      +
      +
      + +
      +
      + )} +
      + ) + } +} + +export default BooksApp diff --git a/src/BookItem.js b/src/BookItem.js new file mode 100644 index 0000000000..9f30582187 --- /dev/null +++ b/src/BookItem.js @@ -0,0 +1,50 @@ +import React, { Component } from 'react' + + +class BookItem extends Component { + + getBookShelf(foundBook, allBooks){ + let myBook + if (allBooks) { + myBook = allBooks.find(item => { + return item.id === foundBook.id + }) + } + + let isOwened = ((myBook !== undefined) ? true : false) + + let shelfValue = isOwened ? myBook.shelf : "none" + + return shelfValue + + } + + render() { + let { book , changeSelf, allBooks} = this.props + console.log("all books") + console.log(allBooks) + + + return ( +
    1. +
      +
      +
      +
      + +
      +
      +
      {book.title}
      +
      +
    2. + ) + } +} + +export default BookItem diff --git a/src/SearchMain.js b/src/SearchMain.js new file mode 100644 index 0000000000..84fdbe794b --- /dev/null +++ b/src/SearchMain.js @@ -0,0 +1,113 @@ +import React, { Component } from 'react' +import { DebounceInput } from 'react-debounce-input' +import * as BooksAPI from './BooksAPI' +import ShelfBooks from './ShelfBooks' + +import { Link } from 'react-router-dom' + + +class SearchMain extends Component { + + state = { + books: [], + badTerms: [] + } + + querryIsValid = false; + allTerms = ['Android', 'Art', 'Artificial Intelligence', 'Astronomy', 'Austen', 'Baseball', 'Basketball', + 'Bhagat', 'Biography', 'Brief', 'Business', 'Camus', 'Cervantes', 'Christie', 'Classics', 'Comics', 'Cook', + 'Cricket', 'Cycling', 'Desai', 'Design', 'Development', 'Digital Marketing', 'Drama', 'Drawing', 'Dumas', + 'Education', 'Everything', 'Fantasy', 'Film', 'Finance', 'First', 'Fitness', 'Football', 'Future', 'Games', + 'Gandhi', 'Homer', 'Horror', 'Hugo', 'Ibsen', 'Journey', 'Kafka', 'King', 'Lahiri', 'Larsson', 'Learn', + 'Literary Fiction', 'Make', 'Manage', 'Marquez', 'Money', 'Mystery', 'Negotiate', 'Painting', 'Philosophy', + 'Photography', 'Poetry', 'Production', 'Programming', 'React', 'Redux', 'River', 'Robotics', 'Rowling', + 'Satire', 'Science Fiction', 'Shakespeare', 'Singh', 'Swimming', 'Tale', 'Thrun', 'Time', 'Tolstoy', 'Travel', + 'Ultimate', 'Virtual Reality', 'Web Development', 'iOS']; + validator = this.allTerms.join(',').toLowerCase(); + + getBadTerms(query) { + let tokens = query.split(" "); + let terms = []; + tokens.forEach(element => { + + if (!this.validator.includes(element.toLowerCase())) { + terms.push(element) + } + }); + return terms; + } + + runSearch(event) { + + let query = event.target.value + query = query.trim() + if (query === '') { + this.setState({ books: [] }) + return + } + + let badTerms = this.getBadTerms(query); + + + if (badTerms.length < 1) { + BooksAPI.search(query).then((books) => { + if (books && books.length > 0) { + let foundBooks = books.filter((book) => (book.imageLinks && book.imageLinks.thumbnail)) + this.setState({ books: foundBooks, badTerms: [] }) + } + + }) + } else { + this.setState({ + books: [], + badTerms: badTerms + }) + } + + + + + } + + render() { + const { addBookToShelf, allBooks } = this.props + + return ( +
      +
      + + {/* */} + Close + +
      + {/* + 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 + + 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. + */} + this.runSearch(evt)} /> + +
      +
      +
      + {(this.state.badTerms.length < 1) + ? + :
      Bad Thearm
      + } + +
        +
        +
        + ) + } + +} + +export default SearchMain \ No newline at end of file diff --git a/src/ShelfBooks.js b/src/ShelfBooks.js new file mode 100644 index 0000000000..a08dd86916 --- /dev/null +++ b/src/ShelfBooks.js @@ -0,0 +1,32 @@ +import React from 'react' +import BookItem from './BookItem' + + +class ShelfBooks extends React.Component { + render() { + const { bookList,changeSelf, shelfKey, allBooks } = this.props; + let bookItem = bookList.map( book => { + + return( + + ) + }) + + + + return ( +
          + {bookItem} +
        + + ) + } + +} +export default ShelfBooks \ No newline at end of file diff --git a/src/Shelfs.js b/src/Shelfs.js new file mode 100644 index 0000000000..c4d0f210cd --- /dev/null +++ b/src/Shelfs.js @@ -0,0 +1,26 @@ +import React from 'react' +import ShelfBooks from './ShelfBooks' + +class Shelfs extends React.Component { + render() { + const { shelfKey, shelfNames, bookList, allBooks, changeSelf } = this.props; + return ( +
        +

        {shelfNames}

        +
        + +
        + +
        + ) + + } + +} + +export default Shelfs \ No newline at end of file diff --git a/src/index.js b/src/index.js index fde0d67bd1..c5ccbb40a5 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,11 @@ import React from 'react' import ReactDOM from 'react-dom' +import { BrowserRouter } from 'react-router-dom' import App from './App' import './index.css' -ReactDOM.render(, document.getElementById('root')) +ReactDOM.render( + + + + , document.getElementById('root'))