diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..6b55e2e66f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules +yarn.lock +.DS_Store diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000000..2923eaa1c0 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,3 @@ +# 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/README.md b/README.md new file mode 100644 index 0000000000..afb0f1d831 --- /dev/null +++ b/README.md @@ -0,0 +1,93 @@ +# 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, maxResults) +``` + +* query: `` +* maxResults: `` Due to the nature of the backend server, search results are capped at 20, even if this is set higher. +* Returns a Promise which resolves to a JSON object containing a collection of 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). diff --git a/SEARCH_TERMS.md b/SEARCH_TERMS.md new file mode 100644 index 0000000000..a0ec9025d0 --- /dev/null +++ b/SEARCH_TERMS.md @@ -0,0 +1 @@ +'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' diff --git a/package.json b/package.json new file mode 100644 index 0000000000..be5083ad17 --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "dependencies": { + "prop-types": "^15.5.8", + "react": "^15.5.4", + "react-dom": "^15.5.4" + }, + "devDependencies": { + "react-scripts": "0.9.5" + }, + "scripts": { + "start": "react-scripts start", + "build": "react-scripts build", + "test": "react-scripts test --env=jsdom", + "eject": "react-scripts eject" + } +} diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000000..5c125de5d8 Binary files /dev/null and b/public/favicon.ico differ diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000000..9da2a810b9 --- /dev/null +++ b/public/index.html @@ -0,0 +1,32 @@ + + + + + + + + + MyReads + + +
+ + + diff --git a/src/App.css b/src/App.css new file mode 100644 index 0000000000..31ad511326 --- /dev/null +++ b/src/App.css @@ -0,0 +1,174 @@ +html, body, .root { + height: 100%; +} +body { + line-height: 1.5; +} +body, .app { + background: white; +} + +/* main page */ + +.list-books-title { + padding: 10px 0; + background: #2e7c31; + text-align: center; +} +.list-books-title h1 { + font-weight: 400; + margin: 0; + color: white; +} + +.list-books-content { + padding: 0 0 80px; + flex: 1; +} + +.bookshelf { + padding: 0 10px 20px; +} + +@media (min-width: 600px) { + .bookshelf { + padding: 0 20px 40px; + } +} + +.bookshelf-title { + border-bottom: 1px solid #dedede; +} +.bookshelf-books { + text-align: center; +} + +.open-search { + position: fixed; + right: 25px; + bottom: 25px; +} +.open-search a { + display: block; + width: 50px; + height: 50px; + border-radius: 50%; + background: #2e7d32; + background-image: url('./icons/add.svg'); + background-repeat: no-repeat; + background-position: center; + background-size: 28px; + box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23); + font-size: 0; +} + +/* search page */ + +.search-books-bar { + position: fixed; + width: 100%; + top: 0; + left: 0; + z-index: 5; + display: flex; + box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 0 6px rgba(0,0,0,0.23); +} +.search-books-input-wrapper { + flex: 1; + background: #e9e; +} +.search-books-bar input { + width: 100%; + padding: 15px 10px; + font-size: 1.25em; + border: none; + outline: none; +} + +.close-search { + display: block; + top: 20px; + left: 15px; + width: 50px; + height: 53px; + background: white; + background-image: url('./icons/arrow-back.svg'); + background-position: center; + background-repeat: no-repeat; + background-size: 28px; + font-size: 0; +} + +.search-books-results { + padding: 80px 10px 20px; +} + +/* books grid */ + +.books-grid { + list-style-type: none; + padding: 0; + margin: 0; + + display: flex; + justify-content: center; + flex-wrap: wrap; +} +.books-grid li { + padding: 10px 15px; + text-align: left; +} + +.book { + width: 140px; +} +.book-title, +.book-authors { + font-size: 0.8em; +} +.book-title { + margin-top: 10px; +} +.book-authors { + color: #999; +} + +.book-top { + position: relative; + height: 200px; + display: flex; + align-items: flex-end; +} + +.book-shelf-changer { + position: absolute; + right: 0; + bottom: -10px; + width: 40px; + height: 40px; + border-radius: 50%; + background: #60ac5d; + background-image: url('./icons/arrow-drop-down.svg'); + background-repeat: no-repeat; + background-position: center; + background-size: 20px; + box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23); +} +.book-shelf-changer select { + width: 100%; + height: 100%; + opacity: 0; + cursor: pointer; +} + +/* book cover */ + +.book-cover { + box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23); + background: #eee; +} +.book-cover-title { + padding: 20px 10px 0; + text-align: center; + font-size: 0.8em; +} diff --git a/src/App.js b/src/App.js new file mode 100644 index 0000000000..3387cd458a --- /dev/null +++ b/src/App.js @@ -0,0 +1,206 @@ +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 ? ( +
+
+ this.setState({ showSearchPage: false })}>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. + */} + + +
+
+
+
    +
    +
    + ) : ( +
    +
    +

    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. +
    +
    +
    +
    +
    + +
    + )} +
    + ) + } +} + +export default BooksApp diff --git a/src/App.test.js b/src/App.test.js new file mode 100644 index 0000000000..9f26f64047 --- /dev/null +++ b/src/App.test.js @@ -0,0 +1,16 @@ +import React from 'react' +import ReactDOM from 'react-dom' +import App from './App' + +/** + This course is not designed to teach Test Driven Development. + Feel free to use this file to test your application, but it + is not required. +**/ + +it('renders without crashing', () => { + const div = document.createElement('div') + ReactDOM.render(, div) +}) + + diff --git a/src/BooksAPI.js b/src/BooksAPI.js new file mode 100644 index 0000000000..1235dbad8e --- /dev/null +++ b/src/BooksAPI.js @@ -0,0 +1,44 @@ + +const api = "https://reactnd-books-api.udacity.com" + + +// Generate a unique token for storing your bookshelf data on the backend server. +let token = localStorage.token +if (!token) + token = localStorage.token = Math.random().toString(36).substr(-8) + +const headers = { + 'Accept': 'application/json', + 'Authorization': token +} + +export const get = (bookId) => + fetch(`${api}/books/${bookId}`, { headers }) + .then(res => res.json()) + .then(data => data.book) + +export const getAll = () => + fetch(`${api}/books`, { headers }) + .then(res => res.json()) + .then(data => data.books) + +export const update = (book, shelf) => + fetch(`${api}/books/${book.id}`, { + method: 'PUT', + headers: { + ...headers, + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ shelf }) + }).then(res => res.json()) + +export const search = (query, maxResults) => + fetch(`${api}/search`, { + method: 'POST', + headers: { + ...headers, + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ query, maxResults }) + }).then(res => res.json()) + .then(data => data.books) diff --git a/src/icons/add.svg b/src/icons/add.svg new file mode 100644 index 0000000000..ed289e430b --- /dev/null +++ b/src/icons/add.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/icons/arrow-back.svg b/src/icons/arrow-back.svg new file mode 100644 index 0000000000..55e16c5527 --- /dev/null +++ b/src/icons/arrow-back.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/icons/arrow-drop-down.svg b/src/icons/arrow-drop-down.svg new file mode 100644 index 0000000000..30c40f86b2 --- /dev/null +++ b/src/icons/arrow-drop-down.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/index.css b/src/index.css new file mode 100644 index 0000000000..e2370ceee2 --- /dev/null +++ b/src/index.css @@ -0,0 +1,11 @@ +html { + box-sizing: border-box; +} +*, *:before, *:after { + box-sizing: inherit; +} +body { + margin: 0; + padding: 0; + font-family: 'Roboto', sans-serif; +} diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000000..fde0d67bd1 --- /dev/null +++ b/src/index.js @@ -0,0 +1,6 @@ +import React from 'react' +import ReactDOM from 'react-dom' +import App from './App' +import './index.css' + +ReactDOM.render(, document.getElementById('root'))