From dcd269825af29e3cb9f738aa94da7c422886adf1 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Mon, 17 Jul 2017 00:42:08 -0400 Subject: [PATCH 001/112] add boilerplate --- client/.gitignore | 21 + client/README.md | 2138 +++++++++ client/package.json | 18 + client/public/favicon.ico | Bin 0 -> 24838 bytes client/public/index.html | 40 + client/public/manifest.json | 15 + client/src/App.css | 24 + client/src/App.js | 21 + client/src/App.test.js | 8 + client/src/index.css | 5 + client/src/index.js | 8 + client/src/logo.svg | 7 + client/src/registerServiceWorker.js | 108 + client/yarn.lock | 6366 +++++++++++++++++++++++++++ server/.gitignore | 1 + server/config/mongo.json | 13 + server/index.js | 196 + server/mongo.js | 10 + server/package.json | 16 + server/repl.js | 13 + server/seeds/clean.js | 16 + server/spec/app_spec.js | 21 + server/spec/helpers/index.js | 18 + server/spec/support/jasmine.json | 11 + server/yarn.lock | 1136 +++++ 25 files changed, 10230 insertions(+) create mode 100644 client/.gitignore create mode 100644 client/README.md create mode 100644 client/package.json create mode 100644 client/public/favicon.ico create mode 100644 client/public/index.html create mode 100644 client/public/manifest.json create mode 100644 client/src/App.css create mode 100644 client/src/App.js create mode 100644 client/src/App.test.js create mode 100644 client/src/index.css create mode 100644 client/src/index.js create mode 100644 client/src/logo.svg create mode 100644 client/src/registerServiceWorker.js create mode 100644 client/yarn.lock create mode 100644 server/.gitignore create mode 100644 server/config/mongo.json create mode 100644 server/index.js create mode 100644 server/mongo.js create mode 100644 server/package.json create mode 100644 server/repl.js create mode 100644 server/seeds/clean.js create mode 100644 server/spec/app_spec.js create mode 100644 server/spec/helpers/index.js create mode 100644 server/spec/support/jasmine.json create mode 100644 server/yarn.lock diff --git a/client/.gitignore b/client/.gitignore new file mode 100644 index 00000000..d30f40ef --- /dev/null +++ b/client/.gitignore @@ -0,0 +1,21 @@ +# See https://help.github.com/ignore-files/ for more about ignoring files. + +# dependencies +/node_modules + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/client/README.md b/client/README.md new file mode 100644 index 00000000..57750284 --- /dev/null +++ b/client/README.md @@ -0,0 +1,2138 @@ +This project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app). + +Below you will find some information on how to perform common tasks.
+You can find the most recent version of this guide [here](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md). + +## Table of Contents + +- [Updating to New Releases](#updating-to-new-releases) +- [Sending Feedback](#sending-feedback) +- [Folder Structure](#folder-structure) +- [Available Scripts](#available-scripts) + - [npm start](#npm-start) + - [npm test](#npm-test) + - [npm run build](#npm-run-build) + - [npm run eject](#npm-run-eject) +- [Supported Language Features and Polyfills](#supported-language-features-and-polyfills) +- [Syntax Highlighting in the Editor](#syntax-highlighting-in-the-editor) +- [Displaying Lint Output in the Editor](#displaying-lint-output-in-the-editor) +- [Debugging in the Editor](#debugging-in-the-editor) +- [Formatting Code Automatically](#formatting-code-automatically) +- [Changing the Page ``](#changing-the-page-title) +- [Installing a Dependency](#installing-a-dependency) +- [Importing a Component](#importing-a-component) +- [Code Splitting](#code-splitting) +- [Adding a Stylesheet](#adding-a-stylesheet) +- [Post-Processing CSS](#post-processing-css) +- [Adding a CSS Preprocessor (Sass, Less etc.)](#adding-a-css-preprocessor-sass-less-etc) +- [Adding Images, Fonts, and Files](#adding-images-fonts-and-files) +- [Using the `public` Folder](#using-the-public-folder) + - [Changing the HTML](#changing-the-html) + - [Adding Assets Outside of the Module System](#adding-assets-outside-of-the-module-system) + - [When to Use the `public` Folder](#when-to-use-the-public-folder) +- [Using Global Variables](#using-global-variables) +- [Adding Bootstrap](#adding-bootstrap) + - [Using a Custom Theme](#using-a-custom-theme) +- [Adding Flow](#adding-flow) +- [Adding Custom Environment Variables](#adding-custom-environment-variables) + - [Referencing Environment Variables in the HTML](#referencing-environment-variables-in-the-html) + - [Adding Temporary Environment Variables In Your Shell](#adding-temporary-environment-variables-in-your-shell) + - [Adding Development Environment Variables In `.env`](#adding-development-environment-variables-in-env) +- [Can I Use Decorators?](#can-i-use-decorators) +- [Integrating with an API Backend](#integrating-with-an-api-backend) + - [Node](#node) + - [Ruby on Rails](#ruby-on-rails) +- [Proxying API Requests in Development](#proxying-api-requests-in-development) + - ["Invalid Host Header" Errors After Configuring Proxy](#invalid-host-header-errors-after-configuring-proxy) + - [Configuring the Proxy Manually](#configuring-the-proxy-manually) + - [Configuring a WebSocket Proxy](#configuring-a-websocket-proxy) +- [Using HTTPS in Development](#using-https-in-development) +- [Generating Dynamic `<meta>` Tags on the Server](#generating-dynamic-meta-tags-on-the-server) +- [Pre-Rendering into Static HTML Files](#pre-rendering-into-static-html-files) +- [Injecting Data from the Server into the Page](#injecting-data-from-the-server-into-the-page) +- [Running Tests](#running-tests) + - [Filename Conventions](#filename-conventions) + - [Command Line Interface](#command-line-interface) + - [Version Control Integration](#version-control-integration) + - [Writing Tests](#writing-tests) + - [Testing Components](#testing-components) + - [Using Third Party Assertion Libraries](#using-third-party-assertion-libraries) + - [Initializing Test Environment](#initializing-test-environment) + - [Focusing and Excluding Tests](#focusing-and-excluding-tests) + - [Coverage Reporting](#coverage-reporting) + - [Continuous Integration](#continuous-integration) + - [Disabling jsdom](#disabling-jsdom) + - [Snapshot Testing](#snapshot-testing) + - [Editor Integration](#editor-integration) +- [Developing Components in Isolation](#developing-components-in-isolation) + - [Getting Started with Storybook](#getting-started-with-storybook) + - [Getting Started with Styleguidist](#getting-started-with-styleguidist) +- [Making a Progressive Web App](#making-a-progressive-web-app) + - [Offline-First Considerations](#offline-first-considerations) + - [Progressive Web App Metadata](#progressive-web-app-metadata) +- [Analyzing the Bundle Size](#analyzing-the-bundle-size) +- [Deployment](#deployment) + - [Static Server](#static-server) + - [Other Solutions](#other-solutions) + - [Serving Apps with Client-Side Routing](#serving-apps-with-client-side-routing) + - [Building for Relative Paths](#building-for-relative-paths) + - [Azure](#azure) + - [Firebase](#firebase) + - [GitHub Pages](#github-pages) + - [Heroku](#heroku) + - [Modulus](#modulus) + - [Netlify](#netlify) + - [Now](#now) + - [S3 and CloudFront](#s3-and-cloudfront) + - [Surge](#surge) +- [Advanced Configuration](#advanced-configuration) +- [Troubleshooting](#troubleshooting) + - [`npm start` doesn’t detect changes](#npm-start-doesnt-detect-changes) + - [`npm test` hangs on macOS Sierra](#npm-test-hangs-on-macos-sierra) + - [`npm run build` exits too early](#npm-run-build-exits-too-early) + - [`npm run build` fails on Heroku](#npm-run-build-fails-on-heroku) + - [Moment.js locales are missing](#momentjs-locales-are-missing) +- [Something Missing?](#something-missing) + +## Updating to New Releases + +Create React App is divided into two packages: + +* `create-react-app` is a global command-line utility that you use to create new projects. +* `react-scripts` is a development dependency in the generated projects (including this one). + +You almost never need to update `create-react-app` itself: it delegates all the setup to `react-scripts`. + +When you run `create-react-app`, it always creates the project with the latest version of `react-scripts` so you’ll get all the new features and improvements in newly created apps automatically. + +To update an existing project to a new version of `react-scripts`, [open the changelog](https://github.com/facebookincubator/create-react-app/blob/master/CHANGELOG.md), find the version you’re currently on (check `package.json` in this folder if you’re not sure), and apply the migration instructions for the newer versions. + +In most cases bumping the `react-scripts` version in `package.json` and running `npm install` in this folder should be enough, but it’s good to consult the [changelog](https://github.com/facebookincubator/create-react-app/blob/master/CHANGELOG.md) for potential breaking changes. + +We commit to keeping the breaking changes minimal so you can upgrade `react-scripts` painlessly. + +## Sending Feedback + +We are always open to [your feedback](https://github.com/facebookincubator/create-react-app/issues). + +## Folder Structure + +After creation, your project should look like this: + +``` +my-app/ + README.md + node_modules/ + package.json + public/ + index.html + favicon.ico + src/ + App.css + App.js + App.test.js + index.css + index.js + logo.svg +``` + +For the project to build, **these files must exist with exact filenames**: + +* `public/index.html` is the page template; +* `src/index.js` is the JavaScript entry point. + +You can delete or rename the other files. + +You may create subdirectories inside `src`. For faster rebuilds, only files inside `src` are processed by Webpack.<br> +You need to **put any JS and CSS files inside `src`**, otherwise Webpack won’t see them. + +Only files inside `public` can be used from `public/index.html`.<br> +Read instructions below for using assets from JavaScript and HTML. + +You can, however, create more top-level directories.<br> +They will not be included in the production build so you can use them for things like documentation. + +## Available Scripts + +In the project directory, you can run: + +### `npm start` + +Runs the app in the development mode.<br> +Open [http://localhost:3000](http://localhost:3000) to view it in the browser. + +The page will reload if you make edits.<br> +You will also see any lint errors in the console. + +### `npm test` + +Launches the test runner in the interactive watch mode.<br> +See the section about [running tests](#running-tests) for more information. + +### `npm run build` + +Builds the app for production to the `build` folder.<br> +It correctly bundles React in production mode and optimizes the build for the best performance. + +The build is minified and the filenames include the hashes.<br> +Your app is ready to be deployed! + +See the section about [deployment](#deployment) for more information. + +### `npm run eject` + +**Note: this is a one-way operation. Once you `eject`, you can’t go back!** + +If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. + +Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. + +You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. + +## Supported Language Features and Polyfills + +This project supports a superset of the latest JavaScript standard.<br> +In addition to [ES6](https://github.com/lukehoban/es6features) syntax features, it also supports: + +* [Exponentiation Operator](https://github.com/rwaldron/exponentiation-operator) (ES2016). +* [Async/await](https://github.com/tc39/ecmascript-asyncawait) (ES2017). +* [Object Rest/Spread Properties](https://github.com/sebmarkbage/ecmascript-rest-spread) (stage 3 proposal). +* [Dynamic import()](https://github.com/tc39/proposal-dynamic-import) (stage 3 proposal) +* [Class Fields and Static Properties](https://github.com/tc39/proposal-class-public-fields) (stage 2 proposal). +* [JSX](https://facebook.github.io/react/docs/introducing-jsx.html) and [Flow](https://flowtype.org/) syntax. + +Learn more about [different proposal stages](https://babeljs.io/docs/plugins/#presets-stage-x-experimental-presets-). + +While we recommend to use experimental proposals with some caution, Facebook heavily uses these features in the product code, so we intend to provide [codemods](https://medium.com/@cpojer/effective-javascript-codemods-5a6686bb46fb) if any of these proposals change in the future. + +Note that **the project only includes a few ES6 [polyfills](https://en.wikipedia.org/wiki/Polyfill)**: + +* [`Object.assign()`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) via [`object-assign`](https://github.com/sindresorhus/object-assign). +* [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) via [`promise`](https://github.com/then/promise). +* [`fetch()`](https://developer.mozilla.org/en/docs/Web/API/Fetch_API) via [`whatwg-fetch`](https://github.com/github/fetch). + +If you use any other ES6+ features that need **runtime support** (such as `Array.from()` or `Symbol`), make sure you are including the appropriate polyfills manually, or that the browsers you are targeting already support them. + +## Syntax Highlighting in the Editor + +To configure the syntax highlighting in your favorite text editor, head to the [relevant Babel documentation page](https://babeljs.io/docs/editors) and follow the instructions. Some of the most popular editors are covered. + +## Displaying Lint Output in the Editor + +>Note: this feature is available with `react-scripts@0.2.0` and higher.<br> +>It also only works with npm 3 or higher. + +Some editors, including Sublime Text, Atom, and Visual Studio Code, provide plugins for ESLint. + +They are not required for linting. You should see the linter output right in your terminal as well as the browser console. However, if you prefer the lint results to appear right in your editor, there are some extra steps you can do. + +You would need to install an ESLint plugin for your editor first. Then, add a file called `.eslintrc` to the project root: + +```js +{ + "extends": "react-app" +} +``` + +Now your editor should report the linting warnings. + +Note that even if you edit your `.eslintrc` file further, these changes will **only affect the editor integration**. They won’t affect the terminal and in-browser lint output. This is because Create React App intentionally provides a minimal set of rules that find common mistakes. + +If you want to enforce a coding style for your project, consider using [Prettier](https://github.com/jlongster/prettier) instead of ESLint style rules. + +## Debugging in the Editor + +**This feature is currently only supported by [Visual Studio Code](https://code.visualstudio.com) editor.** + +Visual Studio Code supports debugging out of the box with Create React App. This enables you as a developer to write and debug your React code without leaving the editor, and most importantly it enables you to have a continuous development workflow, where context switching is minimal, as you don’t have to switch between tools. + +You would need to have the latest version of [VS Code](https://code.visualstudio.com) and VS Code [Chrome Debugger Extension](https://marketplace.visualstudio.com/items?itemName=msjsdiag.debugger-for-chrome) installed. + +Then add the block below to your `launch.json` file and put it inside the `.vscode` folder in your app’s root directory. + +```json +{ + "version": "0.2.0", + "configurations": [{ + "name": "Chrome", + "type": "chrome", + "request": "launch", + "url": "http://localhost:3000", + "webRoot": "${workspaceRoot}/src", + "userDataDir": "${workspaceRoot}/.vscode/chrome", + "sourceMapPathOverrides": { + "webpack:///src/*": "${webRoot}/*" + } + }] +} +``` + +Start your app by running `npm start`, and start debugging in VS Code by pressing `F5` or by clicking the green debug icon. You can now write code, set breakpoints, make changes to the code, and debug your newly modified code—all from your editor. + +## Formatting Code Automatically + +Prettier is an opinionated code formatter with support for JavaScript, CSS and JSON. With Prettier you can format the code you write automatically to ensure a code style within your project. See the [Prettier's GitHub page](https://github.com/prettier/prettier) for more information, and look at this [page to see it in action](https://prettier.github.io/prettier/). + +To format our code whenever we make a commit in git, we need to install the following dependencies: + +```sh +npm install --save husky lint-staged prettier +``` + +Alternatively you may use `yarn`: + +```sh +yarn add husky lint-staged prettier +``` + +* `husky` makes it easy to use githooks as if they are npm scripts. +* `lint-staged` allows us to run scripts on staged files in git. See this [blog post about lint-staged to learn more about it](https://medium.com/@okonetchnikov/make-linting-great-again-f3890e1ad6b8). +* `prettier` is the JavaScript formatter we will run before commits. + +Now we can make sure every file is formatted correctly by adding a few lines to the `package.json` in the project root. + +Add the following line to `scripts` section: + +```diff + "scripts": { ++ "precommit": "lint-staged", + "start": "react-scripts start", + "build": "react-scripts build", +``` + +Next we add a 'lint-staged' field to the `package.json`, for example: + +```diff + "dependencies": { + // ... + }, ++ "lint-staged": { ++ "src/**/*.{js,jsx,json,css}": [ ++ "prettier --single-quote --write", ++ "git add" ++ ] ++ }, + "scripts": { +``` + +Now, whenever you make a commit, Prettier will format the changed files automatically. You can also run `./node_modules/.bin/prettier --single-quote --write "src/**/*.{js,jsx}"` to format your entire project for the first time. + +Next you might want to integrate Prettier in your favorite editor. Read the section on [Editor Integration](https://github.com/prettier/prettier#editor-integration) on the Prettier GitHub page. + +## Changing the Page `<title>` + +You can find the source HTML file in the `public` folder of the generated project. You may edit the `<title>` tag in it to change the title from “React App” to anything else. + +Note that normally you wouldn’t edit files in the `public` folder very often. For example, [adding a stylesheet](#adding-a-stylesheet) is done without touching the HTML. + +If you need to dynamically update the page title based on the content, you can use the browser [`document.title`](https://developer.mozilla.org/en-US/docs/Web/API/Document/title) API. For more complex scenarios when you want to change the title from React components, you can use [React Helmet](https://github.com/nfl/react-helmet), a third party library. + +If you use a custom server for your app in production and want to modify the title before it gets sent to the browser, you can follow advice in [this section](#generating-dynamic-meta-tags-on-the-server). Alternatively, you can pre-build each page as a static HTML file which then loads the JavaScript bundle, which is covered [here](#pre-rendering-into-static-html-files). + +## Installing a Dependency + +The generated project includes React and ReactDOM as dependencies. It also includes a set of scripts used by Create React App as a development dependency. You may install other dependencies (for example, React Router) with `npm`: + +```sh +npm install --save react-router +``` + +Alternatively you may use `yarn`: + +```sh +yarn add react-router +``` + +This works for any library, not just `react-router`. + +## Importing a Component + +This project setup supports ES6 modules thanks to Babel.<br> +While you can still use `require()` and `module.exports`, we encourage you to use [`import` and `export`](http://exploringjs.com/es6/ch_modules.html) instead. + +For example: + +### `Button.js` + +```js +import React, { Component } from 'react'; + +class Button extends Component { + render() { + // ... + } +} + +export default Button; // Don’t forget to use export default! +``` + +### `DangerButton.js` + + +```js +import React, { Component } from 'react'; +import Button from './Button'; // Import a component from another file + +class DangerButton extends Component { + render() { + return <Button color="red" />; + } +} + +export default DangerButton; +``` + +Be aware of the [difference between default and named exports](http://stackoverflow.com/questions/36795819/react-native-es-6-when-should-i-use-curly-braces-for-import/36796281#36796281). It is a common source of mistakes. + +We suggest that you stick to using default imports and exports when a module only exports a single thing (for example, a component). That’s what you get when you use `export default Button` and `import Button from './Button'`. + +Named exports are useful for utility modules that export several functions. A module may have at most one default export and as many named exports as you like. + +Learn more about ES6 modules: + +* [When to use the curly braces?](http://stackoverflow.com/questions/36795819/react-native-es-6-when-should-i-use-curly-braces-for-import/36796281#36796281) +* [Exploring ES6: Modules](http://exploringjs.com/es6/ch_modules.html) +* [Understanding ES6: Modules](https://leanpub.com/understandinges6/read#leanpub-auto-encapsulating-code-with-modules) + +## Code Splitting + +Instead of downloading the entire app before users can use it, code splitting allows you to split your code into small chunks which you can then load on demand. + +This project setup supports code splitting via [dynamic `import()`](http://2ality.com/2017/01/import-operator.html#loading-code-on-demand). Its [proposal](https://github.com/tc39/proposal-dynamic-import) is in stage 3. The `import()` function-like form takes the module name as an argument and returns a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) which always resolves to the namespace object of the module. + +Here is an example: + +### `moduleA.js` + +```js +const moduleA = 'Hello'; + +export { moduleA }; +``` +### `App.js` + +```js +import React, { Component } from 'react'; + +class App extends Component { + handleClick = () => { + import('./moduleA') + .then(({ moduleA }) => { + // Use moduleA + }) + .catch(err => { + // Handle failure + }); + }; + + render() { + return ( + <div> + <button onClick={this.handleClick}>Load</button> + </div> + ); + } +} + +export default App; +``` + +This will make `moduleA.js` and all its unique dependencies as a separate chunk that only loads after the user clicks the 'Load' button. + +You can also use it with `async` / `await` syntax if you prefer it. + +### With React Router + +If you are using React Router check out [this tutorial](http://serverless-stack.com/chapters/code-splitting-in-create-react-app.html) on how to use code splitting with it. You can find the companion GitHub repository [here](https://github.com/AnomalyInnovations/serverless-stack-demo-client/tree/code-splitting-in-create-react-app). + +## Adding a Stylesheet + +This project setup uses [Webpack](https://webpack.js.org/) for handling all assets. Webpack offers a custom way of “extending” the concept of `import` beyond JavaScript. To express that a JavaScript file depends on a CSS file, you need to **import the CSS from the JavaScript file**: + +### `Button.css` + +```css +.Button { + padding: 20px; +} +``` + +### `Button.js` + +```js +import React, { Component } from 'react'; +import './Button.css'; // Tell Webpack that Button.js uses these styles + +class Button extends Component { + render() { + // You can use them as regular CSS styles + return <div className="Button" />; + } +} +``` + +**This is not required for React** but many people find this feature convenient. You can read about the benefits of this approach [here](https://medium.com/seek-ui-engineering/block-element-modifying-your-javascript-components-d7f99fcab52b). However you should be aware that this makes your code less portable to other build tools and environments than Webpack. + +In development, expressing dependencies this way allows your styles to be reloaded on the fly as you edit them. In production, all CSS files will be concatenated into a single minified `.css` file in the build output. + +If you are concerned about using Webpack-specific semantics, you can put all your CSS right into `src/index.css`. It would still be imported from `src/index.js`, but you could always remove that import if you later migrate to a different build tool. + +## Post-Processing CSS + +This project setup minifies your CSS and adds vendor prefixes to it automatically through [Autoprefixer](https://github.com/postcss/autoprefixer) so you don’t need to worry about it. + +For example, this: + +```css +.App { + display: flex; + flex-direction: row; + align-items: center; +} +``` + +becomes this: + +```css +.App { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-orient: horizontal; + -webkit-box-direction: normal; + -ms-flex-direction: row; + flex-direction: row; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; +} +``` + +If you need to disable autoprefixing for some reason, [follow this section](https://github.com/postcss/autoprefixer#disabling). + +## Adding a CSS Preprocessor (Sass, Less etc.) + +Generally, we recommend that you don’t reuse the same CSS classes across different components. For example, instead of using a `.Button` CSS class in `<AcceptButton>` and `<RejectButton>` components, we recommend creating a `<Button>` component with its own `.Button` styles, that both `<AcceptButton>` and `<RejectButton>` can render (but [not inherit](https://facebook.github.io/react/docs/composition-vs-inheritance.html)). + +Following this rule often makes CSS preprocessors less useful, as features like mixins and nesting are replaced by component composition. You can, however, integrate a CSS preprocessor if you find it valuable. In this walkthrough, we will be using Sass, but you can also use Less, or another alternative. + +First, let’s install the command-line interface for Sass: + +```sh +npm install --save node-sass-chokidar +``` + +Alternatively you may use `yarn`: + +```sh +yarn add node-sass-chokidar +``` + +Then in `package.json`, add the following lines to `scripts`: + +```diff + "scripts": { ++ "build-css": "node-sass-chokidar src/ -o src/", ++ "watch-css": "npm run build-css && node-sass-chokidar src/ -o src/ --watch --recursive", + "start": "react-scripts start", + "build": "react-scripts build", + "test": "react-scripts test --env=jsdom", +``` + +>Note: To use a different preprocessor, replace `build-css` and `watch-css` commands according to your preprocessor’s documentation. + +Now you can rename `src/App.css` to `src/App.scss` and run `npm run watch-css`. The watcher will find every Sass file in `src` subdirectories, and create a corresponding CSS file next to it, in our case overwriting `src/App.css`. Since `src/App.js` still imports `src/App.css`, the styles become a part of your application. You can now edit `src/App.scss`, and `src/App.css` will be regenerated. + +To share variables between Sass files, you can use Sass imports. For example, `src/App.scss` and other component style files could include `@import "./shared.scss";` with variable definitions. + +To enable importing files without using relative paths, you can add the `--include-path` option to the command in `package.json`. + +``` +"build-css": "node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/", +"watch-css": "npm run build-css && node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/ --watch --recursive", +``` + +This will allow you to do imports like + +```scss +@import 'styles/_colors.scss'; // assuming a styles directory under src/ +@import 'nprogress/nprogress'; // importing a css file from the nprogress node module +``` + +At this point you might want to remove all CSS files from the source control, and add `src/**/*.css` to your `.gitignore` file. It is generally a good practice to keep the build products outside of the source control. + +As a final step, you may find it convenient to run `watch-css` automatically with `npm start`, and run `build-css` as a part of `npm run build`. You can use the `&&` operator to execute two scripts sequentially. However, there is no cross-platform way to run two scripts in parallel, so we will install a package for this: + +```sh +npm install --save npm-run-all +``` + +Alternatively you may use `yarn`: + +```sh +yarn add npm-run-all +``` + +Then we can change `start` and `build` scripts to include the CSS preprocessor commands: + +```diff + "scripts": { + "build-css": "node-sass-chokidar src/ -o src/", + "watch-css": "npm run build-css && node-sass-chokidar src/ -o src/ --watch --recursive", +- "start": "react-scripts start", +- "build": "react-scripts build", ++ "start-js": "react-scripts start", ++ "start": "npm-run-all -p watch-css start-js", ++ "build": "npm run build-css && react-scripts build", + "test": "react-scripts test --env=jsdom", + "eject": "react-scripts eject" + } +``` + +Now running `npm start` and `npm run build` also builds Sass files. + +**Why `node-sass-chokidar`?** + +`node-sass` has been reported as having the following issues: + +- `node-sass --watch` has been reported to have *performance issues* in certain conditions when used in a virtual machine or with docker. + +- Infinite styles compiling [#1939](https://github.com/facebookincubator/create-react-app/issues/1939) + +- `node-sass` has been reported as having issues with detecting new files in a directory [#1891](https://github.com/sass/node-sass/issues/1891) + + `node-sass-chokidar` is used here as it addresses these issues. + +## Adding Images, Fonts, and Files + +With Webpack, using static assets like images and fonts works similarly to CSS. + +You can **`import` a file right in a JavaScript module**. This tells Webpack to include that file in the bundle. Unlike CSS imports, importing a file gives you a string value. This value is the final path you can reference in your code, e.g. as the `src` attribute of an image or the `href` of a link to a PDF. + +To reduce the number of requests to the server, importing images that are less than 10,000 bytes returns a [data URI](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) instead of a path. This applies to the following file extensions: bmp, gif, jpg, jpeg, and png. SVG files are excluded due to [#1153](https://github.com/facebookincubator/create-react-app/issues/1153). + +Here is an example: + +```js +import React from 'react'; +import logo from './logo.png'; // Tell Webpack this JS file uses this image + +console.log(logo); // /logo.84287d09.png + +function Header() { + // Import result is the URL of your image + return <img src={logo} alt="Logo" />; +} + +export default Header; +``` + +This ensures that when the project is built, Webpack will correctly move the images into the build folder, and provide us with correct paths. + +This works in CSS too: + +```css +.Logo { + background-image: url(./logo.png); +} +``` + +Webpack finds all relative module references in CSS (they start with `./`) and replaces them with the final paths from the compiled bundle. If you make a typo or accidentally delete an important file, you will see a compilation error, just like when you import a non-existent JavaScript module. The final filenames in the compiled bundle are generated by Webpack from content hashes. If the file content changes in the future, Webpack will give it a different name in production so you don’t need to worry about long-term caching of assets. + +Please be advised that this is also a custom feature of Webpack. + +**It is not required for React** but many people enjoy it (and React Native uses a similar mechanism for images).<br> +An alternative way of handling static assets is described in the next section. + +## Using the `public` Folder + +>Note: this feature is available with `react-scripts@0.5.0` and higher. + +### Changing the HTML + +The `public` folder contains the HTML file so you can tweak it, for example, to [set the page title](#changing-the-page-title). +The `<script>` tag with the compiled code will be added to it automatically during the build process. + +### Adding Assets Outside of the Module System + +You can also add other assets to the `public` folder. + +Note that we normally encourage you to `import` assets in JavaScript files instead. +For example, see the sections on [adding a stylesheet](#adding-a-stylesheet) and [adding images and fonts](#adding-images-fonts-and-files). +This mechanism provides a number of benefits: + +* Scripts and stylesheets get minified and bundled together to avoid extra network requests. +* Missing files cause compilation errors instead of 404 errors for your users. +* Result filenames include content hashes so you don’t need to worry about browsers caching their old versions. + +However there is an **escape hatch** that you can use to add an asset outside of the module system. + +If you put a file into the `public` folder, it will **not** be processed by Webpack. Instead it will be copied into the build folder untouched. To reference assets in the `public` folder, you need to use a special variable called `PUBLIC_URL`. + +Inside `index.html`, you can use it like this: + +```html +<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico"> +``` + +Only files inside the `public` folder will be accessible by `%PUBLIC_URL%` prefix. If you need to use a file from `src` or `node_modules`, you’ll have to copy it there to explicitly specify your intention to make this file a part of the build. + +When you run `npm run build`, Create React App will substitute `%PUBLIC_URL%` with a correct absolute path so your project works even if you use client-side routing or host it at a non-root URL. + +In JavaScript code, you can use `process.env.PUBLIC_URL` for similar purposes: + +```js +render() { + // Note: this is an escape hatch and should be used sparingly! + // Normally we recommend using `import` for getting asset URLs + // as described in “Adding Images and Fonts” above this section. + return <img src={process.env.PUBLIC_URL + '/img/logo.png'} />; +} +``` + +Keep in mind the downsides of this approach: + +* None of the files in `public` folder get post-processed or minified. +* Missing files will not be called at compilation time, and will cause 404 errors for your users. +* Result filenames won’t include content hashes so you’ll need to add query arguments or rename them every time they change. + +### When to Use the `public` Folder + +Normally we recommend importing [stylesheets](#adding-a-stylesheet), [images, and fonts](#adding-images-fonts-and-files) from JavaScript. +The `public` folder is useful as a workaround for a number of less common cases: + +* You need a file with a specific name in the build output, such as [`manifest.webmanifest`](https://developer.mozilla.org/en-US/docs/Web/Manifest). +* You have thousands of images and need to dynamically reference their paths. +* You want to include a small script like [`pace.js`](http://github.hubspot.com/pace/docs/welcome/) outside of the bundled code. +* Some library may be incompatible with Webpack and you have no other option but to include it as a `<script>` tag. + +Note that if you add a `<script>` that declares global variables, you also need to read the next section on using them. + +## Using Global Variables + +When you include a script in the HTML file that defines global variables and try to use one of these variables in the code, the linter will complain because it cannot see the definition of the variable. + +You can avoid this by reading the global variable explicitly from the `window` object, for example: + +```js +const $ = window.$; +``` + +This makes it obvious you are using a global variable intentionally rather than because of a typo. + +Alternatively, you can force the linter to ignore any line by adding `// eslint-disable-line` after it. + +## Adding Bootstrap + +You don’t have to use [React Bootstrap](https://react-bootstrap.github.io) together with React but it is a popular library for integrating Bootstrap with React apps. If you need it, you can integrate it with Create React App by following these steps: + +Install React Bootstrap and Bootstrap from npm. React Bootstrap does not include Bootstrap CSS so this needs to be installed as well: + +```sh +npm install --save react-bootstrap bootstrap@3 +``` + +Alternatively you may use `yarn`: + +```sh +yarn add react-bootstrap bootstrap@3 +``` + +Import Bootstrap CSS and optionally Bootstrap theme CSS in the beginning of your ```src/index.js``` file: + +```js +import 'bootstrap/dist/css/bootstrap.css'; +import 'bootstrap/dist/css/bootstrap-theme.css'; +// Put any other imports below so that CSS from your +// components takes precedence over default styles. +``` + +Import required React Bootstrap components within ```src/App.js``` file or your custom component files: + +```js +import { Navbar, Jumbotron, Button } from 'react-bootstrap'; +``` + +Now you are ready to use the imported React Bootstrap components within your component hierarchy defined in the render method. Here is an example [`App.js`](https://gist.githubusercontent.com/gaearon/85d8c067f6af1e56277c82d19fd4da7b/raw/6158dd991b67284e9fc8d70b9d973efe87659d72/App.js) redone using React Bootstrap. + +### Using a Custom Theme + +Sometimes you might need to tweak the visual styles of Bootstrap (or equivalent package).<br> +We suggest the following approach: + +* Create a new package that depends on the package you wish to customize, e.g. Bootstrap. +* Add the necessary build steps to tweak the theme, and publish your package on npm. +* Install your own theme npm package as a dependency of your app. + +Here is an example of adding a [customized Bootstrap](https://medium.com/@tacomanator/customizing-create-react-app-aa9ffb88165) that follows these steps. + +## Adding Flow + +Flow is a static type checker that helps you write code with fewer bugs. Check out this [introduction to using static types in JavaScript](https://medium.com/@preethikasireddy/why-use-static-types-in-javascript-part-1-8382da1e0adb) if you are new to this concept. + +Recent versions of [Flow](http://flowtype.org/) work with Create React App projects out of the box. + +To add Flow to a Create React App project, follow these steps: + +1. Run `npm install --save flow-bin` (or `yarn add flow-bin`). +2. Add `"flow": "flow"` to the `scripts` section of your `package.json`. +3. Run `npm run flow init` (or `yarn flow init`) to create a [`.flowconfig` file](https://flowtype.org/docs/advanced-configuration.html) in the root directory. +4. Add `// @flow` to any files you want to type check (for example, to `src/App.js`). + +Now you can run `npm run flow` (or `yarn flow`) to check the files for type errors. +You can optionally use an IDE like [Nuclide](https://nuclide.io/docs/languages/flow/) for a better integrated experience. +In the future we plan to integrate it into Create React App even more closely. + +To learn more about Flow, check out [its documentation](https://flowtype.org/). + +## Adding Custom Environment Variables + +>Note: this feature is available with `react-scripts@0.2.3` and higher. + +Your project can consume variables declared in your environment as if they were declared locally in your JS files. By +default you will have `NODE_ENV` defined for you, and any other environment variables starting with +`REACT_APP_`. + +**The environment variables are embedded during the build time**. Since Create React App produces a static HTML/CSS/JS bundle, it can’t possibly read them at runtime. To read them at runtime, you would need to load HTML into memory on the server and replace placeholders in runtime, just like [described here](#injecting-data-from-the-server-into-the-page). Alternatively you can rebuild the app on the server anytime you change them. + +>Note: You must create custom environment variables beginning with `REACT_APP_`. Any other variables except `NODE_ENV` will be ignored to avoid accidentally [exposing a private key on the machine that could have the same name](https://github.com/facebookincubator/create-react-app/issues/865#issuecomment-252199527). Changing any environment variables will require you to restart the development server if it is running. + +These environment variables will be defined for you on `process.env`. For example, having an environment +variable named `REACT_APP_SECRET_CODE` will be exposed in your JS as `process.env.REACT_APP_SECRET_CODE`. + +There is also a special built-in environment variable called `NODE_ENV`. You can read it from `process.env.NODE_ENV`. When you run `npm start`, it is always equal to `'development'`, when you run `npm test` it is always equal to `'test'`, and when you run `npm run build` to make a production bundle, it is always equal to `'production'`. **You cannot override `NODE_ENV` manually.** This prevents developers from accidentally deploying a slow development build to production. + +These environment variables can be useful for displaying information conditionally based on where the project is +deployed or consuming sensitive data that lives outside of version control. + +First, you need to have environment variables defined. For example, let’s say you wanted to consume a secret defined +in the environment inside a `<form>`: + +```jsx +render() { + return ( + <div> + <small>You are running this application in <b>{process.env.NODE_ENV}</b> mode.</small> + <form> + <input type="hidden" defaultValue={process.env.REACT_APP_SECRET_CODE} /> + </form> + </div> + ); +} +``` + +During the build, `process.env.REACT_APP_SECRET_CODE` will be replaced with the current value of the `REACT_APP_SECRET_CODE` environment variable. Remember that the `NODE_ENV` variable will be set for you automatically. + +When you load the app in the browser and inspect the `<input>`, you will see its value set to `abcdef`, and the bold text will show the environment provided when using `npm start`: + +```html +<div> + <small>You are running this application in <b>development</b> mode.</small> + <form> + <input type="hidden" value="abcdef" /> + </form> +</div> +``` + +The above form is looking for a variable called `REACT_APP_SECRET_CODE` from the environment. In order to consume this +value, we need to have it defined in the environment. This can be done using two ways: either in your shell or in +a `.env` file. Both of these ways are described in the next few sections. + +Having access to the `NODE_ENV` is also useful for performing actions conditionally: + +```js +if (process.env.NODE_ENV !== 'production') { + analytics.disable(); +} +``` + +When you compile the app with `npm run build`, the minification step will strip out this condition, and the resulting bundle will be smaller. + +### Referencing Environment Variables in the HTML + +>Note: this feature is available with `react-scripts@0.9.0` and higher. + +You can also access the environment variables starting with `REACT_APP_` in the `public/index.html`. For example: + +```html +<title>%REACT_APP_WEBSITE_NAME% +``` + +Note that the caveats from the above section apply: + +* Apart from a few built-in variables (`NODE_ENV` and `PUBLIC_URL`), variable names must start with `REACT_APP_` to work. +* The environment variables are injected at build time. If you need to inject them at runtime, [follow this approach instead](#generating-dynamic-meta-tags-on-the-server). + +### Adding Temporary Environment Variables In Your Shell + +Defining environment variables can vary between OSes. It’s also important to know that this manner is temporary for the +life of the shell session. + +#### Windows (cmd.exe) + +```cmd +set REACT_APP_SECRET_CODE=abcdef&&npm start +``` + +(Note: the lack of whitespace is intentional.) + +#### Linux, macOS (Bash) + +```bash +REACT_APP_SECRET_CODE=abcdef npm start +``` + +### Adding Development Environment Variables In `.env` + +>Note: this feature is available with `react-scripts@0.5.0` and higher. + +To define permanent environment variables, create a file called `.env` in the root of your project: + +``` +REACT_APP_SECRET_CODE=abcdef +``` + +`.env` files **should be** checked into source control (with the exclusion of `.env*.local`). + +#### What other `.env` files are can be used? + +>Note: this feature is **available with `react-scripts@1.0.0` and higher**. + +* `.env`: Default. +* `.env.local`: Local overrides. **This file is loaded for all environments except test.** +* `.env.development`, `.env.test`, `.env.production`: Environment-specific settings. +* `.env.development.local`, `.env.test.local`, `.env.production.local`: Local overrides of environment-specific settings. + +Files on the left have more priority than files on the right: + +* `npm start`: `.env.development.local`, `.env.development`, `.env.local`, `.env` +* `npm run build`: `.env.production.local`, `.env.production`, `.env.local`, `.env` +* `npm test`: `.env.test.local`, `.env.test`, `.env` (note `.env.local` is missing) + +These variables will act as the defaults if the machine does not explicitly set them.
+Please refer to the [dotenv documentation](https://github.com/motdotla/dotenv) for more details. + +>Note: If you are defining environment variables for development, your CI and/or hosting platform will most likely need +these defined as well. Consult their documentation how to do this. For example, see the documentation for [Travis CI](https://docs.travis-ci.com/user/environment-variables/) or [Heroku](https://devcenter.heroku.com/articles/config-vars). + +## Can I Use Decorators? + +Many popular libraries use [decorators](https://medium.com/google-developers/exploring-es7-decorators-76ecb65fb841) in their documentation.
+Create React App doesn’t support decorator syntax at the moment because: + +* It is an experimental proposal and is subject to change. +* The current specification version is not officially supported by Babel. +* If the specification changes, we won’t be able to write a codemod because we don’t use them internally at Facebook. + +However in many cases you can rewrite decorator-based code without decorators just as fine.
+Please refer to these two threads for reference: + +* [#214](https://github.com/facebookincubator/create-react-app/issues/214) +* [#411](https://github.com/facebookincubator/create-react-app/issues/411) + +Create React App will add decorator support when the specification advances to a stable stage. + +## Integrating with an API Backend + +These tutorials will help you to integrate your app with an API backend running on another port, +using `fetch()` to access it. + +### Node +Check out [this tutorial](https://www.fullstackreact.com/articles/using-create-react-app-with-a-server/). +You can find the companion GitHub repository [here](https://github.com/fullstackreact/food-lookup-demo). + +### Ruby on Rails + +Check out [this tutorial](https://www.fullstackreact.com/articles/how-to-get-create-react-app-to-work-with-your-rails-api/). +You can find the companion GitHub repository [here](https://github.com/fullstackreact/food-lookup-demo-rails). + +## Proxying API Requests in Development + +>Note: this feature is available with `react-scripts@0.2.3` and higher. + +People often serve the front-end React app from the same host and port as their backend implementation.
+For example, a production setup might look like this after the app is deployed: + +``` +/ - static server returns index.html with React app +/todos - static server returns index.html with React app +/api/todos - server handles any /api/* requests using the backend implementation +``` + +Such setup is **not** required. However, if you **do** have a setup like this, it is convenient to write requests like `fetch('/api/todos')` without worrying about redirecting them to another host or port during development. + +To tell the development server to proxy any unknown requests to your API server in development, add a `proxy` field to your `package.json`, for example: + +```js + "proxy": "http://localhost:4000", +``` + +This way, when you `fetch('/api/todos')` in development, the development server will recognize that it’s not a static asset, and will proxy your request to `http://localhost:4000/api/todos` as a fallback. The development server will only attempt to send requests without a `text/html` accept header to the proxy. + +Conveniently, this avoids [CORS issues](http://stackoverflow.com/questions/21854516/understanding-ajax-cors-and-security-considerations) and error messages like this in development: + +``` +Fetch API cannot load http://localhost:4000/api/todos. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. +``` + +Keep in mind that `proxy` only has effect in development (with `npm start`), and it is up to you to ensure that URLs like `/api/todos` point to the right thing in production. You don’t have to use the `/api` prefix. Any unrecognized request without a `text/html` accept header will be redirected to the specified `proxy`. + +The `proxy` option supports HTTP, HTTPS and WebSocket connections.
+If the `proxy` option is **not** flexible enough for you, alternatively you can: + +* [Configure the proxy yourself](#configuring-the-proxy-manually) +* Enable CORS on your server ([here’s how to do it for Express](http://enable-cors.org/server_expressjs.html)). +* Use [environment variables](#adding-custom-environment-variables) to inject the right server host and port into your app. + +### "Invalid Host Header" Errors After Configuring Proxy + +When you enable the `proxy` option, you opt into a more strict set of host checks. This is necessary because leaving the backend open to remote hosts makes your computer vulnerable to DNS rebinding attacks. The issue is explained in [this article](https://medium.com/webpack/webpack-dev-server-middleware-security-issues-1489d950874a) and [this issue](https://github.com/webpack/webpack-dev-server/issues/887). + +This shouldn’t affect you when developing on `localhost`, but if you develop remotely like [described here](https://github.com/facebookincubator/create-react-app/issues/2271), you will see this error in the browser after enabling the `proxy` option: + +>Invalid Host header + +To work around it, you can specify your public development host in a file called `.env.development` in the root of your project: + +``` +HOST=mypublicdevhost.com +``` + +If you restart the development server now and load the app from the specified host, it should work. + +If you are still having issues or if you’re using a more exotic environment like a cloud editor, you can bypass the host check completely by adding a line to `.env.development.local`. **Note that this is dangerous and exposes your machine to remote code execution from malicious websites:** + +``` +# NOTE: THIS IS DANGEROUS! +# It exposes your machine to attacks from the websites you visit. +DANGEROUSLY_DISABLE_HOST_CHECK=true +``` + +We don’t recommend this approach. + +### Configuring the Proxy Manually + +>Note: this feature is available with `react-scripts@1.0.0` and higher. + +If the `proxy` option is **not** flexible enough for you, you can specify an object in the following form (in `package.json`).
+You may also specify any configuration value [`http-proxy-middleware`](https://github.com/chimurai/http-proxy-middleware#options) or [`http-proxy`](https://github.com/nodejitsu/node-http-proxy#options) supports. +```js +{ + // ... + "proxy": { + "/api": { + "target": "", + "ws": true + // ... + } + } + // ... +} +``` + +All requests matching this path will be proxies, no exceptions. This includes requests for `text/html`, which the standard `proxy` option does not proxy. + +If you need to specify multiple proxies, you may do so by specifying additional entries. +You may also narrow down matches using `*` and/or `**`, to match the path exactly or any subpath. +```js +{ + // ... + "proxy": { + // Matches any request starting with /api + "/api": { + "target": "", + "ws": true + // ... + }, + // Matches any request starting with /foo + "/foo": { + "target": "", + "ssl": true, + "pathRewrite": { + "^/foo": "/foo/beta" + } + // ... + }, + // Matches /bar/abc.html but not /bar/sub/def.html + "/bar/*.html": { + "target": "", + // ... + }, + // Matches /baz/abc.html and /baz/sub/def.html + "/baz/**/*.html": { + "target": "" + // ... + } + } + // ... +} +``` + +### Configuring a WebSocket Proxy + +When setting up a WebSocket proxy, there are a some extra considerations to be aware of. + +If you’re using a WebSocket engine like [Socket.io](https://socket.io/), you must have a Socket.io server running that you can use as the proxy target. Socket.io will not work with a standard WebSocket server. Specifically, don't expect Socket.io to work with [the websocket.org echo test](http://websocket.org/echo.html). + +There’s some good documentation available for [setting up a Socket.io server](https://socket.io/docs/). + +Standard WebSockets **will** work with a standard WebSocket server as well as the websocket.org echo test. You can use libraries like [ws](https://github.com/websockets/ws) for the server, with [native WebSockets in the browser](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket). + +Either way, you can proxy WebSocket requests manually in `package.json`: + +```js +{ + // ... + "proxy": { + "/socket": { + // Your compatible WebSocket server + "target": "ws://", + // Tell http-proxy-middleware that this is a WebSocket proxy. + // Also allows you to proxy WebSocket requests without an additional HTTP request + // https://github.com/chimurai/http-proxy-middleware#external-websocket-upgrade + "ws": true + // ... + } + } + // ... +} +``` + +## Using HTTPS in Development + +>Note: this feature is available with `react-scripts@0.4.0` and higher. + +You may require the dev server to serve pages over HTTPS. One particular case where this could be useful is when using [the "proxy" feature](#proxying-api-requests-in-development) to proxy requests to an API server when that API server is itself serving HTTPS. + +To do this, set the `HTTPS` environment variable to `true`, then start the dev server as usual with `npm start`: + +#### Windows (cmd.exe) + +```cmd +set HTTPS=true&&npm start +``` + +(Note: the lack of whitespace is intentional.) + +#### Linux, macOS (Bash) + +```bash +HTTPS=true npm start +``` + +Note that the server will use a self-signed certificate, so your web browser will almost definitely display a warning upon accessing the page. + +## Generating Dynamic `` Tags on the Server + +Since Create React App doesn’t support server rendering, you might be wondering how to make `` tags dynamic and reflect the current URL. To solve this, we recommend to add placeholders into the HTML, like this: + +```html + + + + + +``` + +Then, on the server, regardless of the backend you use, you can read `index.html` into memory and replace `__OG_TITLE__`, `__OG_DESCRIPTION__`, and any other placeholders with values depending on the current URL. Just make sure to sanitize and escape the interpolated values so that they are safe to embed into HTML! + +If you use a Node server, you can even share the route matching logic between the client and the server. However duplicating it also works fine in simple cases. + +## Pre-Rendering into Static HTML Files + +If you’re hosting your `build` with a static hosting provider you can use [react-snapshot](https://www.npmjs.com/package/react-snapshot) to generate HTML pages for each route, or relative link, in your application. These pages will then seamlessly become active, or “hydrated”, when the JavaScript bundle has loaded. + +There are also opportunities to use this outside of static hosting, to take the pressure off the server when generating and caching routes. + +The primary benefit of pre-rendering is that you get the core content of each page _with_ the HTML payload—regardless of whether or not your JavaScript bundle successfully downloads. It also increases the likelihood that each route of your application will be picked up by search engines. + +You can read more about [zero-configuration pre-rendering (also called snapshotting) here](https://medium.com/superhighfives/an-almost-static-stack-6df0a2791319). + +## Injecting Data from the Server into the Page + +Similarly to the previous section, you can leave some placeholders in the HTML that inject global variables, for example: + +```js + + + + +``` + +Then, on the server, you can replace `__SERVER_DATA__` with a JSON of real data right before sending the response. The client code can then read `window.SERVER_DATA` to use it. **Make sure to [sanitize the JSON before sending it to the client](https://medium.com/node-security/the-most-common-xss-vulnerability-in-react-js-applications-2bdffbcc1fa0) as it makes your app vulnerable to XSS attacks.** + +## Running Tests + +>Note: this feature is available with `react-scripts@0.3.0` and higher.
+>[Read the migration guide to learn how to enable it in older projects!](https://github.com/facebookincubator/create-react-app/blob/master/CHANGELOG.md#migrating-from-023-to-030) + +Create React App uses [Jest](https://facebook.github.io/jest/) as its test runner. To prepare for this integration, we did a [major revamp](https://facebook.github.io/jest/blog/2016/09/01/jest-15.html) of Jest so if you heard bad things about it years ago, give it another try. + +Jest is a Node-based runner. This means that the tests always run in a Node environment and not in a real browser. This lets us enable fast iteration speed and prevent flakiness. + +While Jest provides browser globals such as `window` thanks to [jsdom](https://github.com/tmpvar/jsdom), they are only approximations of the real browser behavior. Jest is intended to be used for unit tests of your logic and your components rather than the DOM quirks. + +We recommend that you use a separate tool for browser end-to-end tests if you need them. They are beyond the scope of Create React App. + +### Filename Conventions + +Jest will look for test files with any of the following popular naming conventions: + +* Files with `.js` suffix in `__tests__` folders. +* Files with `.test.js` suffix. +* Files with `.spec.js` suffix. + +The `.test.js` / `.spec.js` files (or the `__tests__` folders) can be located at any depth under the `src` top level folder. + +We recommend to put the test files (or `__tests__` folders) next to the code they are testing so that relative imports appear shorter. For example, if `App.test.js` and `App.js` are in the same folder, the test just needs to `import App from './App'` instead of a long relative path. Colocation also helps find tests more quickly in larger projects. + +### Command Line Interface + +When you run `npm test`, Jest will launch in the watch mode. Every time you save a file, it will re-run the tests, just like `npm start` recompiles the code. + +The watcher includes an interactive command-line interface with the ability to run all tests, or focus on a search pattern. It is designed this way so that you can keep it open and enjoy fast re-runs. You can learn the commands from the “Watch Usage” note that the watcher prints after every run: + +![Jest watch mode](http://facebook.github.io/jest/img/blog/15-watch.gif) + +### Version Control Integration + +By default, when you run `npm test`, Jest will only run the tests related to files changed since the last commit. This is an optimization designed to make your tests run fast regardless of how many tests you have. However it assumes that you don’t often commit the code that doesn’t pass the tests. + +Jest will always explicitly mention that it only ran tests related to the files changed since the last commit. You can also press `a` in the watch mode to force Jest to run all tests. + +Jest will always run all tests on a [continuous integration](#continuous-integration) server or if the project is not inside a Git or Mercurial repository. + +### Writing Tests + +To create tests, add `it()` (or `test()`) blocks with the name of the test and its code. You may optionally wrap them in `describe()` blocks for logical grouping but this is neither required nor recommended. + +Jest provides a built-in `expect()` global function for making assertions. A basic test could look like this: + +```js +import sum from './sum'; + +it('sums numbers', () => { + expect(sum(1, 2)).toEqual(3); + expect(sum(2, 2)).toEqual(4); +}); +``` + +All `expect()` matchers supported by Jest are [extensively documented here](http://facebook.github.io/jest/docs/expect.html).
+You can also use [`jest.fn()` and `expect(fn).toBeCalled()`](http://facebook.github.io/jest/docs/expect.html#tohavebeencalled) to create “spies” or mock functions. + +### Testing Components + +There is a broad spectrum of component testing techniques. They range from a “smoke test” verifying that a component renders without throwing, to shallow rendering and testing some of the output, to full rendering and testing component lifecycle and state changes. + +Different projects choose different testing tradeoffs based on how often components change, and how much logic they contain. If you haven’t decided on a testing strategy yet, we recommend that you start with creating simple smoke tests for your components: + +```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); +}); +``` + +This test mounts a component and makes sure that it didn’t throw during rendering. Tests like this provide a lot value with very little effort so they are great as a starting point, and this is the test you will find in `src/App.test.js`. + +When you encounter bugs caused by changing components, you will gain a deeper insight into which parts of them are worth testing in your application. This might be a good time to introduce more specific tests asserting specific expected output or behavior. + +If you’d like to test components in isolation from the child components they render, we recommend using [`shallow()` rendering API](http://airbnb.io/enzyme/docs/api/shallow.html) from [Enzyme](http://airbnb.io/enzyme/). To install it, run: + +```sh +npm install --save enzyme react-test-renderer +``` + +Alternatively you may use `yarn`: + +```sh +yarn add enzyme react-test-renderer +``` + +You can write a smoke test with it too: + +```js +import React from 'react'; +import { shallow } from 'enzyme'; +import App from './App'; + +it('renders without crashing', () => { + shallow(); +}); +``` + +Unlike the previous smoke test using `ReactDOM.render()`, this test only renders `` and doesn’t go deeper. For example, even if `` itself renders a ` + + + + + ) }; diff --git a/client/src/containers/AuthLayerContainer.js b/client/src/containers/AuthLayerContainer.js index a6199729..2261f899 100644 --- a/client/src/containers/AuthLayerContainer.js +++ b/client/src/containers/AuthLayerContainer.js @@ -15,6 +15,7 @@ const mapDispatchToProps = dispatch => { e.preventDefault(); const form = e.target; const creds = serialize(form, { hash: true }); + console.log(creds); dispatch(loginUser(creds)); } } From a09b436112ad63d47a072ae7301d44f04a471c07 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Wed, 19 Jul 2017 14:41:24 -0400 Subject: [PATCH 045/112] add jwt decoding --- client/package.json | 1 + client/src/reducers/auth.js | 6 +++++- client/yarn.lock | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/client/package.json b/client/package.json index 7e1d3cd5..4751185a 100644 --- a/client/package.json +++ b/client/package.json @@ -6,6 +6,7 @@ "dependencies": { "bootswatch": "^3.3.7", "form-serialize": "^0.7.2", + "jwt-decode": "^2.2.0", "react": "^15.6.1", "react-bootstrap": "^0.31.1", "react-dom": "^15.6.1", diff --git a/client/src/reducers/auth.js b/client/src/reducers/auth.js index 31907122..dd9615e3 100644 --- a/client/src/reducers/auth.js +++ b/client/src/reducers/auth.js @@ -1,13 +1,17 @@ import * as Actions from '../actions/auth'; +import decode from 'jwt-decode'; export const user = (state = {isAuthenticated: false}, action) => { switch (action.type) { case Actions.LOGIN_SUCCESS: + const decoded = decode(action.data); return { ...state, isAuthenticated: true, token: action.data, - isFetching: false + isFetching: false, + email: decoded.email, + id: decoded.id }; case Actions.LOGIN_REQUEST: return { diff --git a/client/yarn.lock b/client/yarn.lock index 1b57c4cf..bfef3810 100644 --- a/client/yarn.lock +++ b/client/yarn.lock @@ -3708,6 +3708,10 @@ jsx-ast-utils@^1.4.0, jsx-ast-utils@^1.4.1: version "1.4.1" resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-1.4.1.tgz#3867213e8dd79bf1e8f2300c0cfc1efb182c0df1" +jwt-decode@^2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/jwt-decode/-/jwt-decode-2.2.0.tgz#7d86bd56679f58ce6a84704a657dd392bba81a79" + keycode@^2.1.2: version "2.1.9" resolved "https://registry.yarnpkg.com/keycode/-/keycode-2.1.9.tgz#964a23c54e4889405b4861a5c9f0480d45141dfa" From 6425c58cab10da4e60a508d64669af5d36cab5e6 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Wed, 19 Jul 2017 15:01:03 -0400 Subject: [PATCH 046/112] add login error alert --- client/src/actions/auth.js | 15 ++++++----- client/src/components/App.js | 23 +++++++++------- client/src/components/AuthLayer.js | 4 +-- client/src/components/Header.js | 23 ++++++++++++++-- client/src/components/Login.js | 4 ++- client/src/components/LoginError.js | 30 +++++++++++++++++++++ client/src/containers/AppContainer.js | 24 +++++++++++++++++ client/src/containers/AuthLayerContainer.js | 4 +-- client/src/index.js | 4 +-- client/src/reducers/auth.js | 4 +-- 10 files changed, 107 insertions(+), 28 deletions(-) create mode 100644 client/src/components/LoginError.js create mode 100644 client/src/containers/AppContainer.js diff --git a/client/src/actions/auth.js b/client/src/actions/auth.js index 8ae7bef0..7892aa84 100644 --- a/client/src/actions/auth.js +++ b/client/src/actions/auth.js @@ -3,27 +3,27 @@ export const LOGIN_SUCCESS = 'LOGIN_SUCCESS' export const LOGIN_FAILURE = 'LOGIN_FAILURE' export const LOGOUT = 'LOGOUT'; -export function loginRequest() { +export function getLoginRequest() { return { type: LOGIN_REQUEST }; } -export function loginSuccess(data) { +export function getLoginSuccess(data) { return { type: LOGIN_SUCCESS, data }; } -export function loginFailure(error) { +export function getLoginFailure(error) { return { type: LOGIN_FAILURE, error }; } -export function logout() { +export function logoutUser() { return { type: LOGOUT } @@ -38,7 +38,7 @@ export function loginUser(creds) { }; return dispatch => { - dispatch(loginRequest()) + dispatch(getLoginRequest()) fetch(`sessions`, config) .then(response => { @@ -49,10 +49,11 @@ export function loginUser(creds) { return response.json(); }) .then(json => { - dispatch(loginSuccess(json.token)); + dispatch(getLoginSuccess(json.token)); }) .catch(error => { - dispatch(loginFailure(error)); + console.log(error); + dispatch(getLoginFailure(error)); }); } } \ No newline at end of file diff --git a/client/src/components/App.js b/client/src/components/App.js index 927c9a8f..5c6d381c 100644 --- a/client/src/components/App.js +++ b/client/src/components/App.js @@ -1,4 +1,4 @@ -import React, { Component } from 'react'; +import React from 'react'; import Header from './Header'; import AuthLayerContainer from '../containers/AuthLayerContainer'; @@ -9,15 +9,18 @@ import AuthLayerContainer from '../containers/AuthLayerContainer'; // also create an app container that passes in isAuthenticated to // header for logout purposes -class App extends Component { - render() { - return ( -
-
- -
- ); - } +const App = ({isAuthenticated, email, onLogout}) => { + return ( +
+
+ +
+ ); } export default App; diff --git a/client/src/components/AuthLayer.js b/client/src/components/AuthLayer.js index 0c85d69e..e2095e19 100644 --- a/client/src/components/AuthLayer.js +++ b/client/src/components/AuthLayer.js @@ -1,9 +1,9 @@ import React from 'react'; import Login from './Login'; -const AuthLayer = ({isAuthenticated, loginUser}) => { +const AuthLayer = ({isAuthenticated, loginUser, authError}) => { if (!isAuthenticated) { - return + return } return ( diff --git a/client/src/components/Header.js b/client/src/components/Header.js index f3f5396e..32062f4a 100644 --- a/client/src/components/Header.js +++ b/client/src/components/Header.js @@ -1,7 +1,21 @@ import React from "react"; -import { Navbar } from "react-bootstrap"; +import { Navbar, Nav, NavItem } from "react-bootstrap"; -const Header = ({ title }) => { +const LogOut = ({isAuthenticated, email, onLogout}) => { + if (!isAuthenticated) { + return null; + } + + return ( + + ) +} + +const Header = ({ title, isAuthenticated, email, onLogout }) => { return ( @@ -9,6 +23,11 @@ const Header = ({ title }) => { {title} + ); }; diff --git a/client/src/components/Login.js b/client/src/components/Login.js index a05c4d25..ef861aa7 100644 --- a/client/src/components/Login.js +++ b/client/src/components/Login.js @@ -1,11 +1,13 @@ import React from 'react'; import {Grid, Row, Col, Panel, FormControl, Button} from 'react-bootstrap'; +import LoginError from './LoginError'; -const Login = ({loginUser}) => { +const Login = ({loginUser, error}) => { return ( + {error ? : null}

Login

diff --git a/client/src/components/LoginError.js b/client/src/components/LoginError.js new file mode 100644 index 00000000..5d59ba83 --- /dev/null +++ b/client/src/components/LoginError.js @@ -0,0 +1,30 @@ +import React, { Component } from 'react'; +import {Alert} from 'react-bootstrap'; + +class LoginError extends Component { + constructor() { + super() + this.state = { + visible: true + } + } + + handleAlertDismiss = () => { + this.setState({visible: false}); + } + + render() { + if (this.state.visible) { + return ( + +

Whoops, something went wrong!

+

Please try logging in again.

+
+ ); + } else { + return null; + } + } +} + +export default LoginError; \ No newline at end of file diff --git a/client/src/containers/AppContainer.js b/client/src/containers/AppContainer.js new file mode 100644 index 00000000..d9ee9a91 --- /dev/null +++ b/client/src/containers/AppContainer.js @@ -0,0 +1,24 @@ +import { connect } from "react-redux"; +import App from "../components/App"; +import { logoutUser } from "../actions/auth"; + +const mapStateToProps = state => { + return { + isAuthenticated: state.user.isAuthenticated, + email: state.user.email + }; +}; + +const mapDispatchToProps = dispatch => { + return { + onLogout: e => { + e.preventDefault(); + dispatch(logoutUser()); + } + } +} + + +const AppContainer = connect(mapStateToProps, mapDispatchToProps)(App); + +export default AppContainer; \ No newline at end of file diff --git a/client/src/containers/AuthLayerContainer.js b/client/src/containers/AuthLayerContainer.js index 2261f899..132dcb6b 100644 --- a/client/src/containers/AuthLayerContainer.js +++ b/client/src/containers/AuthLayerContainer.js @@ -5,7 +5,8 @@ import { loginUser } from "../actions/auth"; const mapStateToProps = state => { return { - isAuthenticated: state.user.isAuthenticated + isAuthenticated: state.user.isAuthenticated, + authError: state.user.error }; }; @@ -15,7 +16,6 @@ const mapDispatchToProps = dispatch => { e.preventDefault(); const form = e.target; const creds = serialize(form, { hash: true }); - console.log(creds); dispatch(loginUser(creds)); } } diff --git a/client/src/index.js b/client/src/index.js index 64059367..8b28ea91 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -2,7 +2,7 @@ import React from 'react'; import ReactDOM from 'react-dom'; import "bootswatch/flatly/bootstrap.min.css"; import './index.css'; -import App from './components/App'; +import AppContainer from './containers/AppContainer'; import { Provider } from "react-redux"; import { createStore, applyMiddleware, compose } from "redux"; import thunk from "redux-thunk"; @@ -20,7 +20,7 @@ const store = createStore( ReactDOM.render( - + , document.getElementById("root") ); diff --git a/client/src/reducers/auth.js b/client/src/reducers/auth.js index dd9615e3..16ca70f9 100644 --- a/client/src/reducers/auth.js +++ b/client/src/reducers/auth.js @@ -1,7 +1,7 @@ import * as Actions from '../actions/auth'; import decode from 'jwt-decode'; -export const user = (state = {isAuthenticated: false}, action) => { +export const user = (state = {isAuthenticated: false, error: null}, action) => { switch (action.type) { case Actions.LOGIN_SUCCESS: const decoded = decode(action.data); @@ -24,7 +24,7 @@ export const user = (state = {isAuthenticated: false}, action) => { ...state, isFetching: false, isAuthenticated: false, - error: action.error + error: true }; case Actions.LOGOUT: return { From dca4883c07ca48c52468566db02de91d9bd03b7c Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Wed, 19 Jul 2017 15:04:44 -0400 Subject: [PATCH 047/112] persist user login --- client/src/index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/client/src/index.js b/client/src/index.js index 8b28ea91..84ee203a 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -10,12 +10,19 @@ import djelloApp from "./reducers"; const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; +const persistedState = localStorage.getItem("djelloAppState") + ? JSON.parse(localStorage.getItem("djelloAppState")) + : {}; + const store = createStore( djelloApp, - // persistedState, + {user: persistedState}, composeEnhancers(applyMiddleware(thunk)) ); +store.subscribe(() => { + localStorage.setItem("djelloAppState", JSON.stringify(store.getState().user)); +}); ReactDOM.render( From 691f213fc73c66b30ae625bc77200f7ff5833c5d Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Wed, 19 Jul 2017 15:19:13 -0400 Subject: [PATCH 048/112] add board fetching --- client/src/actions/boards.js | 55 +++++++++++++++++++ client/src/components/AuthLayer.js | 11 +++- client/src/components/BoardPicker.js | 7 +++ client/src/containers/BoardPickerContainer.js | 31 +++++++++++ client/src/reducers/boards.js | 27 +++++++++ client/src/reducers/index.js | 4 +- 6 files changed, 131 insertions(+), 4 deletions(-) create mode 100644 client/src/actions/boards.js create mode 100644 client/src/components/BoardPicker.js create mode 100644 client/src/containers/BoardPickerContainer.js create mode 100644 client/src/reducers/boards.js diff --git a/client/src/actions/boards.js b/client/src/actions/boards.js new file mode 100644 index 00000000..58024f24 --- /dev/null +++ b/client/src/actions/boards.js @@ -0,0 +1,55 @@ +export const GET_ALL_BOARDS_REQUEST = 'GET_ALL_BOARDS_REQUEST' +export const GET_ALL_BOARDS_SUCCESS = 'GET_ALL_BOARDS_SUCCESS' +export const GET_ALL_BOARDS_FAILURE = 'GET_ALL_BOARDS_FAILURE' +export const LOGOUT = 'LOGOUT'; + +export function getAllBoardsRequest() { + return { + type: GET_ALL_BOARDS_REQUEST + }; +} + +export function getAllBoardsSuccess(data) { + return { + type: GET_ALL_BOARDS_SUCCESS, + data + }; +} + +export function getAllBoardsFailure(error) { + return { + type: GET_ALL_BOARDS_FAILURE, + error + }; +} + + +export function getAllBoards(token, userId) { + let config = { + method: 'GET', + headers: { 'Authorization':'Bearer ' + token }, + }; + + return dispatch => { + dispatch(getAllBoardsRequest()) + + fetch(`api/v1/users/${userId}/boards`, config) + .then(response => { + if (!response.ok) { + throw new Error(`${response.status}: ${response.statusText}`); + } + + return response.json(); + }) + .then(json => { + console.log('#########') + console.log(json); + console.log('#########') + dispatch(getAllBoardsSuccess(json)); + }) + .catch(error => { + console.log(error); + dispatch(getAllBoardsFailure(error)); + }); + } + } \ No newline at end of file diff --git a/client/src/components/AuthLayer.js b/client/src/components/AuthLayer.js index e2095e19..f181f15c 100644 --- a/client/src/components/AuthLayer.js +++ b/client/src/components/AuthLayer.js @@ -1,5 +1,7 @@ import React from 'react'; import Login from './Login'; +import {Grid, Row, Col} from 'react-bootstrap'; +import BoardPickerContainer from '../containers/BoardPickerContainer'; const AuthLayer = ({isAuthenticated, loginUser, authError}) => { if (!isAuthenticated) { @@ -7,9 +9,12 @@ const AuthLayer = ({isAuthenticated, loginUser, authError}) => { } return ( -
- You're logged in!!!! -
+ + +

Djello

+ +
+
) }; diff --git a/client/src/components/BoardPicker.js b/client/src/components/BoardPicker.js new file mode 100644 index 00000000..f6aa77fb --- /dev/null +++ b/client/src/components/BoardPicker.js @@ -0,0 +1,7 @@ +import React from 'react'; + +const BoardPicker = () => { + return null; +}; + +export default BoardPicker; \ No newline at end of file diff --git a/client/src/containers/BoardPickerContainer.js b/client/src/containers/BoardPickerContainer.js new file mode 100644 index 00000000..bb714b92 --- /dev/null +++ b/client/src/containers/BoardPickerContainer.js @@ -0,0 +1,31 @@ +import React, { Component } from "react"; +import { connect } from "react-redux"; +import BoardPicker from "../components/BoardPicker"; +import { getAllBoards } from "../actions/boards"; + +class BoardPickerContainer extends Component { + componentDidMount() { + this.props.getAllBoards(this.props.token, this.props.userId); + } + + render() { + return ; + } +} + +const mapStateToProps = state => { + return { + token: state.user.token, + userId: state.user.id + }; +}; + +const mapDispatchToProps = dispatch => { + return { + getAllBoards: (token, userId) => { + dispatch(getAllBoards(token, userId)); + } + }; +}; + +export default connect(mapStateToProps, mapDispatchToProps)(BoardPickerContainer); diff --git a/client/src/reducers/boards.js b/client/src/reducers/boards.js new file mode 100644 index 00000000..1fc22e60 --- /dev/null +++ b/client/src/reducers/boards.js @@ -0,0 +1,27 @@ +import * as Actions from '../actions/boards'; + +export const boards = (state = {}, action) => { + switch (action.type) { + case Actions.GET_ALL_BOARDS_SUCCESS: + return { + ...state, + allBoards: action.data, + specificBoard: action.data[0], + isFetching: false + }; + case Actions.GET_ALL_BOARDS_REQUEST: + return { + ...state, + isFetching: true, + error: null + }; + case Actions.GET_ALL_BOARDS_FAILURE: + return { + ...state, + isFetching: false, + error: true + }; + default: + return state; + } +}; \ No newline at end of file diff --git a/client/src/reducers/index.js b/client/src/reducers/index.js index 06124e4d..0d48626e 100644 --- a/client/src/reducers/index.js +++ b/client/src/reducers/index.js @@ -1,8 +1,10 @@ import { combineReducers } from 'redux'; import {user} from './auth'; +import {boards} from './boards'; const djelloApp = combineReducers({ - user + user, + boards }); export default djelloApp; \ No newline at end of file From 60b04a1fc2a72a7bf020b9394604b1b9ee26dd6c Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Wed, 19 Jul 2017 15:34:17 -0400 Subject: [PATCH 049/112] updating server seeding and board retrieval --- client/src/actions/boards.js | 7 +++--- client/src/reducers/boards.js | 4 +-- server/seeds/seeds.js | 47 +++++++++++++++++++++++++++-------- 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/client/src/actions/boards.js b/client/src/actions/boards.js index 58024f24..690a8c51 100644 --- a/client/src/actions/boards.js +++ b/client/src/actions/boards.js @@ -42,10 +42,9 @@ export function getAllBoards(token, userId) { return response.json(); }) .then(json => { - console.log('#########') - console.log(json); - console.log('#########') - dispatch(getAllBoardsSuccess(json)); + let boardIds = json.data.map(board => board._id); + let specificBoard = json.data[0]; + dispatch(getAllBoardsSuccess({boardIds, specificBoard})); }) .catch(error => { console.log(error); diff --git a/client/src/reducers/boards.js b/client/src/reducers/boards.js index 1fc22e60..8daccd7a 100644 --- a/client/src/reducers/boards.js +++ b/client/src/reducers/boards.js @@ -5,8 +5,8 @@ export const boards = (state = {}, action) => { case Actions.GET_ALL_BOARDS_SUCCESS: return { ...state, - allBoards: action.data, - specificBoard: action.data[0], + allBoards: action.data.boardIds, + specificBoard: action.data.specificBoard, isFetching: false }; case Actions.GET_ALL_BOARDS_REQUEST: diff --git a/server/seeds/seeds.js b/server/seeds/seeds.js index a35a67e3..b2813d1a 100644 --- a/server/seeds/seeds.js +++ b/server/seeds/seeds.js @@ -1,21 +1,48 @@ +const MULTIPLIER = 5; + module.exports = () => { - let users = []; // ---------------------------------------- // Creating Users // ---------------------------------------- - let p = User.create({ - fname: "Foo", - lname: "Bar", - email: "foobar@gmail.com", - password: "password" - }); + console.log('Creating users...'); + let users = []; + for (let i = 0; i < 2; i++) { + let user = new User({ + email: `foobar${i}@gmail.com`, + password: "password" + }); + users.push(user); + } + + // ---------------------------------------- + // Creating Boards + // ---------------------------------------- + console.log('Creating boards...'); + let boards = []; + for (let i = 0; i < MULTIPLIER; i++) { + let board = new Board({ + title: `Test Board ${i + 1}`, + lists: [], + users: [users[i % users.length]] + }); + boards.push(board); + users[i % users.length].boards.push(board); + } + // ---------------------------------------- // Finish // ---------------------------------------- - const promises = [p]; - return Promise.all(promises).then(() => console.log()).catch(e => { - throw e; + console.log('Saving...'); + let promises = []; + [ + users, + boards + ].forEach((collection) => { + collection.forEach((model) => { + promises.push(model.save()); + }); }); + return Promise.all(promises); }; From 60845bdbc8b03c798a237bb4517affabe29b7ade Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Wed, 19 Jul 2017 16:43:17 -0400 Subject: [PATCH 050/112] begin adding coard for selecting specific board --- client/src/actions/boards.js | 110 ++++++++++++++---- client/src/components/AuthLayer.js | 4 +- client/src/components/BoardPicker.js | 19 ++- client/src/containers/BoardPickerContainer.js | 9 +- client/src/reducers/boards.js | 6 +- 5 files changed, 116 insertions(+), 32 deletions(-) diff --git a/client/src/actions/boards.js b/client/src/actions/boards.js index 690a8c51..5bc6f0b3 100644 --- a/client/src/actions/boards.js +++ b/client/src/actions/boards.js @@ -1,6 +1,9 @@ export const GET_ALL_BOARDS_REQUEST = 'GET_ALL_BOARDS_REQUEST' export const GET_ALL_BOARDS_SUCCESS = 'GET_ALL_BOARDS_SUCCESS' export const GET_ALL_BOARDS_FAILURE = 'GET_ALL_BOARDS_FAILURE' +export const GET_SPECIFIC_BOARDS_REQUEST = 'GET_SPECIFIC_BOARDS_REQUEST' +export const GET_SPECIFIC_BOARDS_SUCCESS = 'GET_SPECIFIC_BOARDS_SUCCESS' +export const GET_SPECIFIC_BOARDS_FAILURE = 'GET_SPECIFIC_BOARDS_FAILURE' export const LOGOUT = 'LOGOUT'; export function getAllBoardsRequest() { @@ -23,32 +26,91 @@ export function getAllBoardsFailure(error) { }; } +export function getSpecificBoardsRequest() { + return { + type: GET_SPECIFIC_BOARDS_REQUEST + }; +} + +export function getSpecificBoardsSuccess(data) { + return { + type: GET_SPECIFIC_BOARDS_SUCCESS, + data + }; +} + +export function getSpecificBoardsFailure(error) { + return { + type: GET_SPECIFIC_BOARDS_FAILURE, + error + }; +} + export function getAllBoards(token, userId) { - let config = { - method: 'GET', - headers: { 'Authorization':'Bearer ' + token }, - }; - - return dispatch => { - dispatch(getAllBoardsRequest()) - - fetch(`api/v1/users/${userId}/boards`, config) - .then(response => { - if (!response.ok) { - throw new Error(`${response.status}: ${response.statusText}`); + let config = { + method: 'GET', + headers: { 'Authorization':'Bearer ' + token }, + }; + + return dispatch => { + dispatch(getAllBoardsRequest()) + + fetch(`api/v1/users/${userId}/boards`, config) + .then(response => { + if (!response.ok) { + throw new Error(`${response.status}: ${response.statusText}`); + } + + return response.json(); + }) + .then(json => { + let boardIds = json.data.map(board => { + return { + id: board._id, + title: board.title } + }); + let specificBoard = json.data[0]; + dispatch(getAllBoardsSuccess({boardIds, specificBoard})); + }) + .catch(error => { + console.log(error); + dispatch(getAllBoardsFailure(error)); + }); + } +} + +export function getSelectedBoard(token, userId) { + let config = { + method: 'GET', + headers: { 'Authorization':'Bearer ' + token }, + }; - return response.json(); - }) - .then(json => { - let boardIds = json.data.map(board => board._id); - let specificBoard = json.data[0]; - dispatch(getAllBoardsSuccess({boardIds, specificBoard})); - }) - .catch(error => { - console.log(error); - dispatch(getAllBoardsFailure(error)); + return dispatch => { + dispatch(getAllBoardsRequest()) + + fetch(`api/v1/users/${userId}/boards`, config) + .then(response => { + if (!response.ok) { + throw new Error(`${response.status}: ${response.statusText}`); + } + + return response.json(); + }) + .then(json => { + let boardIds = json.data.map(board => { + return { + id: board._id, + title: board.title + } }); - } - } \ No newline at end of file + let specificBoard = json.data[0]; + dispatch(getAllBoardsSuccess({boardIds, specificBoard})); + }) + .catch(error => { + console.log(error); + dispatch(getAllBoardsFailure(error)); + }); + } +} \ No newline at end of file diff --git a/client/src/components/AuthLayer.js b/client/src/components/AuthLayer.js index f181f15c..67cf07fd 100644 --- a/client/src/components/AuthLayer.js +++ b/client/src/components/AuthLayer.js @@ -12,7 +12,9 @@ const AuthLayer = ({isAuthenticated, loginUser, authError}) => {

Djello

- + + +
) diff --git a/client/src/components/BoardPicker.js b/client/src/components/BoardPicker.js index f6aa77fb..2b12f3af 100644 --- a/client/src/components/BoardPicker.js +++ b/client/src/components/BoardPicker.js @@ -1,7 +1,22 @@ import React from 'react'; +import {FormControl} from 'react-bootstrap'; -const BoardPicker = () => { - return null; + + +const BoardPicker = ({allBoards, onChangeSelectedBoard}) => { + let boardOptions = []; + if (allBoards && allBoards.length > 0) { + boardOptions = allBoards.map(board => ( + + )); + } + return ( + + + {boardOptions} + + + ); }; export default BoardPicker; \ No newline at end of file diff --git a/client/src/containers/BoardPickerContainer.js b/client/src/containers/BoardPickerContainer.js index bb714b92..2cd28ce7 100644 --- a/client/src/containers/BoardPickerContainer.js +++ b/client/src/containers/BoardPickerContainer.js @@ -1,7 +1,7 @@ import React, { Component } from "react"; import { connect } from "react-redux"; import BoardPicker from "../components/BoardPicker"; -import { getAllBoards } from "../actions/boards"; +import { getAllBoards, getSelectedBoard } from "../actions/boards"; class BoardPickerContainer extends Component { componentDidMount() { @@ -16,7 +16,8 @@ class BoardPickerContainer extends Component { const mapStateToProps = state => { return { token: state.user.token, - userId: state.user.id + userId: state.user.id, + allBoards: state.boards.allBoards }; }; @@ -24,6 +25,10 @@ const mapDispatchToProps = dispatch => { return { getAllBoards: (token, userId) => { dispatch(getAllBoards(token, userId)); + }, + onChangeSelectedBoard: e => { + const selectedBoard = e.target.value; + dispatch(getSelectedBoard(selectedBoard)); } }; }; diff --git a/client/src/reducers/boards.js b/client/src/reducers/boards.js index 8daccd7a..ae670566 100644 --- a/client/src/reducers/boards.js +++ b/client/src/reducers/boards.js @@ -7,18 +7,18 @@ export const boards = (state = {}, action) => { ...state, allBoards: action.data.boardIds, specificBoard: action.data.specificBoard, - isFetching: false + isFetchingAll: false }; case Actions.GET_ALL_BOARDS_REQUEST: return { ...state, - isFetching: true, + isFetchingAll: true, error: null }; case Actions.GET_ALL_BOARDS_FAILURE: return { ...state, - isFetching: false, + isFetchingAll: false, error: true }; default: From 6a4d6cf38f5a3fddc60c302b5b1a1cfd8991ab9c Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Wed, 19 Jul 2017 16:50:46 -0400 Subject: [PATCH 051/112] add specific board getting and changing --- client/src/actions/boards.js | 17 +++++------------ client/src/components/AuthLayer.js | 5 +++-- client/src/containers/AuthLayerContainer.js | 4 +++- client/src/containers/BoardPickerContainer.js | 6 +++--- client/src/reducers/boards.js | 18 ++++++++++++++++++ 5 files changed, 32 insertions(+), 18 deletions(-) diff --git a/client/src/actions/boards.js b/client/src/actions/boards.js index 5bc6f0b3..9e848c6c 100644 --- a/client/src/actions/boards.js +++ b/client/src/actions/boards.js @@ -81,16 +81,16 @@ export function getAllBoards(token, userId) { } } -export function getSelectedBoard(token, userId) { +export function getSpecificBoard(token, boardId) { let config = { method: 'GET', headers: { 'Authorization':'Bearer ' + token }, }; return dispatch => { - dispatch(getAllBoardsRequest()) + dispatch(getSpecificBoardsRequest()) - fetch(`api/v1/users/${userId}/boards`, config) + fetch(`api/v1/boards/${boardId}`, config) .then(response => { if (!response.ok) { throw new Error(`${response.status}: ${response.statusText}`); @@ -99,18 +99,11 @@ export function getSelectedBoard(token, userId) { return response.json(); }) .then(json => { - let boardIds = json.data.map(board => { - return { - id: board._id, - title: board.title - } - }); - let specificBoard = json.data[0]; - dispatch(getAllBoardsSuccess({boardIds, specificBoard})); + dispatch(getSpecificBoardsSuccess(json.data)); }) .catch(error => { console.log(error); - dispatch(getAllBoardsFailure(error)); + dispatch(getSpecificBoardsFailure(error)); }); } } \ No newline at end of file diff --git a/client/src/components/AuthLayer.js b/client/src/components/AuthLayer.js index 67cf07fd..945a8f96 100644 --- a/client/src/components/AuthLayer.js +++ b/client/src/components/AuthLayer.js @@ -3,7 +3,7 @@ import Login from './Login'; import {Grid, Row, Col} from 'react-bootstrap'; import BoardPickerContainer from '../containers/BoardPickerContainer'; -const AuthLayer = ({isAuthenticated, loginUser, authError}) => { +const AuthLayer = ({isAuthenticated, loginUser, authError, token, specificBoard}) => { if (!isAuthenticated) { return } @@ -12,8 +12,9 @@ const AuthLayer = ({isAuthenticated, loginUser, authError}) => {

Djello

+

{specificBoard ? specificBoard.title : ""}

- +
diff --git a/client/src/containers/AuthLayerContainer.js b/client/src/containers/AuthLayerContainer.js index 132dcb6b..6886b33e 100644 --- a/client/src/containers/AuthLayerContainer.js +++ b/client/src/containers/AuthLayerContainer.js @@ -6,7 +6,9 @@ import { loginUser } from "../actions/auth"; const mapStateToProps = state => { return { isAuthenticated: state.user.isAuthenticated, - authError: state.user.error + authError: state.user.error, + token: state.user.token, + specificBoard: state.boards.specificBoard }; }; diff --git a/client/src/containers/BoardPickerContainer.js b/client/src/containers/BoardPickerContainer.js index 2cd28ce7..6082f023 100644 --- a/client/src/containers/BoardPickerContainer.js +++ b/client/src/containers/BoardPickerContainer.js @@ -1,7 +1,7 @@ import React, { Component } from "react"; import { connect } from "react-redux"; import BoardPicker from "../components/BoardPicker"; -import { getAllBoards, getSelectedBoard } from "../actions/boards"; +import { getAllBoards, getSpecificBoard } from "../actions/boards"; class BoardPickerContainer extends Component { componentDidMount() { @@ -21,14 +21,14 @@ const mapStateToProps = state => { }; }; -const mapDispatchToProps = dispatch => { +const mapDispatchToProps = (dispatch, ownProps) => { return { getAllBoards: (token, userId) => { dispatch(getAllBoards(token, userId)); }, onChangeSelectedBoard: e => { const selectedBoard = e.target.value; - dispatch(getSelectedBoard(selectedBoard)); + dispatch(getSpecificBoard(ownProps.token, selectedBoard)); } }; }; diff --git a/client/src/reducers/boards.js b/client/src/reducers/boards.js index ae670566..390fad61 100644 --- a/client/src/reducers/boards.js +++ b/client/src/reducers/boards.js @@ -21,6 +21,24 @@ export const boards = (state = {}, action) => { isFetchingAll: false, error: true }; + case Actions.GET_SPECIFIC_BOARDS_SUCCESS: + return { + ...state, + specificBoard: action.data, + isFetchingSpecific: false + }; + case Actions.GET_SPECIFIC_BOARDS_REQUEST: + return { + ...state, + isFetchingSpecific: true, + error: null + }; + case Actions.GET_SPECIFIC_BOARDS_FAILURE: + return { + ...state, + isFetchingSpecific: false, + error: true + }; default: return state; } From cee3b617cffc10d05ee548c83042aa79a334720e Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Wed, 19 Jul 2017 17:00:35 -0400 Subject: [PATCH 052/112] flatten reducers --- client/src/actions/allBoards.js | 58 ++++++++++ client/src/actions/boards.js | 109 ------------------ client/src/actions/specificBoard.js | 49 ++++++++ client/src/containers/AuthLayerContainer.js | 2 +- client/src/containers/BoardPickerContainer.js | 5 +- client/src/reducers/allBoards.js | 26 +++++ client/src/reducers/boards.js | 45 -------- client/src/reducers/index.js | 6 +- client/src/reducers/specificBoard.js | 26 +++++ 9 files changed, 167 insertions(+), 159 deletions(-) create mode 100644 client/src/actions/allBoards.js delete mode 100644 client/src/actions/boards.js create mode 100644 client/src/actions/specificBoard.js create mode 100644 client/src/reducers/allBoards.js delete mode 100644 client/src/reducers/boards.js create mode 100644 client/src/reducers/specificBoard.js diff --git a/client/src/actions/allBoards.js b/client/src/actions/allBoards.js new file mode 100644 index 00000000..51a34b6a --- /dev/null +++ b/client/src/actions/allBoards.js @@ -0,0 +1,58 @@ +import {getSpecificBoardSuccess} from './specificBoard'; +export const GET_ALL_BOARDS_REQUEST = 'GET_ALL_BOARDS_REQUEST' +export const GET_ALL_BOARDS_SUCCESS = 'GET_ALL_BOARDS_SUCCESS' +export const GET_ALL_BOARDS_FAILURE = 'GET_ALL_BOARDS_FAILURE' + +export function getAllBoardsRequest() { + return { + type: GET_ALL_BOARDS_REQUEST + }; +} + +export function getAllBoardsSuccess(data) { + return { + type: GET_ALL_BOARDS_SUCCESS, + data + }; +} + +export function getAllBoardsFailure(error) { + return { + type: GET_ALL_BOARDS_FAILURE, + error + }; +} + +export function getAllBoards(token, userId) { + let config = { + method: 'GET', + headers: { 'Authorization':'Bearer ' + token }, + }; + + return dispatch => { + dispatch(getAllBoardsRequest()) + + fetch(`api/v1/users/${userId}/boards`, config) + .then(response => { + if (!response.ok) { + throw new Error(`${response.status}: ${response.statusText}`); + } + + return response.json(); + }) + .then(json => { + let boardIds = json.data.map(board => { + return { + id: board._id, + title: board.title + } + }); + let specificBoard = json.data[0]; + dispatch(getAllBoardsSuccess(boardIds)); + dispatch(getSpecificBoardSuccess(specificBoard)); + }) + .catch(error => { + dispatch(getAllBoardsFailure(error)); + }); + } +} \ No newline at end of file diff --git a/client/src/actions/boards.js b/client/src/actions/boards.js deleted file mode 100644 index 9e848c6c..00000000 --- a/client/src/actions/boards.js +++ /dev/null @@ -1,109 +0,0 @@ -export const GET_ALL_BOARDS_REQUEST = 'GET_ALL_BOARDS_REQUEST' -export const GET_ALL_BOARDS_SUCCESS = 'GET_ALL_BOARDS_SUCCESS' -export const GET_ALL_BOARDS_FAILURE = 'GET_ALL_BOARDS_FAILURE' -export const GET_SPECIFIC_BOARDS_REQUEST = 'GET_SPECIFIC_BOARDS_REQUEST' -export const GET_SPECIFIC_BOARDS_SUCCESS = 'GET_SPECIFIC_BOARDS_SUCCESS' -export const GET_SPECIFIC_BOARDS_FAILURE = 'GET_SPECIFIC_BOARDS_FAILURE' -export const LOGOUT = 'LOGOUT'; - -export function getAllBoardsRequest() { - return { - type: GET_ALL_BOARDS_REQUEST - }; -} - -export function getAllBoardsSuccess(data) { - return { - type: GET_ALL_BOARDS_SUCCESS, - data - }; -} - -export function getAllBoardsFailure(error) { - return { - type: GET_ALL_BOARDS_FAILURE, - error - }; -} - -export function getSpecificBoardsRequest() { - return { - type: GET_SPECIFIC_BOARDS_REQUEST - }; -} - -export function getSpecificBoardsSuccess(data) { - return { - type: GET_SPECIFIC_BOARDS_SUCCESS, - data - }; -} - -export function getSpecificBoardsFailure(error) { - return { - type: GET_SPECIFIC_BOARDS_FAILURE, - error - }; -} - - -export function getAllBoards(token, userId) { - let config = { - method: 'GET', - headers: { 'Authorization':'Bearer ' + token }, - }; - - return dispatch => { - dispatch(getAllBoardsRequest()) - - fetch(`api/v1/users/${userId}/boards`, config) - .then(response => { - if (!response.ok) { - throw new Error(`${response.status}: ${response.statusText}`); - } - - return response.json(); - }) - .then(json => { - let boardIds = json.data.map(board => { - return { - id: board._id, - title: board.title - } - }); - let specificBoard = json.data[0]; - dispatch(getAllBoardsSuccess({boardIds, specificBoard})); - }) - .catch(error => { - console.log(error); - dispatch(getAllBoardsFailure(error)); - }); - } -} - -export function getSpecificBoard(token, boardId) { - let config = { - method: 'GET', - headers: { 'Authorization':'Bearer ' + token }, - }; - - return dispatch => { - dispatch(getSpecificBoardsRequest()) - - fetch(`api/v1/boards/${boardId}`, config) - .then(response => { - if (!response.ok) { - throw new Error(`${response.status}: ${response.statusText}`); - } - - return response.json(); - }) - .then(json => { - dispatch(getSpecificBoardsSuccess(json.data)); - }) - .catch(error => { - console.log(error); - dispatch(getSpecificBoardsFailure(error)); - }); - } -} \ No newline at end of file diff --git a/client/src/actions/specificBoard.js b/client/src/actions/specificBoard.js new file mode 100644 index 00000000..4966c69e --- /dev/null +++ b/client/src/actions/specificBoard.js @@ -0,0 +1,49 @@ +export const GET_SPECIFIC_BOARD_REQUEST = 'GET_SPECIFIC_BOARD_REQUEST' +export const GET_SPECIFIC_BOARD_SUCCESS = 'GET_SPECIFIC_BOARD_SUCCESS' +export const GET_SPECIFIC_BOARD_FAILURE = 'GET_SPECIFIC_BOARD_FAILURE' + +export function getSpecificBoardRequest() { + return { + type: GET_SPECIFIC_BOARD_REQUEST + }; +} + +export function getSpecificBoardSuccess(data) { + return { + type: GET_SPECIFIC_BOARD_SUCCESS, + data + }; +} + +export function getSpecificBoardFailure(error) { + return { + type: GET_SPECIFIC_BOARD_FAILURE, + error + }; +} + +export function getSpecificBoard(token, boardId) { + let config = { + method: 'GET', + headers: { 'Authorization':'Bearer ' + token }, + }; + + return dispatch => { + dispatch(getSpecificBoardRequest()) + + fetch(`api/v1/boards/${boardId}`, config) + .then(response => { + if (!response.ok) { + throw new Error(`${response.status}: ${response.statusText}`); + } + + return response.json(); + }) + .then(json => { + dispatch(getSpecificBoardSuccess(json.data)); + }) + .catch(error => { + dispatch(getSpecificBoardFailure(error)); + }); + } +} \ No newline at end of file diff --git a/client/src/containers/AuthLayerContainer.js b/client/src/containers/AuthLayerContainer.js index 6886b33e..f5339b1f 100644 --- a/client/src/containers/AuthLayerContainer.js +++ b/client/src/containers/AuthLayerContainer.js @@ -8,7 +8,7 @@ const mapStateToProps = state => { isAuthenticated: state.user.isAuthenticated, authError: state.user.error, token: state.user.token, - specificBoard: state.boards.specificBoard + specificBoard: state.specificBoard.data }; }; diff --git a/client/src/containers/BoardPickerContainer.js b/client/src/containers/BoardPickerContainer.js index 6082f023..174a1038 100644 --- a/client/src/containers/BoardPickerContainer.js +++ b/client/src/containers/BoardPickerContainer.js @@ -1,7 +1,8 @@ import React, { Component } from "react"; import { connect } from "react-redux"; import BoardPicker from "../components/BoardPicker"; -import { getAllBoards, getSpecificBoard } from "../actions/boards"; +import { getAllBoards } from "../actions/allBoards"; +import { getSpecificBoard } from "../actions/specificBoard"; class BoardPickerContainer extends Component { componentDidMount() { @@ -17,7 +18,7 @@ const mapStateToProps = state => { return { token: state.user.token, userId: state.user.id, - allBoards: state.boards.allBoards + allBoards: state.allBoards.data }; }; diff --git a/client/src/reducers/allBoards.js b/client/src/reducers/allBoards.js new file mode 100644 index 00000000..6a450b77 --- /dev/null +++ b/client/src/reducers/allBoards.js @@ -0,0 +1,26 @@ +import * as Actions from '../actions/allBoards'; + +export const allBoards = (state = {}, action) => { + switch (action.type) { + case Actions.GET_ALL_BOARDS_SUCCESS: + return { + ...state, + data: action.data, + isFetching: false + }; + case Actions.GET_ALL_BOARDS_REQUEST: + return { + ...state, + isFetching: true, + error: null + }; + case Actions.GET_ALL_BOARDS_FAILURE: + return { + ...state, + isFetching: false, + error: true + }; + default: + return state; + } +}; \ No newline at end of file diff --git a/client/src/reducers/boards.js b/client/src/reducers/boards.js deleted file mode 100644 index 390fad61..00000000 --- a/client/src/reducers/boards.js +++ /dev/null @@ -1,45 +0,0 @@ -import * as Actions from '../actions/boards'; - -export const boards = (state = {}, action) => { - switch (action.type) { - case Actions.GET_ALL_BOARDS_SUCCESS: - return { - ...state, - allBoards: action.data.boardIds, - specificBoard: action.data.specificBoard, - isFetchingAll: false - }; - case Actions.GET_ALL_BOARDS_REQUEST: - return { - ...state, - isFetchingAll: true, - error: null - }; - case Actions.GET_ALL_BOARDS_FAILURE: - return { - ...state, - isFetchingAll: false, - error: true - }; - case Actions.GET_SPECIFIC_BOARDS_SUCCESS: - return { - ...state, - specificBoard: action.data, - isFetchingSpecific: false - }; - case Actions.GET_SPECIFIC_BOARDS_REQUEST: - return { - ...state, - isFetchingSpecific: true, - error: null - }; - case Actions.GET_SPECIFIC_BOARDS_FAILURE: - return { - ...state, - isFetchingSpecific: false, - error: true - }; - default: - return state; - } -}; \ No newline at end of file diff --git a/client/src/reducers/index.js b/client/src/reducers/index.js index 0d48626e..89f08c74 100644 --- a/client/src/reducers/index.js +++ b/client/src/reducers/index.js @@ -1,10 +1,12 @@ import { combineReducers } from 'redux'; import {user} from './auth'; -import {boards} from './boards'; +import {allBoards} from './allBoards'; +import {specificBoard} from './specificBoard'; const djelloApp = combineReducers({ user, - boards + allBoards, + specificBoard }); export default djelloApp; \ No newline at end of file diff --git a/client/src/reducers/specificBoard.js b/client/src/reducers/specificBoard.js new file mode 100644 index 00000000..55206e1a --- /dev/null +++ b/client/src/reducers/specificBoard.js @@ -0,0 +1,26 @@ +import * as Actions from '../actions/specificBoard'; + +export const specificBoard = (state = {}, action) => { + switch (action.type) { + case Actions.GET_SPECIFIC_BOARD_SUCCESS: + return { + ...state, + data: action.data, + isFetching: false + }; + case Actions.GET_SPECIFIC_BOARD_REQUEST: + return { + ...state, + isFetching: true, + error: null + }; + case Actions.GET_SPECIFIC_BOARD_FAILURE: + return { + ...state, + isFetching: false, + error: true + }; + default: + return state; + } +}; \ No newline at end of file From 733357d2c74925bc2a2da0f1610342db73b0fca8 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Wed, 19 Jul 2017 17:11:15 -0400 Subject: [PATCH 053/112] add form label for board picker --- client/src/components/AuthLayer.js | 5 ++++- client/src/components/Board.js | 12 ++++++++++++ client/src/components/BoardPicker.js | 13 +++++++------ client/src/containers/BoardContainer.js | 20 ++++++++++++++++++++ client/src/index.css | 8 ++++++++ client/src/reducers/specificBoard.js | 10 +++++++++- 6 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 client/src/components/Board.js create mode 100644 client/src/containers/BoardContainer.js diff --git a/client/src/components/AuthLayer.js b/client/src/components/AuthLayer.js index 945a8f96..a807686e 100644 --- a/client/src/components/AuthLayer.js +++ b/client/src/components/AuthLayer.js @@ -2,6 +2,7 @@ import React from 'react'; import Login from './Login'; import {Grid, Row, Col} from 'react-bootstrap'; import BoardPickerContainer from '../containers/BoardPickerContainer'; +import BoardContainer from '../containers/BoardContainer'; const AuthLayer = ({isAuthenticated, loginUser, authError, token, specificBoard}) => { if (!isAuthenticated) { @@ -12,11 +13,13 @@ const AuthLayer = ({isAuthenticated, loginUser, authError, token, specificBoard}

Djello

-

{specificBoard ? specificBoard.title : ""}

+ + +
) }; diff --git a/client/src/components/Board.js b/client/src/components/Board.js new file mode 100644 index 00000000..c5c69800 --- /dev/null +++ b/client/src/components/Board.js @@ -0,0 +1,12 @@ +import React from 'react'; +import {Col} from 'react-bootstrap'; + +const Board = ({board}) => { + return ( + +

{board.title}

+ + ); +}; + +export default Board; \ No newline at end of file diff --git a/client/src/components/BoardPicker.js b/client/src/components/BoardPicker.js index 2b12f3af..7d084324 100644 --- a/client/src/components/BoardPicker.js +++ b/client/src/components/BoardPicker.js @@ -1,7 +1,5 @@ import React from 'react'; -import {FormControl} from 'react-bootstrap'; - - +import {FormGroup, FormControl, ControlLabel} from 'react-bootstrap'; const BoardPicker = ({allBoards, onChangeSelectedBoard}) => { let boardOptions = []; @@ -12,9 +10,12 @@ const BoardPicker = ({allBoards, onChangeSelectedBoard}) => { } return (
- - {boardOptions} - + + Select a Board: + + {boardOptions} + +
); }; diff --git a/client/src/containers/BoardContainer.js b/client/src/containers/BoardContainer.js new file mode 100644 index 00000000..aa1c6bb4 --- /dev/null +++ b/client/src/containers/BoardContainer.js @@ -0,0 +1,20 @@ +import { connect } from "react-redux"; +import Board from "../components/Board"; +// import { loginUser } from "../actions/auth"; + +const mapStateToProps = state => { + return { + board: state.specificBoard.data + }; +}; + +const mapDispatchToProps = dispatch => { + return { + onChangeBoardTitle: e => { + } + } +} + +const BoardContainer = connect(mapStateToProps, null)(Board); + +export default BoardContainer; \ No newline at end of file diff --git a/client/src/index.css b/client/src/index.css index 88a03ede..82a956e9 100644 --- a/client/src/index.css +++ b/client/src/index.css @@ -7,3 +7,11 @@ body { .navbar { border-radius: 0px; } + +h1 { + text-align: center; + text-transform: uppercase; + padding-bottom: 1em; + border-bottom: solid 3px #2C3E50; + margin-bottom: 1em; +} \ No newline at end of file diff --git a/client/src/reducers/specificBoard.js b/client/src/reducers/specificBoard.js index 55206e1a..ccbe4cd0 100644 --- a/client/src/reducers/specificBoard.js +++ b/client/src/reducers/specificBoard.js @@ -1,6 +1,14 @@ import * as Actions from '../actions/specificBoard'; -export const specificBoard = (state = {}, action) => { +const initialState = { + data: { + title: "" + }, + isFetching: false, + error: null +} + +export const specificBoard = (state = initialState, action) => { switch (action.type) { case Actions.GET_SPECIFIC_BOARD_SUCCESS: return { From 1e06a5828bd97f5e7eb140334194c9e1809d59e4 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Wed, 19 Jul 2017 17:23:37 -0400 Subject: [PATCH 054/112] add editable field component --- client/src/components/Board.js | 5 ++- client/src/components/BoardPicker.js | 2 +- client/src/components/EditableField.js | 57 ++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 client/src/components/EditableField.js diff --git a/client/src/components/Board.js b/client/src/components/Board.js index c5c69800..9dc6c0c3 100644 --- a/client/src/components/Board.js +++ b/client/src/components/Board.js @@ -1,10 +1,13 @@ import React from 'react'; import {Col} from 'react-bootstrap'; +import EditableField from './EditableField'; const Board = ({board}) => { return ( -

{board.title}

+ +

{board.title}

+
); }; diff --git a/client/src/components/BoardPicker.js b/client/src/components/BoardPicker.js index 7d084324..f57cc2e1 100644 --- a/client/src/components/BoardPicker.js +++ b/client/src/components/BoardPicker.js @@ -11,7 +11,7 @@ const BoardPicker = ({allBoards, onChangeSelectedBoard}) => { return (
- Select a Board: + Select a Board: {boardOptions} diff --git a/client/src/components/EditableField.js b/client/src/components/EditableField.js new file mode 100644 index 00000000..cdc1390e --- /dev/null +++ b/client/src/components/EditableField.js @@ -0,0 +1,57 @@ +import React, { Component } from 'react'; +import {FormControl, Button} from 'react-bootstrap'; + +class EditableField extends Component { + constructor() { + super(); + this.state = { + isEditOpen: false + }; + } + + onClick = e => { + console.log('fuck'); + if (!this.state.isEditOpen) { + this.setState({ + isEditOpen: true + }) + } + }; + + onBlur = e => { + this.setState({ + isEditOpen: false + }) + } + + onCancel = e => { + e.preventDefault(); + this.setState({ + isEditOpen: false + }) + } + + render() { + const form = ( + + +
+ + + + ) + return ( +
+ {this.state.isEditOpen ? form : this.props.children} +
+ ); + } +} + +export default EditableField; \ No newline at end of file From 438ad15baf1a54ee3c65b083361c5b208911d01a Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Wed, 19 Jul 2017 17:42:20 -0400 Subject: [PATCH 055/112] add board editing --- client/src/actions/specificBoard.js | 30 ++++++++++++++++ client/src/components/AuthLayer.js | 5 ++- client/src/components/Board.js | 7 ++-- client/src/components/EditableField.js | 46 ++++++++++++++++--------- client/src/containers/BoardContainer.js | 11 ++++-- server/spec/board_spec.js | 1 - 6 files changed, 77 insertions(+), 23 deletions(-) diff --git a/client/src/actions/specificBoard.js b/client/src/actions/specificBoard.js index 4966c69e..4f6b9bbf 100644 --- a/client/src/actions/specificBoard.js +++ b/client/src/actions/specificBoard.js @@ -28,6 +28,36 @@ export function getSpecificBoard(token, boardId) { headers: { 'Authorization':'Bearer ' + token }, }; + return dispatch => { + dispatch(getSpecificBoardRequest()) + + fetch(`api/v1/boards/${boardId}`, config) + .then(response => { + if (!response.ok) { + throw new Error(`${response.status}: ${response.statusText}`); + } + + return response.json(); + }) + .then(json => { + dispatch(getSpecificBoardSuccess(json.data)); + }) + .catch(error => { + dispatch(getSpecificBoardFailure(error)); + }); + } +} + +export function editSpecificBoard(token, boardId, form) { + let config = { + method: 'PUT', + headers: { + 'Authorization': 'Bearer ' + token, + 'Content-Type': 'application/x-www-form-urlencoded' + }, + body: form + }; + return dispatch => { dispatch(getSpecificBoardRequest()) diff --git a/client/src/components/AuthLayer.js b/client/src/components/AuthLayer.js index a807686e..2c658eca 100644 --- a/client/src/components/AuthLayer.js +++ b/client/src/components/AuthLayer.js @@ -18,7 +18,10 @@ const AuthLayer = ({isAuthenticated, loginUser, authError, token, specificBoard}
- +
) diff --git a/client/src/components/Board.js b/client/src/components/Board.js index 9dc6c0c3..95f797f9 100644 --- a/client/src/components/Board.js +++ b/client/src/components/Board.js @@ -2,10 +2,13 @@ import React from 'react'; import {Col} from 'react-bootstrap'; import EditableField from './EditableField'; -const Board = ({board}) => { +const Board = ({board, onChangeBoardTitle}) => { return ( - +

{board.title}

diff --git a/client/src/components/EditableField.js b/client/src/components/EditableField.js index cdc1390e..4c06daef 100644 --- a/client/src/components/EditableField.js +++ b/client/src/components/EditableField.js @@ -10,7 +10,6 @@ class EditableField extends Component { } onClick = e => { - console.log('fuck'); if (!this.state.isEditOpen) { this.setState({ isEditOpen: true @@ -19,35 +18,50 @@ class EditableField extends Component { }; onBlur = e => { + if(e.relatedTarget && e.relatedTarget.type !== "submit"){ + this.setState({ + isEditOpen: false + }) + } + } + + onCancel = e => { + e.preventDefault(); this.setState({ isEditOpen: false }) } - onCancel = e => { - e.preventDefault(); + handleSubmit = e => { + this.props.onSubmit(e); this.setState({ isEditOpen: false }) } render() { + const {fieldName} = this.props; const form = ( -
- -
- - - +
+
+ +
+ +
+ + +
) + return ( -
+
{this.state.isEditOpen ? form : this.props.children}
); diff --git a/client/src/containers/BoardContainer.js b/client/src/containers/BoardContainer.js index aa1c6bb4..f1e29537 100644 --- a/client/src/containers/BoardContainer.js +++ b/client/src/containers/BoardContainer.js @@ -1,6 +1,7 @@ import { connect } from "react-redux"; import Board from "../components/Board"; -// import { loginUser } from "../actions/auth"; +import serialize from "form-serialize"; +import { editSpecificBoard } from "../actions/specificBoard"; const mapStateToProps = state => { return { @@ -8,13 +9,17 @@ const mapStateToProps = state => { }; }; -const mapDispatchToProps = dispatch => { +const mapDispatchToProps = (dispatch, ownProps) => { return { onChangeBoardTitle: e => { + e.preventDefault(); + const form = e.target; + const data = serialize(form); + dispatch(editSpecificBoard(ownProps.token, ownProps.boardId, data)); } } } -const BoardContainer = connect(mapStateToProps, null)(Board); +const BoardContainer = connect(mapStateToProps, mapDispatchToProps)(Board); export default BoardContainer; \ No newline at end of file diff --git a/server/spec/board_spec.js b/server/spec/board_spec.js index af93bec1..f54da55e 100644 --- a/server/spec/board_spec.js +++ b/server/spec/board_spec.js @@ -175,7 +175,6 @@ describe("Board", () => { }); }); - it("deletes a board", done => { let options = { method: "DELETE", From b00b645e82a90d360af72b68fd9deaa7bf06200d Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Wed, 19 Jul 2017 17:53:08 -0400 Subject: [PATCH 056/112] improve editable field event handling --- client/src/actions/allBoards.js | 34 ++++++++++++++++++- client/src/components/AuthLayer.js | 3 +- client/src/components/EditableField.js | 7 ++-- client/src/containers/AuthLayerContainer.js | 1 + client/src/containers/BoardContainer.js | 2 ++ client/src/containers/BoardPickerContainer.js | 8 ++--- 6 files changed, 46 insertions(+), 9 deletions(-) diff --git a/client/src/actions/allBoards.js b/client/src/actions/allBoards.js index 51a34b6a..077f27ec 100644 --- a/client/src/actions/allBoards.js +++ b/client/src/actions/allBoards.js @@ -23,7 +23,7 @@ export function getAllBoardsFailure(error) { }; } -export function getAllBoards(token, userId) { +export function getAllBoardsInit(token, userId) { let config = { method: 'GET', headers: { 'Authorization':'Bearer ' + token }, @@ -55,4 +55,36 @@ export function getAllBoards(token, userId) { dispatch(getAllBoardsFailure(error)); }); } +} + +export function getAllBoards(token, userId) { + let config = { + method: 'GET', + headers: { 'Authorization':'Bearer ' + token }, + }; + + return dispatch => { + dispatch(getAllBoardsRequest()) + + fetch(`api/v1/users/${userId}/boards`, config) + .then(response => { + if (!response.ok) { + throw new Error(`${response.status}: ${response.statusText}`); + } + + return response.json(); + }) + .then(json => { + let boardIds = json.data.map(board => { + return { + id: board._id, + title: board.title + } + }); + dispatch(getAllBoardsSuccess(boardIds)); + }) + .catch(error => { + dispatch(getAllBoardsFailure(error)); + }); + } } \ No newline at end of file diff --git a/client/src/components/AuthLayer.js b/client/src/components/AuthLayer.js index 2c658eca..3387b74e 100644 --- a/client/src/components/AuthLayer.js +++ b/client/src/components/AuthLayer.js @@ -4,7 +4,7 @@ import {Grid, Row, Col} from 'react-bootstrap'; import BoardPickerContainer from '../containers/BoardPickerContainer'; import BoardContainer from '../containers/BoardContainer'; -const AuthLayer = ({isAuthenticated, loginUser, authError, token, specificBoard}) => { +const AuthLayer = ({isAuthenticated, loginUser, authError, token, userId, specificBoard}) => { if (!isAuthenticated) { return } @@ -21,6 +21,7 @@ const AuthLayer = ({isAuthenticated, loginUser, authError, token, specificBoard} diff --git a/client/src/components/EditableField.js b/client/src/components/EditableField.js index 4c06daef..6242fb93 100644 --- a/client/src/components/EditableField.js +++ b/client/src/components/EditableField.js @@ -18,7 +18,8 @@ class EditableField extends Component { }; onBlur = e => { - if(e.relatedTarget && e.relatedTarget.type !== "submit"){ + let eventRelatedTarget = e.relatedTarget || {}; + if (eventRelatedTarget.type !== "submit"){ this.setState({ isEditOpen: false }) @@ -43,7 +44,7 @@ class EditableField extends Component { const {fieldName} = this.props; const form = (
-
+ +
{this.state.isEditOpen ? form : this.props.children}
); diff --git a/client/src/containers/AuthLayerContainer.js b/client/src/containers/AuthLayerContainer.js index f5339b1f..7db80c94 100644 --- a/client/src/containers/AuthLayerContainer.js +++ b/client/src/containers/AuthLayerContainer.js @@ -8,6 +8,7 @@ const mapStateToProps = state => { isAuthenticated: state.user.isAuthenticated, authError: state.user.error, token: state.user.token, + userId: state.user.id, specificBoard: state.specificBoard.data }; }; diff --git a/client/src/containers/BoardContainer.js b/client/src/containers/BoardContainer.js index f1e29537..f66413cd 100644 --- a/client/src/containers/BoardContainer.js +++ b/client/src/containers/BoardContainer.js @@ -2,6 +2,7 @@ import { connect } from "react-redux"; import Board from "../components/Board"; import serialize from "form-serialize"; import { editSpecificBoard } from "../actions/specificBoard"; +import { getAllBoards } from '../actions/allBoards'; const mapStateToProps = state => { return { @@ -16,6 +17,7 @@ const mapDispatchToProps = (dispatch, ownProps) => { const form = e.target; const data = serialize(form); dispatch(editSpecificBoard(ownProps.token, ownProps.boardId, data)); + dispatch(getAllBoards(ownProps.token, ownProps.userId)); } } } diff --git a/client/src/containers/BoardPickerContainer.js b/client/src/containers/BoardPickerContainer.js index 174a1038..5ffcf0bd 100644 --- a/client/src/containers/BoardPickerContainer.js +++ b/client/src/containers/BoardPickerContainer.js @@ -1,12 +1,12 @@ import React, { Component } from "react"; import { connect } from "react-redux"; import BoardPicker from "../components/BoardPicker"; -import { getAllBoards } from "../actions/allBoards"; +import { getAllBoardsInit } from "../actions/allBoards"; import { getSpecificBoard } from "../actions/specificBoard"; class BoardPickerContainer extends Component { componentDidMount() { - this.props.getAllBoards(this.props.token, this.props.userId); + this.props.getAllBoardsInit(this.props.token, this.props.userId); } render() { @@ -24,8 +24,8 @@ const mapStateToProps = state => { const mapDispatchToProps = (dispatch, ownProps) => { return { - getAllBoards: (token, userId) => { - dispatch(getAllBoards(token, userId)); + getAllBoardsInit: (token, userId) => { + dispatch(getAllBoardsInit(token, userId)); }, onChangeSelectedBoard: e => { const selectedBoard = e.target.value; From 840556354e36fc9fe0fca6999ac1d79120b696c7 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Wed, 19 Jul 2017 17:57:01 -0400 Subject: [PATCH 057/112] add autofocus to editable field and improve styling --- client/src/components/Board.js | 18 +++++++++++------- client/src/components/EditableField.js | 1 + 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/client/src/components/Board.js b/client/src/components/Board.js index 95f797f9..e37b042c 100644 --- a/client/src/components/Board.js +++ b/client/src/components/Board.js @@ -1,16 +1,20 @@ import React from 'react'; -import {Col} from 'react-bootstrap'; +import {Col, Row} from 'react-bootstrap'; import EditableField from './EditableField'; const Board = ({board, onChangeBoardTitle}) => { return ( - -

{board.title}

-
+ + + +

{board.title}

+
+ +
); }; diff --git a/client/src/components/EditableField.js b/client/src/components/EditableField.js index 6242fb93..27b6d949 100644 --- a/client/src/components/EditableField.js +++ b/client/src/components/EditableField.js @@ -48,6 +48,7 @@ class EditableField extends Component {
- ) - + ); + return (
{this.state.isEditOpen ? form : this.props.children} @@ -70,4 +66,4 @@ class EditableField extends Component { } } -export default EditableField; \ No newline at end of file +export default EditableField; diff --git a/client/src/components/Header.js b/client/src/components/Header.js index 32062f4a..7d4b62ec 100644 --- a/client/src/components/Header.js +++ b/client/src/components/Header.js @@ -1,7 +1,7 @@ import React from "react"; import { Navbar, Nav, NavItem } from "react-bootstrap"; -const LogOut = ({isAuthenticated, email, onLogout}) => { +const LogOut = ({ isAuthenticated, email, onLogout }) => { if (!isAuthenticated) { return null; } @@ -12,8 +12,8 @@ const LogOut = ({isAuthenticated, email, onLogout}) => { Logout {email} - ) -} + ); +}; const Header = ({ title, isAuthenticated, email, onLogout }) => { return ( @@ -23,7 +23,7 @@ const Header = ({ title, isAuthenticated, email, onLogout }) => { {title} - { +const Login = ({ loginUser, error }) => { return ( - {error ? : null} -

Login

- -
- -
- -
- - -
+ {error ? : null} +

Login

+ +
+ +
+ +
+ + +
- ) + ); }; -export default Login; \ No newline at end of file +export default Login; diff --git a/client/src/components/LoginError.js b/client/src/components/LoginError.js index 5d59ba83..a2db3b12 100644 --- a/client/src/components/LoginError.js +++ b/client/src/components/LoginError.js @@ -1,17 +1,17 @@ -import React, { Component } from 'react'; -import {Alert} from 'react-bootstrap'; +import React, { Component } from "react"; +import { Alert } from "react-bootstrap"; class LoginError extends Component { constructor() { - super() + super(); this.state = { visible: true - } + }; } handleAlertDismiss = () => { - this.setState({visible: false}); - } + this.setState({ visible: false }); + }; render() { if (this.state.visible) { @@ -27,4 +27,4 @@ class LoginError extends Component { } } -export default LoginError; \ No newline at end of file +export default LoginError; diff --git a/client/src/containers/AppContainer.js b/client/src/containers/AppContainer.js index d9ee9a91..0886e93b 100644 --- a/client/src/containers/AppContainer.js +++ b/client/src/containers/AppContainer.js @@ -15,10 +15,9 @@ const mapDispatchToProps = dispatch => { e.preventDefault(); dispatch(logoutUser()); } - } -} - + }; +}; const AppContainer = connect(mapStateToProps, mapDispatchToProps)(App); -export default AppContainer; \ No newline at end of file +export default AppContainer; diff --git a/client/src/containers/AuthLayerContainer.js b/client/src/containers/AuthLayerContainer.js index 7db80c94..442cc6cc 100644 --- a/client/src/containers/AuthLayerContainer.js +++ b/client/src/containers/AuthLayerContainer.js @@ -21,9 +21,11 @@ const mapDispatchToProps = dispatch => { const creds = serialize(form, { hash: true }); dispatch(loginUser(creds)); } - } -} + }; +}; -const AuthLayerContainer = connect(mapStateToProps, mapDispatchToProps)(AuthLayer); +const AuthLayerContainer = connect(mapStateToProps, mapDispatchToProps)( + AuthLayer +); -export default AuthLayerContainer; \ No newline at end of file +export default AuthLayerContainer; diff --git a/client/src/containers/BoardContainer.js b/client/src/containers/BoardContainer.js index b4ea60ce..f07df2b7 100644 --- a/client/src/containers/BoardContainer.js +++ b/client/src/containers/BoardContainer.js @@ -15,11 +15,18 @@ const mapDispatchToProps = (dispatch, ownProps) => { e.preventDefault(); const form = e.target; const data = serialize(form); - dispatch(editSpecificBoard(ownProps.token, ownProps.boardId, data, ownProps.userId)); + dispatch( + editSpecificBoard( + ownProps.token, + ownProps.boardId, + data, + ownProps.userId + ) + ); } - } -} + }; +}; const BoardContainer = connect(mapStateToProps, mapDispatchToProps)(Board); -export default BoardContainer; \ No newline at end of file +export default BoardContainer; diff --git a/client/src/containers/BoardPickerContainer.js b/client/src/containers/BoardPickerContainer.js index 951b83a6..0830a4d6 100644 --- a/client/src/containers/BoardPickerContainer.js +++ b/client/src/containers/BoardPickerContainer.js @@ -2,7 +2,11 @@ import React, { Component } from "react"; import { connect } from "react-redux"; import BoardPicker from "../components/BoardPicker"; import { getAllBoardsInit } from "../actions/allBoards"; -import { getSpecificBoard, createBoard, deleteBoard } from "../actions/specificBoard"; +import { + getSpecificBoard, + createBoard, + deleteBoard +} from "../actions/specificBoard"; class BoardPickerContainer extends Component { componentDidMount() { @@ -18,7 +22,8 @@ const mapStateToProps = state => { return { token: state.user.token, userId: state.user.id, - allBoards: state.allBoards.data + allBoards: state.allBoards.data, + selectedBoard: state.specificBoard.data }; }; @@ -36,12 +41,25 @@ const mapDispatchToProps = (dispatch, ownProps) => { dispatch(createBoard(ownProps.token, ownProps.userId)); }, onDeleteBoard: e => { - if (window.confirm(`Are you sure you want to delete the following board? \n \n ${ownProps.currentBoard.title}`)) { + if ( + window.confirm( + `Are you sure you want to delete the following board? \n \n ${ownProps + .currentBoard.title}` + ) + ) { e.preventDefault(); - dispatch(deleteBoard(ownProps.token, ownProps.currentBoard._id, ownProps.userId)) + dispatch( + deleteBoard( + ownProps.token, + ownProps.currentBoard._id, + ownProps.userId + ) + ); } } }; }; -export default connect(mapStateToProps, mapDispatchToProps)(BoardPickerContainer); +export default connect(mapStateToProps, mapDispatchToProps)( + BoardPickerContainer +); diff --git a/client/src/index.js b/client/src/index.js index 84ee203a..904d84a4 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -1,8 +1,8 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; +import React from "react"; +import ReactDOM from "react-dom"; import "bootswatch/flatly/bootstrap.min.css"; -import './index.css'; -import AppContainer from './containers/AppContainer'; +import "./index.css"; +import AppContainer from "./containers/AppContainer"; import { Provider } from "react-redux"; import { createStore, applyMiddleware, compose } from "redux"; import thunk from "redux-thunk"; @@ -16,7 +16,7 @@ const persistedState = localStorage.getItem("djelloAppState") const store = createStore( djelloApp, - {user: persistedState}, + { user: persistedState }, composeEnhancers(applyMiddleware(thunk)) ); @@ -24,7 +24,6 @@ store.subscribe(() => { localStorage.setItem("djelloAppState", JSON.stringify(store.getState().user)); }); - ReactDOM.render( diff --git a/client/src/reducers/allBoards.js b/client/src/reducers/allBoards.js index 6a450b77..93de84d5 100644 --- a/client/src/reducers/allBoards.js +++ b/client/src/reducers/allBoards.js @@ -1,4 +1,4 @@ -import * as Actions from '../actions/allBoards'; +import * as Actions from "../actions/allBoards"; export const allBoards = (state = {}, action) => { switch (action.type) { @@ -23,4 +23,4 @@ export const allBoards = (state = {}, action) => { default: return state; } -}; \ No newline at end of file +}; diff --git a/client/src/reducers/auth.js b/client/src/reducers/auth.js index 16ca70f9..e3f721fd 100644 --- a/client/src/reducers/auth.js +++ b/client/src/reducers/auth.js @@ -1,7 +1,10 @@ -import * as Actions from '../actions/auth'; -import decode from 'jwt-decode'; +import * as Actions from "../actions/auth"; +import decode from "jwt-decode"; -export const user = (state = {isAuthenticated: false, error: null}, action) => { +export const user = ( + state = { isAuthenticated: false, error: null }, + action +) => { switch (action.type) { case Actions.LOGIN_SUCCESS: const decoded = decode(action.data); @@ -29,8 +32,8 @@ export const user = (state = {isAuthenticated: false, error: null}, action) => { case Actions.LOGOUT: return { isAuthenticated: false - } + }; default: return state; } -}; \ No newline at end of file +}; diff --git a/client/src/reducers/index.js b/client/src/reducers/index.js index 89f08c74..2e0e14df 100644 --- a/client/src/reducers/index.js +++ b/client/src/reducers/index.js @@ -1,7 +1,7 @@ -import { combineReducers } from 'redux'; -import {user} from './auth'; -import {allBoards} from './allBoards'; -import {specificBoard} from './specificBoard'; +import { combineReducers } from "redux"; +import { user } from "./auth"; +import { allBoards } from "./allBoards"; +import { specificBoard } from "./specificBoard"; const djelloApp = combineReducers({ user, @@ -9,4 +9,4 @@ const djelloApp = combineReducers({ specificBoard }); -export default djelloApp; \ No newline at end of file +export default djelloApp; diff --git a/client/src/reducers/specificBoard.js b/client/src/reducers/specificBoard.js index ccbe4cd0..35e5484f 100644 --- a/client/src/reducers/specificBoard.js +++ b/client/src/reducers/specificBoard.js @@ -1,4 +1,4 @@ -import * as Actions from '../actions/specificBoard'; +import * as Actions from "../actions/specificBoard"; const initialState = { data: { @@ -6,7 +6,7 @@ const initialState = { }, isFetching: false, error: null -} +}; export const specificBoard = (state = initialState, action) => { switch (action.type) { @@ -31,4 +31,4 @@ export const specificBoard = (state = initialState, action) => { default: return state; } -}; \ No newline at end of file +}; diff --git a/server/index.js b/server/index.js index 0262fbd2..f0ea270f 100644 --- a/server/index.js +++ b/server/index.js @@ -1,7 +1,7 @@ const express = require("express"); const app = express(); -const path = require('path'); -require("dotenv").config({ path: path.join(__dirname,"../.env") }); +const path = require("path"); +require("dotenv").config({ path: path.join(__dirname, "../.env") }); // ---------------------------------------- // Body Parser @@ -96,7 +96,9 @@ const host = "localhost"; let args; process.env.NODE_ENV === "production" ? (args = [port]) : (args = [port, host]); -args.push(() => {console.log(`Listening: http://${ host }:${ port }`)}); +args.push(() => { + console.log(`Listening: http://${host}:${port}`); +}); if (require.main === module) { app.listen.apply(app, args); diff --git a/server/seeds/seeds.js b/server/seeds/seeds.js index b2813d1a..78a49a47 100644 --- a/server/seeds/seeds.js +++ b/server/seeds/seeds.js @@ -1,11 +1,10 @@ const MULTIPLIER = 5; module.exports = () => { - // ---------------------------------------- // Creating Users // ---------------------------------------- - console.log('Creating users...'); + console.log("Creating users..."); let users = []; for (let i = 0; i < 2; i++) { let user = new User({ @@ -18,7 +17,7 @@ module.exports = () => { // ---------------------------------------- // Creating Boards // ---------------------------------------- - console.log('Creating boards...'); + console.log("Creating boards..."); let boards = []; for (let i = 0; i < MULTIPLIER; i++) { let board = new Board({ @@ -30,17 +29,13 @@ module.exports = () => { users[i % users.length].boards.push(board); } - // ---------------------------------------- // Finish // ---------------------------------------- - console.log('Saving...'); + console.log("Saving..."); let promises = []; - [ - users, - boards - ].forEach((collection) => { - collection.forEach((model) => { + [users, boards].forEach(collection => { + collection.forEach(model => { promises.push(model.save()); }); }); diff --git a/server/spec/board_spec.js b/server/spec/board_spec.js index f54da55e..d021b513 100644 --- a/server/spec/board_spec.js +++ b/server/spec/board_spec.js @@ -111,7 +111,7 @@ describe("Board", () => { done(); }); }); - + it("fetches a board", done => { let options = { method: "GET", @@ -158,10 +158,10 @@ describe("Board", () => { password: "password" }) .then(user => { - return rp(secondUserLoginOpts) + return rp(secondUserLoginOpts); }) .then(result => { - getOpts.auth = {bearer: result} + getOpts.auth = { bearer: result }; return rp(getOpts); }) .then(result => { diff --git a/start-client.js b/start-client.js index 36d012ca..759480ad 100644 --- a/start-client.js +++ b/start-client.js @@ -1,3 +1,3 @@ const args = ["start"]; const opts = { stdio: "inherit", cwd: "client", shell: true }; -require("child_process").spawn("yarn", args, opts); \ No newline at end of file +require("child_process").spawn("yarn", args, opts); From 911fe24b53e1867519b8730fdb3af3a6f5038bd7 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Thu, 20 Jul 2017 00:41:32 -0400 Subject: [PATCH 062/112] add get all lists associated with board method --- server/routes/api/boards.js | 29 +++++++++++++++++++++++++++++ server/spec/board_spec.js | 1 + server/spec/list_spec.js | 23 +++++++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/server/routes/api/boards.js b/server/routes/api/boards.js index 97d7c3a2..3b803b84 100644 --- a/server/routes/api/boards.js +++ b/server/routes/api/boards.js @@ -257,4 +257,33 @@ router.post("/:id/lists", (req, res, next) => { .catch(error => next(error)); }); +/* =============== + Get All Lists +================ */ +router.get("/:id/lists", (req, res, next) => { +const boardId = req.params.id; +Board.findById(boardId) + .populate({ + path: "lists", + populate: { + path: "cards" + } + }) + .then(board => { + if (!board) { + throw new Error(apiMessages.doesNotExist("Board")); + } + + let canCurrentUserGet = checkUserBoardPermissions(board, req.user.id); + if (!canCurrentUserGet) { + throw new Error(apiMessages.failedAuth); + } + + res.json({ + data: board.lists + }); + }) + .catch(error => next(error)); +}); + module.exports = router; diff --git a/server/spec/board_spec.js b/server/spec/board_spec.js index d021b513..1c67cd54 100644 --- a/server/spec/board_spec.js +++ b/server/spec/board_spec.js @@ -298,5 +298,6 @@ describe("Board", () => { done(); }); }); + }); }); diff --git a/server/spec/list_spec.js b/server/spec/list_spec.js index 0c076f02..cea36b68 100644 --- a/server/spec/list_spec.js +++ b/server/spec/list_spec.js @@ -269,5 +269,28 @@ describe("List", () => { done(); }); }); + + it("returns all lists associated with a board", done => { + let options = { + method: "GET", + uri: `${apiUrl}/boards/${board.id}/lists`, + auth: { + bearer: token + }, + json: true, + resolveWithFullResponse: true + }; + rp(options) + .then(res => { + expect(res.statusCode).toBe(200); + expect(res.body.data.length).toBe(1); + expect(res.body.data[0].title).toBe("Test Original List Title"); + done(); + }) + .catch(error => { + expect(error).toEqual(null); + done(); + }); + }); }); }); From de68646973cb29f6d522648054d93718e6f8d56e Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Thu, 20 Jul 2017 00:45:54 -0400 Subject: [PATCH 063/112] add get card route --- server/routes/api/boards.js | 42 ++++++++++++++++++------------------- server/routes/api/cards.js | 37 +++++++++++++++++++++++++++++++- server/routes/api/lists.js | 2 +- server/spec/card_spec.js | 28 +++++++++++++++++++++++-- 4 files changed, 84 insertions(+), 25 deletions(-) diff --git a/server/routes/api/boards.js b/server/routes/api/boards.js index 3b803b84..691328e0 100644 --- a/server/routes/api/boards.js +++ b/server/routes/api/boards.js @@ -261,29 +261,29 @@ router.post("/:id/lists", (req, res, next) => { Get All Lists ================ */ router.get("/:id/lists", (req, res, next) => { -const boardId = req.params.id; -Board.findById(boardId) - .populate({ - path: "lists", - populate: { - path: "cards" - } - }) - .then(board => { - if (!board) { - throw new Error(apiMessages.doesNotExist("Board")); - } + const boardId = req.params.id; + Board.findById(boardId) + .populate({ + path: "lists", + populate: { + path: "cards" + } + }) + .then(board => { + if (!board) { + throw new Error(apiMessages.doesNotExist("Board")); + } - let canCurrentUserGet = checkUserBoardPermissions(board, req.user.id); - if (!canCurrentUserGet) { - throw new Error(apiMessages.failedAuth); - } + let canCurrentUserGet = checkUserBoardPermissions(board, req.user.id); + if (!canCurrentUserGet) { + throw new Error(apiMessages.failedAuth); + } - res.json({ - data: board.lists - }); - }) - .catch(error => next(error)); + res.json({ + data: board.lists + }); + }) + .catch(error => next(error)); }); module.exports = router; diff --git a/server/routes/api/cards.js b/server/routes/api/cards.js index dac81e59..d6885154 100644 --- a/server/routes/api/cards.js +++ b/server/routes/api/cards.js @@ -12,6 +12,41 @@ const { apiMessages } = require("./../../helpers"); +/* =============== + Get Card +================ */ +router.get("/:id", (req, res, next) => { + const cardId = req.params.id; + + Card.findById(cardId) + .populate({ + path: "list", + populate: { + path: "board" + } + }) + .then(card => { + if (!card) { + throw new Error(apiMessages.doesNotExist("Card")); + } + + let canCurrentUserGet = checkUserBoardPermissions( + card.list.board, + req.user.id + ); + + if (!canCurrentUserGet) { + throw new Error(apiMessages.failedAuth); + } + + res.json({ + message: apiMessages.successfulDelete, + data: card + }); + }) + .catch(error => next(error)); +}); + /* =============== Delete ================ */ @@ -28,7 +63,7 @@ router.delete("/:id", (req, res, next) => { }) .then(card => { if (!card) { - throw new Error(apiMessages.doesNotExist("List")); + throw new Error(apiMessages.doesNotExist("Card")); } let canCurrentUserDelete = checkUserBoardPermissions( diff --git a/server/routes/api/lists.js b/server/routes/api/lists.js index c4dce4a9..278343bc 100644 --- a/server/routes/api/lists.js +++ b/server/routes/api/lists.js @@ -92,7 +92,7 @@ router.put("/:id", (req, res, next) => { /* =============== Create Card ================ */ -router.post("/:id/card", (req, res, next) => { +router.post("/:id/cards", (req, res, next) => { const listId = req.params.id; const { title, description } = req.body; let newCard; diff --git a/server/spec/card_spec.js b/server/spec/card_spec.js index e594bbfd..366caef4 100644 --- a/server/spec/card_spec.js +++ b/server/spec/card_spec.js @@ -139,7 +139,7 @@ describe("Card", () => { it("creates a card through the api", done => { let options = { method: "POST", - uri: `${apiUrl}/lists/${list.id}/card`, + uri: `${apiUrl}/lists/${list.id}/cards`, auth: { bearer: token }, @@ -168,10 +168,34 @@ describe("Card", () => { }); }); + it("gets a card", done => { + let options = { + method: "GET", + uri: `${apiUrl}/cards/${card.id}`, + auth: { + bearer: token + }, + json: true, + resolveWithFullResponse: true + }; + + rp(options) + .then(res => { + expect(res.statusCode).toBe(200); + expect(res.body.data.title).toBe("Test Original Card Title"); + expect(res.body.data.description).toBe("Test Original Card Description"); + done() + }) + .catch(error => { + expect(error).toEqual(null); + done(); + }); + }); + it("updates list after creating card", done => { let options = { method: "POST", - uri: `${apiUrl}/lists/${list.id}/card`, + uri: `${apiUrl}/lists/${list.id}/cards`, auth: { bearer: token }, From efe64c133c2db8faa7a7e46e5a101d81e00a13ed Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Thu, 20 Jul 2017 00:48:21 -0400 Subject: [PATCH 064/112] clean up api routes --- server/routes/api/boards.js | 82 ++++++------- server/routes/api/cards.js | 226 ++++++++++++++++++------------------ server/routes/api/lists.js | 86 +++++++------- server/routes/api/users.js | 2 +- 4 files changed, 198 insertions(+), 198 deletions(-) diff --git a/server/routes/api/boards.js b/server/routes/api/boards.js index 691328e0..da5dcae4 100644 --- a/server/routes/api/boards.js +++ b/server/routes/api/boards.js @@ -7,7 +7,7 @@ const List = models.List; const { checkUserBoardPermissions, apiMessages } = require("./../../helpers"); /* =============== - Read + Read Board ================ */ router.get("/:id", (req, res, next) => { const boardId = req.params.id; @@ -38,45 +38,6 @@ router.get("/:id", (req, res, next) => { .catch(error => next(error)); }); -/* =============== - Delete -================ */ -router.delete("/:id", (req, res, next) => { - const boardId = req.params.id; - let deletedBoard; - - Board.findById(boardId) - .then(board => { - if (!board) { - throw new Error(apiMessages.doesNotExist("Board")); - } - let canCurrentUserDelete = checkUserBoardPermissions(board, req.user.id); - if (!canCurrentUserDelete) { - throw new Error(apiMessages.failedAuth); - } - - return Board.findByIdAndRemove(boardId); - }) - .then(result => { - deletedBoard = result; - return User.update( - { boards: { $in: [deletedBoard.id] } }, - { - $pop: { boards: deletedBoard } - } - ); - }) - .then(() => { - res.json({ - message: apiMessages.successfulDelete, - data: { - deletedResource: deletedBoard - } - }); - }) - .catch(error => next(error)); -}); - /* =============== Update Board ================ */ @@ -286,4 +247,43 @@ router.get("/:id/lists", (req, res, next) => { .catch(error => next(error)); }); -module.exports = router; +/* =============== + Delete Board +================ */ +router.delete("/:id", (req, res, next) => { +const boardId = req.params.id; +let deletedBoard; + +Board.findById(boardId) + .then(board => { + if (!board) { + throw new Error(apiMessages.doesNotExist("Board")); + } + let canCurrentUserDelete = checkUserBoardPermissions(board, req.user.id); + if (!canCurrentUserDelete) { + throw new Error(apiMessages.failedAuth); + } + + return Board.findByIdAndRemove(boardId); + }) + .then(result => { + deletedBoard = result; + return User.update( + { boards: { $in: [deletedBoard.id] } }, + { + $pop: { boards: deletedBoard } + } + ); + }) + .then(() => { + res.json({ + message: apiMessages.successfulDelete, + data: { + deletedResource: deletedBoard + } + }); + }) + .catch(error => next(error)); +}); + +module.exports = router; \ No newline at end of file diff --git a/server/routes/api/cards.js b/server/routes/api/cards.js index d6885154..0394e9e6 100644 --- a/server/routes/api/cards.js +++ b/server/routes/api/cards.js @@ -48,7 +48,119 @@ router.get("/:id", (req, res, next) => { }); /* =============== - Delete + Update Card +================ */ +router.put("/:id", (req, res, next) => { +const cardId = req.params.id; +const { title, description } = req.body; +let originalCard; + +Card.findById(cardId) + .populate({ + path: "list", + populate: { + path: "board" + } + }) + .then(card => { + if (!card) { + throw new Error(apiMessages.doesNotExist("Card")); + } + + let canCurrentUserDelete = checkUserBoardPermissions( + card.list.board, + req.user.id + ); + if (!canCurrentUserDelete) { + throw new Error(apiMessages.failedAuth); + } + originalCard = card; + let activityMessage = parseCardChange(title, description); + return Activity.create({ + description: activityMessage, + card: cardId + }); + }) + .then(activity => { + return Card.findByIdAndUpdate( + cardId, + { + title: title || originalCard.title, + description: description || originalCard.description, + $push: { activities: activity.id } + }, + { new: true } + ); + }) + .then(result => { + res.json({ + message: apiMessages.successfulPut, + data: result + }); + }) + .catch(error => next(error)); +}); + +/* =============== + Add Member to Card +================ */ +router.post("/:id/users/:userId", (req, res, next) => { +const cardId = req.params.id; +const userToAdd = req.params.userId; +let board; +let updatedCard; + +Card.findById(cardId) + .populate({ + path: "list", + populate: { + path: "board" + } + }) + .then(card => { + if (!card) { + throw new Error(apiMessages.doesNotExist("Card")); + } + + let canCurrentUserDelete = checkUserBoardPermissions( + card.list.board, + req.user.id + ); + if (!canCurrentUserDelete) { + throw new Error(apiMessages.failedAuth); + } + + board = card.list.board; + return Card.findByIdAndUpdate( + cardId, + { + $addToSet: { members: userToAdd } + }, + { new: true } + ); + }) + .then(result => { + updatedCard = result; + return Board.findByIdAndUpdate(board.id, { + $addToSet: { users: userToAdd } + }); + }) + .then(result => { + return User.findByIdAndUpdate(userToAdd, { + $addToSet: { boards: board.id } + }); + }) + .then(result => { + res.json({ + message: apiMessages.successfulPut, + data: updatedCard + }); + }) + .catch(error => next(error)); +}); + +/* =============== + Delete Card ================ */ router.delete("/:id", (req, res, next) => { const cardId = req.params.id; @@ -96,116 +208,4 @@ router.delete("/:id", (req, res, next) => { .catch(error => next(error)); }); -/* =============== - Update Card -================ */ -router.put("/:id", (req, res, next) => { - const cardId = req.params.id; - const { title, description } = req.body; - let originalCard; - - Card.findById(cardId) - .populate({ - path: "list", - populate: { - path: "board" - } - }) - .then(card => { - if (!card) { - throw new Error(apiMessages.doesNotExist("Card")); - } - - let canCurrentUserDelete = checkUserBoardPermissions( - card.list.board, - req.user.id - ); - if (!canCurrentUserDelete) { - throw new Error(apiMessages.failedAuth); - } - originalCard = card; - let activityMessage = parseCardChange(title, description); - return Activity.create({ - description: activityMessage, - card: cardId - }); - }) - .then(activity => { - return Card.findByIdAndUpdate( - cardId, - { - title: title || originalCard.title, - description: description || originalCard.description, - $push: { activities: activity.id } - }, - { new: true } - ); - }) - .then(result => { - res.json({ - message: apiMessages.successfulPut, - data: result - }); - }) - .catch(error => next(error)); -}); - -/* =============== - Add Member to Card -================ */ -router.post("/:id/users/:userId", (req, res, next) => { - const cardId = req.params.id; - const userToAdd = req.params.userId; - let board; - let updatedCard; - - Card.findById(cardId) - .populate({ - path: "list", - populate: { - path: "board" - } - }) - .then(card => { - if (!card) { - throw new Error(apiMessages.doesNotExist("Card")); - } - - let canCurrentUserDelete = checkUserBoardPermissions( - card.list.board, - req.user.id - ); - if (!canCurrentUserDelete) { - throw new Error(apiMessages.failedAuth); - } - - board = card.list.board; - return Card.findByIdAndUpdate( - cardId, - { - $addToSet: { members: userToAdd } - }, - { new: true } - ); - }) - .then(result => { - updatedCard = result; - return Board.findByIdAndUpdate(board.id, { - $addToSet: { users: userToAdd } - }); - }) - .then(result => { - return User.findByIdAndUpdate(userToAdd, { - $addToSet: { boards: board.id } - }); - }) - .then(result => { - res.json({ - message: apiMessages.successfulPut, - data: updatedCard - }); - }) - .catch(error => next(error)); -}); - module.exports = router; diff --git a/server/routes/api/lists.js b/server/routes/api/lists.js index 278343bc..6cca9fb8 100644 --- a/server/routes/api/lists.js +++ b/server/routes/api/lists.js @@ -7,49 +7,6 @@ const List = models.List; const Card = models.Card; const { checkUserBoardPermissions, apiMessages } = require("./../../helpers"); -/* =============== - Delete -================ */ -router.delete("/:id", (req, res, next) => { - const listId = req.params.id; - let deletedList; - List.findById(listId) - .populate("board") - .then(list => { - if (!list) { - throw new Error(apiMessages.doesNotExist("List")); - } - - let canCurrentUserDelete = checkUserBoardPermissions( - list.board, - req.user.id - ); - if (!canCurrentUserDelete) { - throw new Error(apiMessages.failedAuth); - } - - return List.findByIdAndRemove(listId); - }) - .then(result => { - deletedList = result; - return Board.update( - { lists: { $in: [deletedList.id] } }, - { - $pop: { lists: deletedList } - } - ); - }) - .then(() => { - res.json({ - message: apiMessages.successfulDelete, - data: { - deletedResource: deletedList - } - }); - }) - .catch(error => next(error)); -}); - /* =============== Update List ================ */ @@ -89,6 +46,49 @@ router.put("/:id", (req, res, next) => { }); }); +/* =============== + Delete List +================ */ +router.delete("/:id", (req, res, next) => { +const listId = req.params.id; +let deletedList; +List.findById(listId) + .populate("board") + .then(list => { + if (!list) { + throw new Error(apiMessages.doesNotExist("List")); + } + + let canCurrentUserDelete = checkUserBoardPermissions( + list.board, + req.user.id + ); + if (!canCurrentUserDelete) { + throw new Error(apiMessages.failedAuth); + } + + return List.findByIdAndRemove(listId); + }) + .then(result => { + deletedList = result; + return Board.update( + { lists: { $in: [deletedList.id] } }, + { + $pop: { lists: deletedList } + } + ); + }) + .then(() => { + res.json({ + message: apiMessages.successfulDelete, + data: { + deletedResource: deletedList + } + }); + }) + .catch(error => next(error)); +}); + /* =============== Create Card ================ */ diff --git a/server/routes/api/users.js b/server/routes/api/users.js index 8da345f7..a1baf80e 100644 --- a/server/routes/api/users.js +++ b/server/routes/api/users.js @@ -23,7 +23,7 @@ router.get("/:id", (req, res) => { }); /* =============== - Get User's Boards + Get User Boards ================ */ router.get("/:id/boards", (req, res, next) => { User.findById(req.params.id) From 6c68930ab87f5820bf596e0348e2597c46403aa3 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Thu, 20 Jul 2017 00:50:57 -0400 Subject: [PATCH 065/112] add population queries to get card route --- server/routes/api/cards.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/server/routes/api/cards.js b/server/routes/api/cards.js index 0394e9e6..9ae420a5 100644 --- a/server/routes/api/cards.js +++ b/server/routes/api/cards.js @@ -19,12 +19,20 @@ router.get("/:id", (req, res, next) => { const cardId = req.params.id; Card.findById(cardId) - .populate({ - path: "list", - populate: { - path: "board" + .populate([ + { + path: "list", + populate: { + path: "board" + } + }, + { + path: "activities" + }, + { + path: "members" } - }) + ]) .then(card => { if (!card) { throw new Error(apiMessages.doesNotExist("Card")); From 7a8157ee7aa110a69780c12b5f5a0d37f9907433 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Thu, 20 Jul 2017 12:03:45 -0400 Subject: [PATCH 066/112] improve css styling --- client/src/components/AuthLayer.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/client/src/components/AuthLayer.js b/client/src/components/AuthLayer.js index 54714ba7..ababa0fc 100644 --- a/client/src/components/AuthLayer.js +++ b/client/src/components/AuthLayer.js @@ -20,7 +20,14 @@ const AuthLayer = ({

Djello

- + + + +
- - -
); }; From 308c67cb256df4ab470f7d1e2cd537109ccaecc4 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Thu, 20 Jul 2017 12:09:07 -0400 Subject: [PATCH 067/112] remove server request from board post --- client/src/actions/allBoards.js | 8 ++++++++ client/src/actions/specificBoard.js | 8 ++++++-- client/src/reducers/allBoards.js | 8 ++++++++ server/helpers/index.js | 2 +- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/client/src/actions/allBoards.js b/client/src/actions/allBoards.js index a4d7a6b3..bc2b58f1 100644 --- a/client/src/actions/allBoards.js +++ b/client/src/actions/allBoards.js @@ -2,6 +2,7 @@ import { getSpecificBoardSuccess } from "./specificBoard"; export const GET_ALL_BOARDS_REQUEST = "GET_ALL_BOARDS_REQUEST"; export const GET_ALL_BOARDS_SUCCESS = "GET_ALL_BOARDS_SUCCESS"; export const GET_ALL_BOARDS_FAILURE = "GET_ALL_BOARDS_FAILURE"; +export const ADD_NEW_BOARD = "ADD_NEW_BOARD"; export function getAllBoardsRequest() { return { @@ -23,6 +24,13 @@ export function getAllBoardsFailure(error) { }; } +export function addNewBoard(data) { + return { + type: ADD_NEW_BOARD, + data + } +} + export function getAllBoardsInit(token, userId) { let config = { method: "GET", diff --git a/client/src/actions/specificBoard.js b/client/src/actions/specificBoard.js index 0bfcef23..1d049e71 100644 --- a/client/src/actions/specificBoard.js +++ b/client/src/actions/specificBoard.js @@ -1,4 +1,4 @@ -import { getAllBoards, getAllBoardsInit } from "./allBoards"; +import { getAllBoards, getAllBoardsInit, addNewBoard } from "./allBoards"; export const GET_SPECIFIC_BOARD_REQUEST = "GET_SPECIFIC_BOARD_REQUEST"; export const GET_SPECIFIC_BOARD_SUCCESS = "GET_SPECIFIC_BOARD_SUCCESS"; @@ -104,7 +104,11 @@ export function createBoard(token, userId) { }) .then(json => { dispatch(getSpecificBoardSuccess(json.data)); - dispatch(getAllBoards(token, userId)); + let newBoard = { + id: json.data._id, + title: json.data.title + } + dispatch(addNewBoard(newBoard)); }) .catch(error => { dispatch(getSpecificBoardFailure(error)); diff --git a/client/src/reducers/allBoards.js b/client/src/reducers/allBoards.js index 93de84d5..9c9fd459 100644 --- a/client/src/reducers/allBoards.js +++ b/client/src/reducers/allBoards.js @@ -20,6 +20,14 @@ export const allBoards = (state = {}, action) => { isFetching: false, error: true }; + case Actions.ADD_NEW_BOARD: + return { + ...state, + data: [ + ...state.data, + action.data + ] + }; default: return state; } diff --git a/server/helpers/index.js b/server/helpers/index.js index 19992eab..519ccb6e 100644 --- a/server/helpers/index.js +++ b/server/helpers/index.js @@ -4,7 +4,7 @@ const checkUserBoardPermissions = (board, user) => { }; const apiMessages = { - successfulPost: "Resource successfully updated.", + successfulPost: "Resource successfully created.", successfulPut: "Resource successfully updated.", successfulDelete: "Resource successfully removed.", failedAuth: "You are not authorized to modify or remove this resource.", From 2781b82c4b362d378456f4b4b9dfa86ece9cfbe9 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Thu, 20 Jul 2017 12:15:34 -0400 Subject: [PATCH 068/112] remove network request from edit board --- client/src/actions/allBoards.js | 10 +++++++++- client/src/actions/specificBoard.js | 8 ++++++-- client/src/reducers/allBoards.js | 11 +++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/client/src/actions/allBoards.js b/client/src/actions/allBoards.js index bc2b58f1..20da0aa1 100644 --- a/client/src/actions/allBoards.js +++ b/client/src/actions/allBoards.js @@ -3,6 +3,7 @@ export const GET_ALL_BOARDS_REQUEST = "GET_ALL_BOARDS_REQUEST"; export const GET_ALL_BOARDS_SUCCESS = "GET_ALL_BOARDS_SUCCESS"; export const GET_ALL_BOARDS_FAILURE = "GET_ALL_BOARDS_FAILURE"; export const ADD_NEW_BOARD = "ADD_NEW_BOARD"; +export const SET_CHANGED_BOARD = "SET_CHANGED_BOARD"; export function getAllBoardsRequest() { return { @@ -28,7 +29,14 @@ export function addNewBoard(data) { return { type: ADD_NEW_BOARD, data - } + }; +} + +export function setChangedBoard(data) { + return { + type: SET_CHANGED_BOARD, + data + }; } export function getAllBoardsInit(token, userId) { diff --git a/client/src/actions/specificBoard.js b/client/src/actions/specificBoard.js index 1d049e71..5bb7034e 100644 --- a/client/src/actions/specificBoard.js +++ b/client/src/actions/specificBoard.js @@ -1,4 +1,4 @@ -import { getAllBoards, getAllBoardsInit, addNewBoard } from "./allBoards"; +import { getAllBoardsInit, addNewBoard, setChangedBoard } from "./allBoards"; export const GET_SPECIFIC_BOARD_REQUEST = "GET_SPECIFIC_BOARD_REQUEST"; export const GET_SPECIFIC_BOARD_SUCCESS = "GET_SPECIFIC_BOARD_SUCCESS"; @@ -72,8 +72,12 @@ export function editSpecificBoard(token, boardId, form, userId) { return response.json(); }) .then(json => { + let changedBoard = { + id: json.data._id, + title: json.data.title + } dispatch(getSpecificBoardSuccess(json.data)); - dispatch(getAllBoards(token, userId)); + dispatch(setChangedBoard(changedBoard)); }) .catch(error => { dispatch(getSpecificBoardFailure(error)); diff --git a/client/src/reducers/allBoards.js b/client/src/reducers/allBoards.js index 9c9fd459..c4550335 100644 --- a/client/src/reducers/allBoards.js +++ b/client/src/reducers/allBoards.js @@ -28,6 +28,17 @@ export const allBoards = (state = {}, action) => { action.data ] }; + case Actions.SET_CHANGED_BOARD: + let newData = state.data.map(board => { + if (board.id.toString() === action.data.id.toString()) { + return action.data + } + return board; + }); + return { + ...state, + data: newData + }; default: return state; } From ade10fe558fe8c2bc457fdbb8b0820735758e27e Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Thu, 20 Jul 2017 12:29:50 -0400 Subject: [PATCH 069/112] fix api delete route --- client/src/components/AuthLayer.js | 23 ++++++++++++++++++++- client/src/containers/AuthLayerContainer.js | 3 ++- client/src/reducers/allBoards.js | 5 ++++- server/routes/api/boards.js | 5 +++-- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/client/src/components/AuthLayer.js b/client/src/components/AuthLayer.js index ababa0fc..05342511 100644 --- a/client/src/components/AuthLayer.js +++ b/client/src/components/AuthLayer.js @@ -10,11 +10,32 @@ const AuthLayer = ({ authError, token, userId, - specificBoard + specificBoard, + allBoards }) => { if (!isAuthenticated) { return ; } + + if (allBoards.length === 0) { + return ( + + +

Djello

+ +

Uh oh, no boards could be found! Make your first one to get started!

+ + + + +
+
+ ) + } return ( diff --git a/client/src/containers/AuthLayerContainer.js b/client/src/containers/AuthLayerContainer.js index 442cc6cc..c93bf3f7 100644 --- a/client/src/containers/AuthLayerContainer.js +++ b/client/src/containers/AuthLayerContainer.js @@ -9,7 +9,8 @@ const mapStateToProps = state => { authError: state.user.error, token: state.user.token, userId: state.user.id, - specificBoard: state.specificBoard.data + specificBoard: state.specificBoard.data, + allBoards: state.allBoards.data }; }; diff --git a/client/src/reducers/allBoards.js b/client/src/reducers/allBoards.js index c4550335..2e1941c3 100644 --- a/client/src/reducers/allBoards.js +++ b/client/src/reducers/allBoards.js @@ -1,6 +1,9 @@ import * as Actions from "../actions/allBoards"; -export const allBoards = (state = {}, action) => { +const initialState = { + data: [] +} +export const allBoards = (state = initialState, action) => { switch (action.type) { case Actions.GET_ALL_BOARDS_SUCCESS: return { diff --git a/server/routes/api/boards.js b/server/routes/api/boards.js index da5dcae4..fc0d36af 100644 --- a/server/routes/api/boards.js +++ b/server/routes/api/boards.js @@ -271,8 +271,9 @@ Board.findById(boardId) return User.update( { boards: { $in: [deletedBoard.id] } }, { - $pop: { boards: deletedBoard } - } + $pull: { boards: deletedBoard.id } + }, + {multi: true} ); }) .then(() => { From 969243be0e835ba2c60ac029a29bf3d01b21e947 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Thu, 20 Jul 2017 12:35:29 -0400 Subject: [PATCH 070/112] add list seeds --- server/package.json | 1 + server/seeds/seeds.js | 19 ++++++++++++++++++- server/yarn.lock | 4 ++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/server/package.json b/server/package.json index db5ac83b..d8762f1e 100644 --- a/server/package.json +++ b/server/package.json @@ -11,6 +11,7 @@ "cookie-parser": "^1.4.3", "express": "^4.15.3", "express-jwt": "^5.3.0", + "faker": "^4.1.0", "jasmine": "^2.6.0", "jsonwebtoken": "^7.4.1", "md5": "^2.2.1", diff --git a/server/seeds/seeds.js b/server/seeds/seeds.js index 78a49a47..85dd39ad 100644 --- a/server/seeds/seeds.js +++ b/server/seeds/seeds.js @@ -1,3 +1,4 @@ +const faker = require('faker'); const MULTIPLIER = 5; module.exports = () => { @@ -29,12 +30,28 @@ module.exports = () => { users[i % users.length].boards.push(board); } + // ---------------------------------------- + // Creating Lists + // ---------------------------------------- + console.log("Creating boards..."); + let lists = []; + for (let i = 0; i < MULTIPLIER * 5; i++) { + let list = new List({ + title: `Test List ${i + 1}`, + description: faker.lorem.sentences(1), + board: boards[i % boards.length], + cards: [] + }); + lists.push(list); + boards[i % boards.length].lists.push(list); + } + // ---------------------------------------- // Finish // ---------------------------------------- console.log("Saving..."); let promises = []; - [users, boards].forEach(collection => { + [users, boards, lists].forEach(collection => { collection.forEach(model => { promises.push(model.save()); }); diff --git a/server/yarn.lock b/server/yarn.lock index 8e3136bc..fbd6af9d 100644 --- a/server/yarn.lock +++ b/server/yarn.lock @@ -449,6 +449,10 @@ extsprintf@1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.0.2.tgz#e1080e0658e300b06294990cc70e1502235fd550" +faker@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/faker/-/faker-4.1.0.tgz#1e45bbbecc6774b3c195fad2835109c6d748cc3f" + fileset@~0.1.5: version "0.1.8" resolved "https://registry.yarnpkg.com/fileset/-/fileset-0.1.8.tgz#506b91a9396eaa7e32fb42a84077c7a0c736b741" From 14fd2f49350d40eff609581db402b3efcdedeea7 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Thu, 20 Jul 2017 12:52:50 -0400 Subject: [PATCH 071/112] add list actions and reducers --- client/src/actions/lists.js | 164 +++++++++++++++++++++++++++++++++++ client/src/reducers/index.js | 4 +- client/src/reducers/lists.js | 63 ++++++++++++++ server/routes/api/lists.js | 2 +- server/seeds/seeds.js | 2 +- 5 files changed, 232 insertions(+), 3 deletions(-) create mode 100644 client/src/actions/lists.js create mode 100644 client/src/reducers/lists.js diff --git a/client/src/actions/lists.js b/client/src/actions/lists.js new file mode 100644 index 00000000..73434a9d --- /dev/null +++ b/client/src/actions/lists.js @@ -0,0 +1,164 @@ +export const GET_LISTS_REQUEST = "GET_LISTS_REQUEST"; +export const GET_LISTS_SUCCESS = "GET_LISTS_SUCCESS"; +export const GET_LISTS_FAILURE = "GET_LISTS_FAILURE"; +export const MODIFY_LIST_FAILURE = "MODIFY_LIST_FAILURE"; +export const ADD_NEW_LIST = "ADD_NEW_LIST"; +export const SET_CHANGED_LIST = "SET_CHANGED_LIST"; +export const DELETE_LIST = "DELETE_LIST"; + +export function getListsRequest() { + return { + type: GET_LISTS_REQUEST + }; +} + +export function getListsSuccess(data) { + return { + type: GET_LISTS_SUCCESS, + data + }; +} + +export function getListsFailure(error) { + return { + type: GET_LISTS_FAILURE, + error + }; +} + +export function addNewList(data) { + return { + type: ADD_NEW_LIST, + data + }; +} + +export function setChangedList(data) { + return { + type: SET_CHANGED_LIST, + data + }; +} + +export function deleteList(data) { + return { + type: DELETE_LIST, + data + } +} + +export function modifyListFailure(data) { + return { + type: MODIFY_LIST_FAILURE, + data + } +} + +export function getLists(token, boardId) { + let config = { + method: "GET", + headers: { Authorization: "Bearer " + token } + }; + + return dispatch => { + dispatch(getListsRequest()); + + fetch(`api/v1/boards/${boardId}/lists`, config) + .then(response => { + if (!response.ok) { + throw new Error(`${response.status}: ${response.statusText}`); + } + + return response.json(); + }) + .then(json => { + dispatch(getListsSuccess(json.data)); + }) + .catch(error => { + dispatch(getListsFailure(error)); + }); + }; +} + + +export function editList(token, listId, form) { + let config = { + method: "PUT", + headers: { + Authorization: "Bearer " + token, + "Content-Type": "application/x-www-form-urlencoded" + }, + body: form + }; + + return dispatch => { + fetch(`api/v1/lists/${listId}`, config) + .then(response => { + if (!response.ok) { + throw new Error(`${response.status}: ${response.statusText}`); + } + + return response.json(); + }) + .then(json => { + dispatch(setChangedList(json.data)); + }) + .catch(error => { + dispatch(modifyListFailure(error)); + }); + }; +} + +export function createList(token, boardId) { + let config = { + method: "POST", + headers: { + Authorization: "Bearer " + token, + "Content-Type": "application/x-www-form-urlencoded" + }, + body: "title=New List&description=Enter a description here" + }; + + return dispatch => { + fetch(`api/v1/boards/${boardId}/lists`, config) + .then(response => { + if (!response.ok) { + throw new Error(`${response.status}: ${response.statusText}`); + } + + return response.json(); + }) + .then(json => { + dispatch(addNewList(json.data)); + }) + .catch(error => { + dispatch(modifyListFailure(error)); + }); + }; +} + +export function deleteBoard(token, listId) { + let config = { + method: "DELETE", + headers: { + Authorization: "Bearer " + token + } + }; + + return dispatch => { + fetch(`api/v1/lists/${listId}`, config) + .then(response => { + if (!response.ok) { + throw new Error(`${response.status}: ${response.statusText}`); + } + + return response.json(); + }) + .then(json => { + dispatch(deleteList(json.data)); + }) + .catch(error => { + dispatch(modifyListFailure(error)); + }); + }; +} diff --git a/client/src/reducers/index.js b/client/src/reducers/index.js index 2e0e14df..5b7bcb75 100644 --- a/client/src/reducers/index.js +++ b/client/src/reducers/index.js @@ -2,11 +2,13 @@ import { combineReducers } from "redux"; import { user } from "./auth"; import { allBoards } from "./allBoards"; import { specificBoard } from "./specificBoard"; +import { lists } from "./lists"; const djelloApp = combineReducers({ user, allBoards, - specificBoard + specificBoard, + lists }); export default djelloApp; diff --git a/client/src/reducers/lists.js b/client/src/reducers/lists.js new file mode 100644 index 00000000..70d6d124 --- /dev/null +++ b/client/src/reducers/lists.js @@ -0,0 +1,63 @@ +import * as Actions from "../actions/lists"; + +const initialState = { + data: [] +} +export const lists = (state = initialState, action) => { + let newData; + switch (action.type) { + case Actions.GET_LISTS_SUCCESS: + return { + ...state, + data: action.data, + isFetching: false + }; + case Actions.GET_LISTS_REQUEST: + return { + ...state, + isFetching: true, + error: null + }; + case Actions.GET_LISTS_FAILURE: + return { + ...state, + isFetching: false, + error: true + }; + case Actions.ADD_NEW_LIST: + return { + ...state, + data: [ + ...state.data, + action.data + ] + }; + case Actions.SET_CHANGED_LIST: + newData = state.data.map(list => { + if (list.id.toString() === action.data._id.toString()) { + return action.data + } + return list; + }); + return { + ...state, + data: newData + }; + case Actions.DELETE_LIST: + // action data is the deleted item + newData = state.data.filter(list => { + return list.id.toString() !== action.data.id.toString(); + }); + return { + ...state, + data: newData + }; + case Actions.MODIFY_LIST_FAILURE: + return { + ...state, + error: action.data + } + default: + return state; + } +}; diff --git a/server/routes/api/lists.js b/server/routes/api/lists.js index 6cca9fb8..7a234fa4 100644 --- a/server/routes/api/lists.js +++ b/server/routes/api/lists.js @@ -36,7 +36,7 @@ router.put("/:id", (req, res, next) => { description: description || list.description }, { new: true } - ); + ).populate('cards'); }) .then(result => { res.json({ diff --git a/server/seeds/seeds.js b/server/seeds/seeds.js index 85dd39ad..218b572d 100644 --- a/server/seeds/seeds.js +++ b/server/seeds/seeds.js @@ -33,7 +33,7 @@ module.exports = () => { // ---------------------------------------- // Creating Lists // ---------------------------------------- - console.log("Creating boards..."); + console.log("Creating lists..."); let lists = []; for (let i = 0; i < MULTIPLIER * 5; i++) { let list = new List({ From d8263add46abadbe5e7263aae592136e6a444f04 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Thu, 20 Jul 2017 12:56:21 -0400 Subject: [PATCH 072/112] add list dispatches to board changes --- client/src/actions/allBoards.js | 2 ++ client/src/actions/specificBoard.js | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/client/src/actions/allBoards.js b/client/src/actions/allBoards.js index 20da0aa1..605776c3 100644 --- a/client/src/actions/allBoards.js +++ b/client/src/actions/allBoards.js @@ -1,4 +1,5 @@ import { getSpecificBoardSuccess } from "./specificBoard"; +import { getListsSuccess } from "./lists"; export const GET_ALL_BOARDS_REQUEST = "GET_ALL_BOARDS_REQUEST"; export const GET_ALL_BOARDS_SUCCESS = "GET_ALL_BOARDS_SUCCESS"; export const GET_ALL_BOARDS_FAILURE = "GET_ALL_BOARDS_FAILURE"; @@ -66,6 +67,7 @@ export function getAllBoardsInit(token, userId) { let specificBoard = json.data[0]; dispatch(getAllBoardsSuccess(boardIds)); dispatch(getSpecificBoardSuccess(specificBoard)); + dispatch(getListsSuccess(specificBoard.lists)); }) .catch(error => { dispatch(getAllBoardsFailure(error)); diff --git a/client/src/actions/specificBoard.js b/client/src/actions/specificBoard.js index 5bb7034e..3eeaf5bf 100644 --- a/client/src/actions/specificBoard.js +++ b/client/src/actions/specificBoard.js @@ -1,5 +1,5 @@ import { getAllBoardsInit, addNewBoard, setChangedBoard } from "./allBoards"; - +import { getListsSuccess } from "./lists"; export const GET_SPECIFIC_BOARD_REQUEST = "GET_SPECIFIC_BOARD_REQUEST"; export const GET_SPECIFIC_BOARD_SUCCESS = "GET_SPECIFIC_BOARD_SUCCESS"; export const GET_SPECIFIC_BOARD_FAILURE = "GET_SPECIFIC_BOARD_FAILURE"; @@ -43,6 +43,7 @@ export function getSpecificBoard(token, boardId) { }) .then(json => { dispatch(getSpecificBoardSuccess(json.data)); + dispatch(getListsSuccess(json.data.lists)); }) .catch(error => { dispatch(getSpecificBoardFailure(error)); From c0eec931336616724a4e5a3e242c0abf1fe02ce9 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Thu, 20 Jul 2017 13:03:31 -0400 Subject: [PATCH 073/112] add list display --- client/src/components/Board.js | 24 ++++++++++++++++++++++-- client/src/containers/BoardContainer.js | 3 ++- client/src/index.css | 5 +++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/client/src/components/Board.js b/client/src/components/Board.js index 45352960..0c11ce54 100644 --- a/client/src/components/Board.js +++ b/client/src/components/Board.js @@ -1,8 +1,25 @@ import React from "react"; -import { Col, Row } from "react-bootstrap"; +import { Panel, Col, Row } from "react-bootstrap"; import EditableField from "./EditableField"; -const Board = ({ board, onChangeBoardTitle }) => { +const buildLists = (lists) => { + return lists.map(list => ( + + +
{list.title}
+

{list.description}

+
+ + )); +}; + +const Board = ({ board, lists, onChangeBoardTitle }) => { + let listPanels; + if (lists.length === 0) { + listPanels = null; + } else { + listPanels = buildLists(lists); + } return ( @@ -12,6 +29,9 @@ const Board = ({ board, onChangeBoardTitle }) => { + + {listPanels} + ); }; diff --git a/client/src/containers/BoardContainer.js b/client/src/containers/BoardContainer.js index f07df2b7..c32b198e 100644 --- a/client/src/containers/BoardContainer.js +++ b/client/src/containers/BoardContainer.js @@ -5,7 +5,8 @@ import { editSpecificBoard } from "../actions/specificBoard"; const mapStateToProps = state => { return { - board: state.specificBoard.data + board: state.specificBoard.data, + lists: state.lists.data }; }; diff --git a/client/src/index.css b/client/src/index.css index 2df87451..3267171a 100644 --- a/client/src/index.css +++ b/client/src/index.css @@ -18,4 +18,9 @@ h1 { a { cursor: pointer; +} + +.row > [class*='col-'] { + display: flex; + flex-direction: column; } \ No newline at end of file From dd89a9545da9e6ff6cc1623b8be7e376ac89f705 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Thu, 20 Jul 2017 13:10:27 -0400 Subject: [PATCH 074/112] add list create to view --- client/src/components/Board.js | 3 ++- client/src/containers/BoardContainer.js | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/client/src/components/Board.js b/client/src/components/Board.js index 0c11ce54..8c3728ca 100644 --- a/client/src/components/Board.js +++ b/client/src/components/Board.js @@ -13,7 +13,7 @@ const buildLists = (lists) => { )); }; -const Board = ({ board, lists, onChangeBoardTitle }) => { +const Board = ({ board, lists, onChangeBoardTitle, onCreateList }) => { let listPanels; if (lists.length === 0) { listPanels = null; @@ -27,6 +27,7 @@ const Board = ({ board, lists, onChangeBoardTitle }) => {

{board.title}

+ Add a List diff --git a/client/src/containers/BoardContainer.js b/client/src/containers/BoardContainer.js index c32b198e..c0a07480 100644 --- a/client/src/containers/BoardContainer.js +++ b/client/src/containers/BoardContainer.js @@ -2,6 +2,7 @@ import { connect } from "react-redux"; import Board from "../components/Board"; import serialize from "form-serialize"; import { editSpecificBoard } from "../actions/specificBoard"; +import { createList } from "../actions/lists"; const mapStateToProps = state => { return { @@ -24,6 +25,10 @@ const mapDispatchToProps = (dispatch, ownProps) => { ownProps.userId ) ); + }, + onCreateList: e => { + e.preventDefault(); + dispatch(createList(ownProps.token, ownProps.boardId)); } }; }; From 3f7399b4b2adee3206b1760ed6005fef7b6495d5 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Thu, 20 Jul 2017 13:19:05 -0400 Subject: [PATCH 075/112] add list deleting --- client/src/actions/lists.js | 5 ++--- client/src/components/Board.js | 7 ++++--- client/src/containers/BoardContainer.js | 6 +++++- client/src/reducers/lists.js | 4 ++-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/client/src/actions/lists.js b/client/src/actions/lists.js index 73434a9d..a7bba8ed 100644 --- a/client/src/actions/lists.js +++ b/client/src/actions/lists.js @@ -137,14 +137,13 @@ export function createList(token, boardId) { }; } -export function deleteBoard(token, listId) { +export function deleteSelectedList(token, listId) { let config = { method: "DELETE", headers: { Authorization: "Bearer " + token } }; - return dispatch => { fetch(`api/v1/lists/${listId}`, config) .then(response => { @@ -155,7 +154,7 @@ export function deleteBoard(token, listId) { return response.json(); }) .then(json => { - dispatch(deleteList(json.data)); + dispatch(deleteList(json.data.deletedResource)); }) .catch(error => { dispatch(modifyListFailure(error)); diff --git a/client/src/components/Board.js b/client/src/components/Board.js index 8c3728ca..b3af6798 100644 --- a/client/src/components/Board.js +++ b/client/src/components/Board.js @@ -2,23 +2,24 @@ import React from "react"; import { Panel, Col, Row } from "react-bootstrap"; import EditableField from "./EditableField"; -const buildLists = (lists) => { +const buildLists = (lists, onDeleteList) => { return lists.map(list => (
{list.title}

{list.description}

+ onDeleteList(e, list._id)}>Delete This List )); }; -const Board = ({ board, lists, onChangeBoardTitle, onCreateList }) => { +const Board = ({ board, lists, onChangeBoardTitle, onCreateList, onDeleteList }) => { let listPanels; if (lists.length === 0) { listPanels = null; } else { - listPanels = buildLists(lists); + listPanels = buildLists(lists, onDeleteList); } return ( diff --git a/client/src/containers/BoardContainer.js b/client/src/containers/BoardContainer.js index c0a07480..4d92bfb4 100644 --- a/client/src/containers/BoardContainer.js +++ b/client/src/containers/BoardContainer.js @@ -2,7 +2,7 @@ import { connect } from "react-redux"; import Board from "../components/Board"; import serialize from "form-serialize"; import { editSpecificBoard } from "../actions/specificBoard"; -import { createList } from "../actions/lists"; +import { createList, deleteSelectedList } from "../actions/lists"; const mapStateToProps = state => { return { @@ -29,6 +29,10 @@ const mapDispatchToProps = (dispatch, ownProps) => { onCreateList: e => { e.preventDefault(); dispatch(createList(ownProps.token, ownProps.boardId)); + }, + onDeleteList: (e, listId) => { + e.preventDefault(); + dispatch(deleteSelectedList(ownProps.token, listId)); } }; }; diff --git a/client/src/reducers/lists.js b/client/src/reducers/lists.js index 70d6d124..d047bf77 100644 --- a/client/src/reducers/lists.js +++ b/client/src/reducers/lists.js @@ -34,7 +34,7 @@ export const lists = (state = initialState, action) => { }; case Actions.SET_CHANGED_LIST: newData = state.data.map(list => { - if (list.id.toString() === action.data._id.toString()) { + if (list._id.toString() === action.data._id.toString()) { return action.data } return list; @@ -46,7 +46,7 @@ export const lists = (state = initialState, action) => { case Actions.DELETE_LIST: // action data is the deleted item newData = state.data.filter(list => { - return list.id.toString() !== action.data.id.toString(); + return list._id.toString() !== action.data._id.toString(); }); return { ...state, From 5c4bc90c27eea6bbccd006a9ed224d7bc7a749e8 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Thu, 20 Jul 2017 14:01:01 -0400 Subject: [PATCH 076/112] add list updating and list container --- client/src/components/Board.js | 17 +++++---------- client/src/components/List.js | 25 +++++++++++++++++++++ client/src/containers/BoardContainer.js | 11 ++++------ client/src/containers/ListContainer.js | 29 +++++++++++++++++++++++++ client/src/index.css | 7 ++++++ 5 files changed, 71 insertions(+), 18 deletions(-) create mode 100644 client/src/components/List.js create mode 100644 client/src/containers/ListContainer.js diff --git a/client/src/components/Board.js b/client/src/components/Board.js index b3af6798..e86e3257 100644 --- a/client/src/components/Board.js +++ b/client/src/components/Board.js @@ -1,25 +1,20 @@ import React from "react"; -import { Panel, Col, Row } from "react-bootstrap"; +import { Col, Row } from "react-bootstrap"; import EditableField from "./EditableField"; +import ListContainer from "../containers/ListContainer"; -const buildLists = (lists, onDeleteList) => { +const buildLists = (lists, token) => { return lists.map(list => ( - - -
{list.title}
-

{list.description}

-
- onDeleteList(e, list._id)}>Delete This List - + )); }; -const Board = ({ board, lists, onChangeBoardTitle, onCreateList, onDeleteList }) => { +const Board = ({ board, lists, token, onChangeBoardTitle, onCreateList }) => { let listPanels; if (lists.length === 0) { listPanels = null; } else { - listPanels = buildLists(lists, onDeleteList); + listPanels = buildLists(lists, token); } return ( diff --git a/client/src/components/List.js b/client/src/components/List.js new file mode 100644 index 00000000..4132d872 --- /dev/null +++ b/client/src/components/List.js @@ -0,0 +1,25 @@ +import React from "react"; +import {Panel, Col } from "react-bootstrap"; +import EditableField from "./EditableField"; + +const List = ({list, onDeleteList, onUpdateList}) => { + return ( + + +

{list.title}

+ + } + className="list-panel" + > + +

{list.description}

+
+
+ onDeleteList(e, list._id)} className="list-delete">Delete This List + + ) +}; + +export default List; \ No newline at end of file diff --git a/client/src/containers/BoardContainer.js b/client/src/containers/BoardContainer.js index 4d92bfb4..632b8b6b 100644 --- a/client/src/containers/BoardContainer.js +++ b/client/src/containers/BoardContainer.js @@ -2,12 +2,13 @@ import { connect } from "react-redux"; import Board from "../components/Board"; import serialize from "form-serialize"; import { editSpecificBoard } from "../actions/specificBoard"; -import { createList, deleteSelectedList } from "../actions/lists"; +import { createList } from "../actions/lists"; -const mapStateToProps = state => { +const mapStateToProps = (state, ownProps) => { return { board: state.specificBoard.data, - lists: state.lists.data + lists: state.lists.data, + token: ownProps.token }; }; @@ -29,10 +30,6 @@ const mapDispatchToProps = (dispatch, ownProps) => { onCreateList: e => { e.preventDefault(); dispatch(createList(ownProps.token, ownProps.boardId)); - }, - onDeleteList: (e, listId) => { - e.preventDefault(); - dispatch(deleteSelectedList(ownProps.token, listId)); } }; }; diff --git a/client/src/containers/ListContainer.js b/client/src/containers/ListContainer.js new file mode 100644 index 00000000..7d1ee143 --- /dev/null +++ b/client/src/containers/ListContainer.js @@ -0,0 +1,29 @@ +import { connect } from "react-redux"; +import List from "../components/List"; +import serialize from "form-serialize"; +import { editList, deleteSelectedList } from "../actions/lists"; + +const mapStateToProps = (state, ownProps) => { + return { + list: ownProps.list + }; +}; + +const mapDispatchToProps = (dispatch, ownProps) => { + return { + onUpdateList: e => { + e.preventDefault(); + const form = e.target; + const data = serialize(form); + dispatch(editList(ownProps.token, ownProps.list._id, data)); + }, + onDeleteList: (e, listId) => { + e.preventDefault(); + dispatch(deleteSelectedList(ownProps.token, listId)); + } + }; +}; + +const ListContainer = connect(mapStateToProps, mapDispatchToProps)(List); + +export default ListContainer; diff --git a/client/src/index.css b/client/src/index.css index 3267171a..6e0a3846 100644 --- a/client/src/index.css +++ b/client/src/index.css @@ -23,4 +23,11 @@ a { .row > [class*='col-'] { display: flex; flex-direction: column; +} + +.list-panel { + margin-bottom: 2px; +} +.list-delete { + margin-bottom: 2em; } \ No newline at end of file From 895420bbe94c8b2b1b3513e4e87e3faf0e225677 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Thu, 20 Jul 2017 14:03:24 -0400 Subject: [PATCH 077/112] add confirmation dialog for deleting list --- client/src/components/List.js | 2 +- client/src/containers/ListContainer.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/client/src/components/List.js b/client/src/components/List.js index 4132d872..8e0606e5 100644 --- a/client/src/components/List.js +++ b/client/src/components/List.js @@ -4,7 +4,7 @@ import EditableField from "./EditableField"; const List = ({list, onDeleteList, onUpdateList}) => { return ( - + diff --git a/client/src/containers/ListContainer.js b/client/src/containers/ListContainer.js index 7d1ee143..ab11f096 100644 --- a/client/src/containers/ListContainer.js +++ b/client/src/containers/ListContainer.js @@ -18,8 +18,12 @@ const mapDispatchToProps = (dispatch, ownProps) => { dispatch(editList(ownProps.token, ownProps.list._id, data)); }, onDeleteList: (e, listId) => { - e.preventDefault(); - dispatch(deleteSelectedList(ownProps.token, listId)); + if (window.confirm( + `Are you sure you want to delete the following list? \n \n ${ownProps.list.title}` + )) { + e.preventDefault(); + dispatch(deleteSelectedList(ownProps.token, listId)); + } } }; }; From dd62c680a1446ac21f8b676b927e55c5f5becbfa Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Thu, 20 Jul 2017 14:12:50 -0400 Subject: [PATCH 078/112] add card seeding --- client/src/components/Board.js | 2 +- client/src/index.css | 9 +++++++-- server/seeds/seeds.js | 19 ++++++++++++++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/client/src/components/Board.js b/client/src/components/Board.js index e86e3257..af26f7c9 100644 --- a/client/src/components/Board.js +++ b/client/src/components/Board.js @@ -23,7 +23,7 @@ const Board = ({ board, lists, token, onChangeBoardTitle, onCreateList }) => {

{board.title}

- Add a List + Add a List
diff --git a/client/src/index.css b/client/src/index.css index 6e0a3846..b5fb893c 100644 --- a/client/src/index.css +++ b/client/src/index.css @@ -11,9 +11,10 @@ body { h1 { text-align: center; text-transform: uppercase; - padding-bottom: 1em; + padding-bottom: 10px; border-bottom: solid 3px #2C3E50; - margin-bottom: 1em; + margin-bottom: 15px; + margin-top: 0px; } a { @@ -30,4 +31,8 @@ a { } .list-delete { margin-bottom: 2em; +} + +.add-list-link { + margin-bottom: 2em; } \ No newline at end of file diff --git a/server/seeds/seeds.js b/server/seeds/seeds.js index 218b572d..b7491ba1 100644 --- a/server/seeds/seeds.js +++ b/server/seeds/seeds.js @@ -46,12 +46,29 @@ module.exports = () => { boards[i % boards.length].lists.push(list); } + // ---------------------------------------- + // Creating Cards + // ---------------------------------------- + console.log("Creating cards..."); + let cards = []; + for (let i = 0; i < MULTIPLIER * 50; i++) { + let card = new Card({ + title: `Test Card ${i + 1}`, + description: faker.lorem.sentences(1), + list: lists[i % lists.length], + activities: [], + members: users[i % users.length] + }); + cards.push(card); + lists[i % lists.length].cards.push(card); + } + // ---------------------------------------- // Finish // ---------------------------------------- console.log("Saving..."); let promises = []; - [users, boards, lists].forEach(collection => { + [users, boards, lists, cards].forEach(collection => { collection.forEach(model => { promises.push(model.save()); }); From c94aa74a65fb0934e165d3f1bdae6b4069dc5c7f Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Thu, 20 Jul 2017 14:21:16 -0400 Subject: [PATCH 079/112] add card component and container --- client/src/components/Card.js | 11 +++++++++ client/src/components/List.js | 18 +++++++++++++- client/src/containers/CardContainer.js | 33 ++++++++++++++++++++++++++ client/src/containers/ListContainer.js | 3 ++- 4 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 client/src/components/Card.js create mode 100644 client/src/containers/CardContainer.js diff --git a/client/src/components/Card.js b/client/src/components/Card.js new file mode 100644 index 00000000..bb90a66c --- /dev/null +++ b/client/src/components/Card.js @@ -0,0 +1,11 @@ +import React from "react"; +import {Panel} from "react-bootstrap"; +const Card = ({card}) => { + return ( + + {card.description} + + ); +}; + +export default Card; \ No newline at end of file diff --git a/client/src/components/List.js b/client/src/components/List.js index 8e0606e5..1e1bd516 100644 --- a/client/src/components/List.js +++ b/client/src/components/List.js @@ -1,8 +1,21 @@ import React from "react"; import {Panel, Col } from "react-bootstrap"; import EditableField from "./EditableField"; +import CardContainer from "../containers/CardContainer"; -const List = ({list, onDeleteList, onUpdateList}) => { +const buildCards = (cards, token) => { + return cards.map(card => ( + + )); +} + +const List = ({list, token, onDeleteList, onUpdateList}) => { + let cardPanels; + if (list.cards.length === 0) { + cardPanels = null; + } else { + cardPanels = buildCards(list.cards, token); + } return ( {

{list.description}

+ + {cardPanels} +
onDeleteList(e, list._id)} className="list-delete">Delete This List diff --git a/client/src/containers/CardContainer.js b/client/src/containers/CardContainer.js new file mode 100644 index 00000000..0f22623c --- /dev/null +++ b/client/src/containers/CardContainer.js @@ -0,0 +1,33 @@ +import { connect } from "react-redux"; +import Card from "../components/Card"; +import serialize from "form-serialize"; +// import { editCard, deleteSelectedCard } from "../actions/lists"; + +const mapStateToProps = (state, ownProps) => { + return { + card: ownProps.card + }; +}; + +const mapDispatchToProps = (dispatch, ownProps) => { + return { + // onUpdateCard: e => { + // e.preventDefault(); + // const form = e.target; + // const data = serialize(form); + // dispatch(editCard(ownProps.token, ownProps.list._id, data)); + // }, + // onDeleteCard: (e, listId) => { + // if (window.confirm( + // `Are you sure you want to delete the following list? \n \n ${ownProps.list.title}` + // )) { + // e.preventDefault(); + // dispatch(deleteSelectedCard(ownProps.token, listId)); + // } + // } + }; +}; + +const CardContainer = connect(mapStateToProps, mapDispatchToProps)(Card); + +export default CardContainer; diff --git a/client/src/containers/ListContainer.js b/client/src/containers/ListContainer.js index ab11f096..f76f46a6 100644 --- a/client/src/containers/ListContainer.js +++ b/client/src/containers/ListContainer.js @@ -5,7 +5,8 @@ import { editList, deleteSelectedList } from "../actions/lists"; const mapStateToProps = (state, ownProps) => { return { - list: ownProps.list + list: ownProps.list, + token: ownProps.token }; }; From d0ba579d75fc7abeaa25ee8a6959ef493132b766 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Thu, 20 Jul 2017 14:37:39 -0400 Subject: [PATCH 080/112] add card updating --- client/src/actions/cards.js | 0 client/src/actions/lists.js | 39 ++++++++++++++++++++++++++ client/src/components/Card.js | 14 +++++++-- client/src/components/List.js | 1 + client/src/containers/CardContainer.js | 14 ++++----- client/src/reducers/lists.js | 20 +++++++++++++ 6 files changed, 78 insertions(+), 10 deletions(-) create mode 100644 client/src/actions/cards.js diff --git a/client/src/actions/cards.js b/client/src/actions/cards.js new file mode 100644 index 00000000..e69de29b diff --git a/client/src/actions/lists.js b/client/src/actions/lists.js index a7bba8ed..5c0b9c32 100644 --- a/client/src/actions/lists.js +++ b/client/src/actions/lists.js @@ -5,6 +5,7 @@ export const MODIFY_LIST_FAILURE = "MODIFY_LIST_FAILURE"; export const ADD_NEW_LIST = "ADD_NEW_LIST"; export const SET_CHANGED_LIST = "SET_CHANGED_LIST"; export const DELETE_LIST = "DELETE_LIST"; +export const SET_CHANGED_CARD = "SET_CHANGED_CARD"; export function getListsRequest() { return { @@ -54,6 +55,13 @@ export function modifyListFailure(data) { } } +export function setChangedCard(data) { + return { + type: SET_CHANGED_CARD, + data + }; +} + export function getLists(token, boardId) { let config = { method: "GET", @@ -161,3 +169,34 @@ export function deleteSelectedList(token, listId) { }); }; } + +/* =============== + Nested Card Actions +================ */ +export function editCard(token, cardId, form) { +let config = { + method: "PUT", + headers: { + Authorization: "Bearer " + token, + "Content-Type": "application/x-www-form-urlencoded" + }, + body: form +}; + +return dispatch => { + fetch(`api/v1/cards/${cardId}`, config) + .then(response => { + if (!response.ok) { + throw new Error(`${response.status}: ${response.statusText}`); + } + + return response.json(); + }) + .then(json => { + dispatch(setChangedCard(json.data)); + }) + .catch(error => { + dispatch(modifyListFailure(error)); + }); +}; +} \ No newline at end of file diff --git a/client/src/components/Card.js b/client/src/components/Card.js index bb90a66c..a4152d67 100644 --- a/client/src/components/Card.js +++ b/client/src/components/Card.js @@ -1,9 +1,17 @@ import React from "react"; import {Panel} from "react-bootstrap"; -const Card = ({card}) => { +import EditableField from "./EditableField"; + +const Card = ({card, onUpdateCard}) => { return ( - - {card.description} + + +

{card.description}

+
+
); }; diff --git a/client/src/components/List.js b/client/src/components/List.js index 1e1bd516..4a2cc069 100644 --- a/client/src/components/List.js +++ b/client/src/components/List.js @@ -19,6 +19,7 @@ const List = ({list, token, onDeleteList, onUpdateList}) => { return (

{list.title}

diff --git a/client/src/containers/CardContainer.js b/client/src/containers/CardContainer.js index 0f22623c..c13bf7b0 100644 --- a/client/src/containers/CardContainer.js +++ b/client/src/containers/CardContainer.js @@ -1,7 +1,7 @@ import { connect } from "react-redux"; import Card from "../components/Card"; import serialize from "form-serialize"; -// import { editCard, deleteSelectedCard } from "../actions/lists"; +import { editCard } from "../actions/lists"; const mapStateToProps = (state, ownProps) => { return { @@ -11,12 +11,12 @@ const mapStateToProps = (state, ownProps) => { const mapDispatchToProps = (dispatch, ownProps) => { return { - // onUpdateCard: e => { - // e.preventDefault(); - // const form = e.target; - // const data = serialize(form); - // dispatch(editCard(ownProps.token, ownProps.list._id, data)); - // }, + onUpdateCard: e => { + e.preventDefault(); + const form = e.target; + const data = serialize(form); + dispatch(editCard(ownProps.token, ownProps.card._id, data)); + }, // onDeleteCard: (e, listId) => { // if (window.confirm( // `Are you sure you want to delete the following list? \n \n ${ownProps.list.title}` diff --git a/client/src/reducers/lists.js b/client/src/reducers/lists.js index d047bf77..de1035c9 100644 --- a/client/src/reducers/lists.js +++ b/client/src/reducers/lists.js @@ -57,6 +57,26 @@ export const lists = (state = initialState, action) => { ...state, error: action.data } + case Actions.SET_CHANGED_CARD: + newData = state.data.map(list => { + if (list._id.toString() === action.data.list.toString()) { + let updatedCards = list.cards.map(card => { + if (card._id.toString() === action.data._id.toString()) { + return action.data; + } + + return card; + }); + + return {...list, cards: updatedCards} + } + + return list; + }); + return { + ...state, + data: newData + }; default: return state; } From 5e44c0b8af372475ba2beaab2015fb92100336af Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Thu, 20 Jul 2017 14:45:37 -0400 Subject: [PATCH 081/112] add card deleting --- client/src/actions/lists.js | 82 ++++++++++++++++++-------- client/src/components/Card.js | 4 +- client/src/containers/CardContainer.js | 18 +++--- client/src/reducers/lists.js | 29 +++++++-- 4 files changed, 91 insertions(+), 42 deletions(-) diff --git a/client/src/actions/lists.js b/client/src/actions/lists.js index 5c0b9c32..635e3f7f 100644 --- a/client/src/actions/lists.js +++ b/client/src/actions/lists.js @@ -6,6 +6,7 @@ export const ADD_NEW_LIST = "ADD_NEW_LIST"; export const SET_CHANGED_LIST = "SET_CHANGED_LIST"; export const DELETE_LIST = "DELETE_LIST"; export const SET_CHANGED_CARD = "SET_CHANGED_CARD"; +export const DELETE_CARD = "DELETE_CARD"; export function getListsRequest() { return { @@ -62,6 +63,13 @@ export function setChangedCard(data) { }; } +export function deleteCard(data) { + return { + type: DELETE_CARD, + data + } +} + export function getLists(token, boardId) { let config = { method: "GET", @@ -174,29 +182,53 @@ export function deleteSelectedList(token, listId) { Nested Card Actions ================ */ export function editCard(token, cardId, form) { -let config = { - method: "PUT", - headers: { - Authorization: "Bearer " + token, - "Content-Type": "application/x-www-form-urlencoded" - }, - body: form -}; - -return dispatch => { - fetch(`api/v1/cards/${cardId}`, config) - .then(response => { - if (!response.ok) { - throw new Error(`${response.status}: ${response.statusText}`); - } - - return response.json(); - }) - .then(json => { - dispatch(setChangedCard(json.data)); - }) - .catch(error => { - dispatch(modifyListFailure(error)); - }); -}; + let config = { + method: "PUT", + headers: { + Authorization: "Bearer " + token, + "Content-Type": "application/x-www-form-urlencoded" + }, + body: form + }; + + return dispatch => { + fetch(`api/v1/cards/${cardId}`, config) + .then(response => { + if (!response.ok) { + throw new Error(`${response.status}: ${response.statusText}`); + } + + return response.json(); + }) + .then(json => { + dispatch(setChangedCard(json.data)); + }) + .catch(error => { + dispatch(modifyListFailure(error)); + }); + }; +} +export function deleteSelectedCard(token, cardId) { + let config = { + method: "DELETE", + headers: { + Authorization: "Bearer " + token + } + }; + return dispatch => { + fetch(`api/v1/cards/${cardId}`, config) + .then(response => { + if (!response.ok) { + throw new Error(`${response.status}: ${response.statusText}`); + } + + return response.json(); + }) + .then(json => { + dispatch(deleteCard(json.data.deletedResource)); + }) + .catch(error => { + dispatch(modifyListFailure(error)); + }); + }; } \ No newline at end of file diff --git a/client/src/components/Card.js b/client/src/components/Card.js index a4152d67..4a28c42e 100644 --- a/client/src/components/Card.js +++ b/client/src/components/Card.js @@ -2,7 +2,7 @@ import React from "react"; import {Panel} from "react-bootstrap"; import EditableField from "./EditableField"; -const Card = ({card, onUpdateCard}) => { +const Card = ({card, onUpdateCard, onDeleteCard}) => { return ( {

{card.description}

- + onDeleteCard(e, card._id)} className="card-delete">Delete This Card
); }; diff --git a/client/src/containers/CardContainer.js b/client/src/containers/CardContainer.js index c13bf7b0..36c1816f 100644 --- a/client/src/containers/CardContainer.js +++ b/client/src/containers/CardContainer.js @@ -1,7 +1,7 @@ import { connect } from "react-redux"; import Card from "../components/Card"; import serialize from "form-serialize"; -import { editCard } from "../actions/lists"; +import { editCard, deleteSelectedCard } from "../actions/lists"; const mapStateToProps = (state, ownProps) => { return { @@ -17,14 +17,14 @@ const mapDispatchToProps = (dispatch, ownProps) => { const data = serialize(form); dispatch(editCard(ownProps.token, ownProps.card._id, data)); }, - // onDeleteCard: (e, listId) => { - // if (window.confirm( - // `Are you sure you want to delete the following list? \n \n ${ownProps.list.title}` - // )) { - // e.preventDefault(); - // dispatch(deleteSelectedCard(ownProps.token, listId)); - // } - // } + onDeleteCard: (e, cardId) => { + if (window.confirm( + `Are you sure you want to delete the following card? \n \n ${ownProps.card.title}` + )) { + e.preventDefault(); + dispatch(deleteSelectedCard(ownProps.token, cardId)); + } + } }; }; diff --git a/client/src/reducers/lists.js b/client/src/reducers/lists.js index de1035c9..9210b901 100644 --- a/client/src/reducers/lists.js +++ b/client/src/reducers/lists.js @@ -61,18 +61,35 @@ export const lists = (state = initialState, action) => { newData = state.data.map(list => { if (list._id.toString() === action.data.list.toString()) { let updatedCards = list.cards.map(card => { - if (card._id.toString() === action.data._id.toString()) { - return action.data; - } - - return card; - }); + if (card._id.toString() === action.data._id.toString()) { + return action.data; + } + + return card; + }); return {...list, cards: updatedCards} } return list; }); + return { + ...state, + data: newData + }; + case Actions.DELETE_CARD: + newData = state.data.map(list => { + if (list._id.toString() === action.data.list.toString()) { + let updatedCards = list.cards.filter(card => { + return card._id.toString() !== action.data._id.toString(); + }); + + return {...list, cards: updatedCards}; + } + + return list; + }); + return { ...state, data: newData From 1511ce6562db781ca2feeea9c31b7e2df7f833fd Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Thu, 20 Jul 2017 14:46:48 -0400 Subject: [PATCH 082/112] add card title editing --- client/src/components/Card.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/src/components/Card.js b/client/src/components/Card.js index 4a28c42e..67860f39 100644 --- a/client/src/components/Card.js +++ b/client/src/components/Card.js @@ -6,7 +6,11 @@ const Card = ({card, onUpdateCard, onDeleteCard}) => { return ( + {card.title} + + } >

{card.description}

From bc6d51eb5d7fb7995ab6d392001eba0b276fdf26 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Thu, 20 Jul 2017 14:55:01 -0400 Subject: [PATCH 083/112] Add card creation --- client/src/actions/cards.js | 0 client/src/actions/lists.js | 35 ++++++++++++++++++++++++++ client/src/components/List.js | 3 ++- client/src/containers/ListContainer.js | 6 ++++- client/src/reducers/lists.js | 12 +++++++++ 5 files changed, 54 insertions(+), 2 deletions(-) delete mode 100644 client/src/actions/cards.js diff --git a/client/src/actions/cards.js b/client/src/actions/cards.js deleted file mode 100644 index e69de29b..00000000 diff --git a/client/src/actions/lists.js b/client/src/actions/lists.js index 635e3f7f..38472c80 100644 --- a/client/src/actions/lists.js +++ b/client/src/actions/lists.js @@ -5,6 +5,7 @@ export const MODIFY_LIST_FAILURE = "MODIFY_LIST_FAILURE"; export const ADD_NEW_LIST = "ADD_NEW_LIST"; export const SET_CHANGED_LIST = "SET_CHANGED_LIST"; export const DELETE_LIST = "DELETE_LIST"; +export const ADD_NEW_CARD = "ADD_NEW_CARD"; export const SET_CHANGED_CARD = "SET_CHANGED_CARD"; export const DELETE_CARD = "DELETE_CARD"; @@ -56,6 +57,12 @@ export function modifyListFailure(data) { } } +export function addNewCard(data) { + return { + type: ADD_NEW_CARD, + data + }; +} export function setChangedCard(data) { return { type: SET_CHANGED_CARD, @@ -231,4 +238,32 @@ export function deleteSelectedCard(token, cardId) { dispatch(modifyListFailure(error)); }); }; +} + +export function createCard(token, listId) { + let config = { + method: "POST", + headers: { + Authorization: "Bearer " + token, + "Content-Type": "application/x-www-form-urlencoded" + }, + body: "title=New Card&description=Enter a description here" + }; + + return dispatch => { + fetch(`api/v1/lists/${listId}/cards`, config) + .then(response => { + if (!response.ok) { + throw new Error(`${response.status}: ${response.statusText}`); + } + + return response.json(); + }) + .then(json => { + dispatch(addNewCard(json.data)); + }) + .catch(error => { + dispatch(modifyListFailure(error)); + }); + }; } \ No newline at end of file diff --git a/client/src/components/List.js b/client/src/components/List.js index 4a2cc069..feff2c5e 100644 --- a/client/src/components/List.js +++ b/client/src/components/List.js @@ -9,7 +9,7 @@ const buildCards = (cards, token) => { )); } -const List = ({list, token, onDeleteList, onUpdateList}) => { +const List = ({list, token, onDeleteList, onUpdateList, onCreateCard}) => { let cardPanels; if (list.cards.length === 0) { cardPanels = null; @@ -33,6 +33,7 @@ const List = ({list, token, onDeleteList, onUpdateList}) => { {cardPanels} + onCreateCard(e, list._id)} className="card-create">Create New Card
onDeleteList(e, list._id)} className="list-delete">Delete This List diff --git a/client/src/containers/ListContainer.js b/client/src/containers/ListContainer.js index f76f46a6..24493d3e 100644 --- a/client/src/containers/ListContainer.js +++ b/client/src/containers/ListContainer.js @@ -1,7 +1,7 @@ import { connect } from "react-redux"; import List from "../components/List"; import serialize from "form-serialize"; -import { editList, deleteSelectedList } from "../actions/lists"; +import { editList, deleteSelectedList, createCard } from "../actions/lists"; const mapStateToProps = (state, ownProps) => { return { @@ -25,6 +25,10 @@ const mapDispatchToProps = (dispatch, ownProps) => { e.preventDefault(); dispatch(deleteSelectedList(ownProps.token, listId)); } + }, + onCreateCard: (e, listId) => { + e.preventDefault(); + dispatch(createCard(ownProps.token, listId)); } }; }; diff --git a/client/src/reducers/lists.js b/client/src/reducers/lists.js index 9210b901..fbb4f00f 100644 --- a/client/src/reducers/lists.js +++ b/client/src/reducers/lists.js @@ -57,6 +57,18 @@ export const lists = (state = initialState, action) => { ...state, error: action.data } + case Actions.ADD_NEW_CARD: + newData = state.data.map(list => { + if (list._id.toString() === action.data.list.toString()) { + return {...list, cards: [...list.cards, action.data]}; + } + + return list; + }); + return { + ...state, + data: newData + }; case Actions.SET_CHANGED_CARD: newData = state.data.map(list => { if (list._id.toString() === action.data.list.toString()) { From f0bee735d6c7877252a9ef5da977c16a23d0df8d Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Thu, 20 Jul 2017 14:57:35 -0400 Subject: [PATCH 084/112] improve styles and code formatting --- client/src/actions/lists.js | 9 ++++---- client/src/actions/specificBoard.js | 4 ++-- client/src/components/AuthLayer.js | 9 +++++--- client/src/components/Board.js | 6 ++--- client/src/components/Card.js | 19 +++++++-------- client/src/components/List.js | 32 ++++++++++++++++---------- client/src/containers/CardContainer.js | 9 +++++--- client/src/containers/ListContainer.js | 9 +++++--- client/src/reducers/allBoards.js | 9 +++----- client/src/reducers/lists.js | 21 ++++++++--------- 10 files changed, 69 insertions(+), 58 deletions(-) diff --git a/client/src/actions/lists.js b/client/src/actions/lists.js index 38472c80..68f817b4 100644 --- a/client/src/actions/lists.js +++ b/client/src/actions/lists.js @@ -47,14 +47,14 @@ export function deleteList(data) { return { type: DELETE_LIST, data - } + }; } export function modifyListFailure(data) { return { type: MODIFY_LIST_FAILURE, data - } + }; } export function addNewCard(data) { @@ -74,7 +74,7 @@ export function deleteCard(data) { return { type: DELETE_CARD, data - } + }; } export function getLists(token, boardId) { @@ -103,7 +103,6 @@ export function getLists(token, boardId) { }; } - export function editList(token, listId, form) { let config = { method: "PUT", @@ -266,4 +265,4 @@ export function createCard(token, listId) { dispatch(modifyListFailure(error)); }); }; -} \ No newline at end of file +} diff --git a/client/src/actions/specificBoard.js b/client/src/actions/specificBoard.js index 3eeaf5bf..d9973e15 100644 --- a/client/src/actions/specificBoard.js +++ b/client/src/actions/specificBoard.js @@ -76,7 +76,7 @@ export function editSpecificBoard(token, boardId, form, userId) { let changedBoard = { id: json.data._id, title: json.data.title - } + }; dispatch(getSpecificBoardSuccess(json.data)); dispatch(setChangedBoard(changedBoard)); }) @@ -112,7 +112,7 @@ export function createBoard(token, userId) { let newBoard = { id: json.data._id, title: json.data.title - } + }; dispatch(addNewBoard(newBoard)); }) .catch(error => { diff --git a/client/src/components/AuthLayer.js b/client/src/components/AuthLayer.js index 05342511..d2897866 100644 --- a/client/src/components/AuthLayer.js +++ b/client/src/components/AuthLayer.js @@ -16,14 +16,17 @@ const AuthLayer = ({ if (!isAuthenticated) { return ; } - + if (allBoards.length === 0) { return (

Djello

-

Uh oh, no boards could be found! Make your first one to get started!

+

+ Uh oh, no boards could be found! Make your first one to get + started! +

- ) + ); } return ( diff --git a/client/src/components/Board.js b/client/src/components/Board.js index af26f7c9..801af901 100644 --- a/client/src/components/Board.js +++ b/client/src/components/Board.js @@ -4,9 +4,9 @@ import EditableField from "./EditableField"; import ListContainer from "../containers/ListContainer"; const buildLists = (lists, token) => { - return lists.map(list => ( - - )); + return lists.map(list => + + ); }; const Board = ({ board, lists, token, onChangeBoardTitle, onCreateList }) => { diff --git a/client/src/components/Card.js b/client/src/components/Card.js index 67860f39..f2db3d90 100644 --- a/client/src/components/Card.js +++ b/client/src/components/Card.js @@ -1,23 +1,24 @@ import React from "react"; -import {Panel} from "react-bootstrap"; +import { Panel } from "react-bootstrap"; import EditableField from "./EditableField"; -const Card = ({card, onUpdateCard, onDeleteCard}) => { +const Card = ({ card, onUpdateCard, onDeleteCard }) => { return ( - {card.title} } > - -

{card.description}

-
- onDeleteCard(e, card._id)} className="card-delete">Delete This Card + +

{card.description}

+
+ onDeleteCard(e, card._id)} className="card-delete"> + Delete This Card +
); }; -export default Card; \ No newline at end of file +export default Card; diff --git a/client/src/components/List.js b/client/src/components/List.js index feff2c5e..896b4317 100644 --- a/client/src/components/List.js +++ b/client/src/components/List.js @@ -1,15 +1,15 @@ import React from "react"; -import {Panel, Col } from "react-bootstrap"; +import { Button, Panel, Col } from "react-bootstrap"; import EditableField from "./EditableField"; import CardContainer from "../containers/CardContainer"; const buildCards = (cards, token) => { - return cards.map(card => ( + return cards.map(card => - )); -} + ); +}; -const List = ({list, token, onDeleteList, onUpdateList, onCreateCard}) => { +const List = ({ list, token, onDeleteList, onUpdateList, onCreateCard }) => { let cardPanels; if (list.cards.length === 0) { cardPanels = null; @@ -18,26 +18,34 @@ const List = ({list, token, onDeleteList, onUpdateList, onCreateCard}) => { } return ( -

{list.title}

- } + } className="list-panel" - > + >

{list.description}

{cardPanels} - onCreateCard(e, list._id)} className="card-create">Create New Card +
- onDeleteList(e, list._id)} className="list-delete">Delete This List + onDeleteList(e, list._id)} className="list-delete"> + Delete This List + - ) + ); }; -export default List; \ No newline at end of file +export default List; diff --git a/client/src/containers/CardContainer.js b/client/src/containers/CardContainer.js index 36c1816f..85cd2b7d 100644 --- a/client/src/containers/CardContainer.js +++ b/client/src/containers/CardContainer.js @@ -18,9 +18,12 @@ const mapDispatchToProps = (dispatch, ownProps) => { dispatch(editCard(ownProps.token, ownProps.card._id, data)); }, onDeleteCard: (e, cardId) => { - if (window.confirm( - `Are you sure you want to delete the following card? \n \n ${ownProps.card.title}` - )) { + if ( + window.confirm( + `Are you sure you want to delete the following card? \n \n ${ownProps + .card.title}` + ) + ) { e.preventDefault(); dispatch(deleteSelectedCard(ownProps.token, cardId)); } diff --git a/client/src/containers/ListContainer.js b/client/src/containers/ListContainer.js index 24493d3e..104f41c3 100644 --- a/client/src/containers/ListContainer.js +++ b/client/src/containers/ListContainer.js @@ -19,9 +19,12 @@ const mapDispatchToProps = (dispatch, ownProps) => { dispatch(editList(ownProps.token, ownProps.list._id, data)); }, onDeleteList: (e, listId) => { - if (window.confirm( - `Are you sure you want to delete the following list? \n \n ${ownProps.list.title}` - )) { + if ( + window.confirm( + `Are you sure you want to delete the following list? \n \n ${ownProps + .list.title}` + ) + ) { e.preventDefault(); dispatch(deleteSelectedList(ownProps.token, listId)); } diff --git a/client/src/reducers/allBoards.js b/client/src/reducers/allBoards.js index 2e1941c3..2713c55c 100644 --- a/client/src/reducers/allBoards.js +++ b/client/src/reducers/allBoards.js @@ -2,7 +2,7 @@ import * as Actions from "../actions/allBoards"; const initialState = { data: [] -} +}; export const allBoards = (state = initialState, action) => { switch (action.type) { case Actions.GET_ALL_BOARDS_SUCCESS: @@ -26,15 +26,12 @@ export const allBoards = (state = initialState, action) => { case Actions.ADD_NEW_BOARD: return { ...state, - data: [ - ...state.data, - action.data - ] + data: [...state.data, action.data] }; case Actions.SET_CHANGED_BOARD: let newData = state.data.map(board => { if (board.id.toString() === action.data.id.toString()) { - return action.data + return action.data; } return board; }); diff --git a/client/src/reducers/lists.js b/client/src/reducers/lists.js index fbb4f00f..6604841c 100644 --- a/client/src/reducers/lists.js +++ b/client/src/reducers/lists.js @@ -2,7 +2,7 @@ import * as Actions from "../actions/lists"; const initialState = { data: [] -} +}; export const lists = (state = initialState, action) => { let newData; switch (action.type) { @@ -27,15 +27,12 @@ export const lists = (state = initialState, action) => { case Actions.ADD_NEW_LIST: return { ...state, - data: [ - ...state.data, - action.data - ] + data: [...state.data, action.data] }; case Actions.SET_CHANGED_LIST: newData = state.data.map(list => { if (list._id.toString() === action.data._id.toString()) { - return action.data + return action.data; } return list; }); @@ -56,11 +53,11 @@ export const lists = (state = initialState, action) => { return { ...state, error: action.data - } + }; case Actions.ADD_NEW_CARD: newData = state.data.map(list => { if (list._id.toString() === action.data.list.toString()) { - return {...list, cards: [...list.cards, action.data]}; + return { ...list, cards: [...list.cards, action.data] }; } return list; @@ -76,11 +73,11 @@ export const lists = (state = initialState, action) => { if (card._id.toString() === action.data._id.toString()) { return action.data; } - + return card; }); - return {...list, cards: updatedCards} + return { ...list, cards: updatedCards }; } return list; @@ -96,9 +93,9 @@ export const lists = (state = initialState, action) => { return card._id.toString() !== action.data._id.toString(); }); - return {...list, cards: updatedCards}; + return { ...list, cards: updatedCards }; } - + return list; }); From 7527d319c4934127df1d51cbdb563406d7dbd016 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Thu, 20 Jul 2017 15:15:59 -0400 Subject: [PATCH 085/112] add list styles --- client/src/components/List.js | 30 ++++++++++++++++++------------ client/src/index.css | 6 ++++++ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/client/src/components/List.js b/client/src/components/List.js index 896b4317..43bbeb0f 100644 --- a/client/src/components/List.js +++ b/client/src/components/List.js @@ -1,5 +1,5 @@ import React from "react"; -import { Button, Panel, Col } from "react-bootstrap"; +import { Button, Panel, Col, ListGroup, ListGroupItem } from "react-bootstrap"; import EditableField from "./EditableField"; import CardContainer from "../containers/CardContainer"; @@ -27,19 +27,25 @@ const List = ({ list, token, onDeleteList, onUpdateList, onCreateCard }) => { } className="list-panel" > - -

{list.description}

-
+ + + +

{list.description}

+
+
+ + {cardPanels} + + +
- {cardPanels} -
onDeleteList(e, list._id)} className="list-delete"> Delete This List diff --git a/client/src/index.css b/client/src/index.css index b5fb893c..941d2a5c 100644 --- a/client/src/index.css +++ b/client/src/index.css @@ -29,10 +29,16 @@ a { .list-panel { margin-bottom: 2px; } + .list-delete { margin-bottom: 2em; } +.list-description { + text-align: center; + font-size: 1.2em; +} + .add-list-link { margin-bottom: 2em; } \ No newline at end of file From bee04b645a8b495f27fbf3ca838f02ba93e53a12 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Thu, 20 Jul 2017 15:25:35 -0400 Subject: [PATCH 086/112] fix new board creation --- client/src/actions/specificBoard.js | 1 + client/src/components/Board.js | 2 +- client/src/components/List.js | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/client/src/actions/specificBoard.js b/client/src/actions/specificBoard.js index d9973e15..671236a8 100644 --- a/client/src/actions/specificBoard.js +++ b/client/src/actions/specificBoard.js @@ -109,6 +109,7 @@ export function createBoard(token, userId) { }) .then(json => { dispatch(getSpecificBoardSuccess(json.data)); + dispatch(getListsSuccess(json.data.lists)); let newBoard = { id: json.data._id, title: json.data.title diff --git a/client/src/components/Board.js b/client/src/components/Board.js index 801af901..8ae24325 100644 --- a/client/src/components/Board.js +++ b/client/src/components/Board.js @@ -12,7 +12,7 @@ const buildLists = (lists, token) => { const Board = ({ board, lists, token, onChangeBoardTitle, onCreateList }) => { let listPanels; if (lists.length === 0) { - listPanels = null; + listPanels =

No Lists found! Create a new list to get started.

; } else { listPanels = buildLists(lists, token); } diff --git a/client/src/components/List.js b/client/src/components/List.js index 43bbeb0f..f09a3911 100644 --- a/client/src/components/List.js +++ b/client/src/components/List.js @@ -12,7 +12,7 @@ const buildCards = (cards, token) => { const List = ({ list, token, onDeleteList, onUpdateList, onCreateCard }) => { let cardPanels; if (list.cards.length === 0) { - cardPanels = null; + cardPanels =

No Cards found! Create a new card to get started.

; } else { cardPanels = buildCards(list.cards, token); } From 8cf0998760dcd1873276990d8ab984b69a746737 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Thu, 20 Jul 2017 22:11:03 -0400 Subject: [PATCH 087/112] add card modal component --- client/src/components/Card.js | 2 ++ client/src/components/CardModal.js | 56 ++++++++++++++++++++++++++++++ client/src/components/List.js | 2 +- 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 client/src/components/CardModal.js diff --git a/client/src/components/Card.js b/client/src/components/Card.js index f2db3d90..b496fa78 100644 --- a/client/src/components/Card.js +++ b/client/src/components/Card.js @@ -1,6 +1,7 @@ import React from "react"; import { Panel } from "react-bootstrap"; import EditableField from "./EditableField"; +import CardModal from "./CardModal"; const Card = ({ card, onUpdateCard, onDeleteCard }) => { return ( @@ -14,6 +15,7 @@ const Card = ({ card, onUpdateCard, onDeleteCard }) => {

{card.description}

+
onDeleteCard(e, card._id)} className="card-delete"> Delete This Card diff --git a/client/src/components/CardModal.js b/client/src/components/CardModal.js new file mode 100644 index 00000000..0f20f23a --- /dev/null +++ b/client/src/components/CardModal.js @@ -0,0 +1,56 @@ +import React, { Component } from 'react'; +import { Button, Modal } from 'react-bootstrap'; + +class CardModal extends Component { + constructor() { + super() + this.state = { + showModal: false + } + } + // getInitialState() { + // return { showModal: false }; + // } + + close = () => { + this.setState({ showModal: false }); + } + + open = () => { + this.setState({ showModal: true }); + } + + render() { + const { card } = this.props; + console.log(card); + return ( +
+ + + + + {card.title} + + +

Description

+

{card.description}

+
+

Members

+
+

Activity Feed

+
+ + + +
+
+ ); + } +} + +export default CardModal; \ No newline at end of file diff --git a/client/src/components/List.js b/client/src/components/List.js index f09a3911..fadb16b9 100644 --- a/client/src/components/List.js +++ b/client/src/components/List.js @@ -12,7 +12,7 @@ const buildCards = (cards, token) => { const List = ({ list, token, onDeleteList, onUpdateList, onCreateCard }) => { let cardPanels; if (list.cards.length === 0) { - cardPanels =

No Cards found! Create a new card to get started.

; + cardPanels =

No cards found.

; } else { cardPanels = buildCards(list.cards, token); } From d1012057396b9a4b9f547097e48388337f5235c4 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Fri, 21 Jul 2017 11:47:57 -0400 Subject: [PATCH 088/112] add current card actions and reducers --- client/src/actions/currentCard.js | 86 +++++++++++++++++++++ client/src/components/Card.js | 6 +- client/src/components/CardModal.js | 7 +- client/src/containers/CardContainer.js | 3 +- client/src/containers/CardModalContainer.js | 24 ++++++ client/src/index.css | 5 ++ client/src/reducers/currentCard.js | 32 ++++++++ client/src/reducers/index.js | 4 +- server/routes/api/cards.js | 47 +++++++++++ server/spec/card_spec.js | 27 +++++++ 10 files changed, 231 insertions(+), 10 deletions(-) create mode 100644 client/src/actions/currentCard.js create mode 100644 client/src/containers/CardModalContainer.js create mode 100644 client/src/reducers/currentCard.js diff --git a/client/src/actions/currentCard.js b/client/src/actions/currentCard.js new file mode 100644 index 00000000..f0ac17df --- /dev/null +++ b/client/src/actions/currentCard.js @@ -0,0 +1,86 @@ +// import { getAllBoardsInit, addNewBoard, setChangedBoard } from "./allBoards"; +// import { getListsSuccess } from "./lists"; +export const GET_CURRENT_CARD_REQUEST = "GET_CURRENT_CARD_REQUEST"; +export const GET_CURRENT_CARD_SUCCESS = "GET_CURRENT_CARD_SUCCESS"; +export const GET_CURRENT_CARD_FAILURE = "GET_CURRENT_CARD_FAILURE"; + +export function getCurrentCardRequest() { + return { + type: GET_CURRENT_CARD_REQUEST + }; +} + +export function getCurrentCardSuccess(data) { + return { + type: GET_CURRENT_CARD_SUCCESS, + data + }; +} + +export function getCurrentCardFailure(error) { + return { + type: GET_CURRENT_CARD_FAILURE, + error + }; +} + +export function getCurrentCard(token, cardId) { + let config = { + method: "GET", + headers: { Authorization: "Bearer " + token } + }; + + return dispatch => { + dispatch(getCurrentCardRequest()); + + fetch(`api/v1/cards/${cardId}`, config) + .then(response => { + if (!response.ok) { + throw new Error(`${response.status}: ${response.statusText}`); + } + + return response.json(); + }) + .then(json => { + dispatch(getCurrentCardSuccess(json.data)); + }) + .catch(error => { + dispatch(getCurrentCardFailure(error)); + }); + }; +} + +// export function editCurrentCard(token, boardId, form, userId) { +// let config = { +// method: "PUT", +// headers: { +// Authorization: "Bearer " + token, +// "Content-Type": "application/x-www-form-urlencoded" +// }, +// body: form +// }; + +// return dispatch => { +// dispatch(getCurrentCardRequest()); + +// fetch(`api/v1/boards/${boardId}`, config) +// .then(response => { +// if (!response.ok) { +// throw new Error(`${response.status}: ${response.statusText}`); +// } + +// return response.json(); +// }) +// .then(json => { +// let changedBoard = { +// id: json.data._id, +// title: json.data.title +// }; +// dispatch(getCurrentCardSuccess(json.data)); +// dispatch(setChangedBoard(changedBoard)); +// }) +// .catch(error => { +// dispatch(getCurrentCardFailure(error)); +// }); +// }; +// } \ No newline at end of file diff --git a/client/src/components/Card.js b/client/src/components/Card.js index b496fa78..34115e75 100644 --- a/client/src/components/Card.js +++ b/client/src/components/Card.js @@ -1,9 +1,9 @@ import React from "react"; import { Panel } from "react-bootstrap"; import EditableField from "./EditableField"; -import CardModal from "./CardModal"; +import CardModalContainer from "../containers/CardModalContainer"; -const Card = ({ card, onUpdateCard, onDeleteCard }) => { +const Card = ({ card, token, onUpdateCard, onDeleteCard }) => { return ( {

{card.description}

- + onDeleteCard(e, card._id)} className="card-delete"> Delete This Card diff --git a/client/src/components/CardModal.js b/client/src/components/CardModal.js index 0f20f23a..d0006d8b 100644 --- a/client/src/components/CardModal.js +++ b/client/src/components/CardModal.js @@ -8,21 +8,18 @@ class CardModal extends Component { showModal: false } } - // getInitialState() { - // return { showModal: false }; - // } close = () => { this.setState({ showModal: false }); } - open = () => { + open = (e) => { + this.props.onGetCard(this.props.card._id); this.setState({ showModal: true }); } render() { const { card } = this.props; - console.log(card); return (
+
diff --git a/client/src/containers/BoardContainer.js b/client/src/containers/BoardContainer.js index 632b8b6b..8db54fa4 100644 --- a/client/src/containers/BoardContainer.js +++ b/client/src/containers/BoardContainer.js @@ -8,7 +8,8 @@ const mapStateToProps = (state, ownProps) => { return { board: state.specificBoard.data, lists: state.lists.data, - token: ownProps.token + token: ownProps.token, + isFetching: state.specificBoard.isFetching }; }; diff --git a/client/src/reducers/currentCard.js b/client/src/reducers/currentCard.js index fe73b311..b6d16037 100644 --- a/client/src/reducers/currentCard.js +++ b/client/src/reducers/currentCard.js @@ -1,7 +1,9 @@ import * as Actions from "../actions/currentCard"; const initialState = { - data: { }, + data: { + members: [] + }, isFetching: false, error: null }; From 4d4f01107e46863e0bf5aa02ac5e4fe56b6b7002 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Fri, 21 Jul 2017 12:03:17 -0400 Subject: [PATCH 090/112] add activity feed --- client/src/components/CardModal.js | 13 ++++++++++--- client/src/reducers/currentCard.js | 3 ++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/client/src/components/CardModal.js b/client/src/components/CardModal.js index 1a3bf635..05802efa 100644 --- a/client/src/components/CardModal.js +++ b/client/src/components/CardModal.js @@ -1,9 +1,15 @@ import React, { Component } from 'react'; import { Table, Button, Modal } from 'react-bootstrap'; +const buildActivityFeed = activities => { + return activities.map(activity => ( +

{activity.description}

+ )); +} + const buildMemberTable = members => { let memberCells = members.map(member => ( - + {member.email} Remove @@ -43,8 +49,8 @@ class CardModal extends Component { render() { const { currentCard } = this.props; - let memberTable; - memberTable = buildMemberTable(currentCard.members); + let memberTable = buildMemberTable(currentCard.members); + let activitiesFeed = buildActivityFeed(currentCard.activities); return (
@@ -67,6 +73,7 @@ class CardModal extends Component { {memberTable}

Activity Feed

+ {activitiesFeed} diff --git a/client/src/reducers/currentCard.js b/client/src/reducers/currentCard.js index b6d16037..3576525f 100644 --- a/client/src/reducers/currentCard.js +++ b/client/src/reducers/currentCard.js @@ -2,7 +2,8 @@ import * as Actions from "../actions/currentCard"; const initialState = { data: { - members: [] + members: [], + activities: [], }, isFetching: false, error: null From 512757a0aca7a7fec11fcad7403dfd872ddc90a4 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Fri, 21 Jul 2017 12:12:40 -0400 Subject: [PATCH 091/112] add date time to activities --- client/src/components/CardModal.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/client/src/components/CardModal.js b/client/src/components/CardModal.js index 05802efa..66301545 100644 --- a/client/src/components/CardModal.js +++ b/client/src/components/CardModal.js @@ -2,9 +2,11 @@ import React, { Component } from 'react'; import { Table, Button, Modal } from 'react-bootstrap'; const buildActivityFeed = activities => { - return activities.map(activity => ( -

{activity.description}

- )); + return activities.map(activity => { + return ( +

{activity.description} Date: {new Date(activity.createdAt).toLocaleString()}

+ ) + }); } const buildMemberTable = members => { From 89393527c111ddc22c87f0dfcb072ffa38a7f84c Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Fri, 21 Jul 2017 12:18:34 -0400 Subject: [PATCH 092/112] add editing to card modal title --- client/src/components/Card.js | 4 ++-- client/src/components/CardModal.js | 7 ++++++- client/src/containers/CardContainer.js | 1 + client/src/containers/CardModalContainer.js | 12 ++++++++++-- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/client/src/components/Card.js b/client/src/components/Card.js index 34115e75..7408ce9e 100644 --- a/client/src/components/Card.js +++ b/client/src/components/Card.js @@ -3,7 +3,7 @@ import { Panel } from "react-bootstrap"; import EditableField from "./EditableField"; import CardModalContainer from "../containers/CardModalContainer"; -const Card = ({ card, token, onUpdateCard, onDeleteCard }) => { +const Card = ({ card, currentCard, token, onUpdateCard, onDeleteCard }) => { return ( {

{card.description}

- + onDeleteCard(e, card._id)} className="card-delete"> Delete This Card diff --git a/client/src/components/CardModal.js b/client/src/components/CardModal.js index 66301545..fdc22262 100644 --- a/client/src/components/CardModal.js +++ b/client/src/components/CardModal.js @@ -1,5 +1,6 @@ import React, { Component } from 'react'; import { Table, Button, Modal } from 'react-bootstrap'; +import EditableField from "./EditableField"; const buildActivityFeed = activities => { return activities.map(activity => { @@ -65,7 +66,11 @@ class CardModal extends Component { - {currentCard.title} + + + {currentCard.title} + +

Description

diff --git a/client/src/containers/CardContainer.js b/client/src/containers/CardContainer.js index 991f8c51..06d1d9b6 100644 --- a/client/src/containers/CardContainer.js +++ b/client/src/containers/CardContainer.js @@ -6,6 +6,7 @@ import { editCard, deleteSelectedCard } from "../actions/lists"; const mapStateToProps = (state, ownProps) => { return { card: ownProps.card, + currentCard: state.currentCard.data, token: state.user.token }; }; diff --git a/client/src/containers/CardModalContainer.js b/client/src/containers/CardModalContainer.js index a4ac3ddf..734a7a0b 100644 --- a/client/src/containers/CardModalContainer.js +++ b/client/src/containers/CardModalContainer.js @@ -1,7 +1,9 @@ import { connect } from "react-redux"; import CardModal from "../components/CardModal"; -// import serialize from "form-serialize"; +import serialize from "form-serialize"; import { getCurrentCard } from "../actions/currentCard"; +import { editCard } from "../actions/lists"; + const mapStateToProps = (state, ownProps) => { return { @@ -15,7 +17,13 @@ const mapDispatchToProps = (dispatch, ownProps) => { return { onGetCard: cardId => { dispatch(getCurrentCard(ownProps.token, cardId)); - } + }, + onUpdateCard: e => { + e.preventDefault(); + const form = e.target; + const data = serialize(form); + dispatch(editCard(ownProps.token, ownProps.currentCard._id, data)); + }, }; }; From f327fda82a83655f036039eec96993b5917b4357 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Fri, 21 Jul 2017 12:32:12 -0400 Subject: [PATCH 093/112] add populating to card put routes --- client/src/actions/lists.js | 6 +++++- client/src/containers/CardModalContainer.js | 2 +- server/routes/api/cards.js | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/client/src/actions/lists.js b/client/src/actions/lists.js index 68f817b4..3c26dc09 100644 --- a/client/src/actions/lists.js +++ b/client/src/actions/lists.js @@ -1,3 +1,4 @@ +import { getCurrentCardSuccess } from "./currentCard"; export const GET_LISTS_REQUEST = "GET_LISTS_REQUEST"; export const GET_LISTS_SUCCESS = "GET_LISTS_SUCCESS"; export const GET_LISTS_FAILURE = "GET_LISTS_FAILURE"; @@ -187,7 +188,7 @@ export function deleteSelectedList(token, listId) { /* =============== Nested Card Actions ================ */ -export function editCard(token, cardId, form) { +export function editCard(token, cardId, form, currentCard = false) { let config = { method: "PUT", headers: { @@ -208,6 +209,9 @@ export function editCard(token, cardId, form) { }) .then(json => { dispatch(setChangedCard(json.data)); + if (currentCard) { + dispatch(getCurrentCardSuccess(json.data)); + } }) .catch(error => { dispatch(modifyListFailure(error)); diff --git a/client/src/containers/CardModalContainer.js b/client/src/containers/CardModalContainer.js index 734a7a0b..860dfb4a 100644 --- a/client/src/containers/CardModalContainer.js +++ b/client/src/containers/CardModalContainer.js @@ -22,7 +22,7 @@ const mapDispatchToProps = (dispatch, ownProps) => { e.preventDefault(); const form = e.target; const data = serialize(form); - dispatch(editCard(ownProps.token, ownProps.currentCard._id, data)); + dispatch(editCard(ownProps.token, ownProps.currentCard._id, data, ownProps.currentCard)); }, }; }; diff --git a/server/routes/api/cards.js b/server/routes/api/cards.js index f5facc03..7ea4e656 100644 --- a/server/routes/api/cards.js +++ b/server/routes/api/cards.js @@ -98,7 +98,7 @@ Card.findById(cardId) $push: { activities: activity.id } }, { new: true } - ); + ).populate(['activities', 'members']); }) .then(result => { res.json({ From 6c95ec3b9be19d8e24ec8abbd1ada4b2a4cd77e5 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Fri, 21 Jul 2017 12:39:09 -0400 Subject: [PATCH 094/112] add all users actions and reducers --- client/src/actions/allUsers.js | 55 +++++++++++++++++++ client/src/components/CardModal.js | 4 +- client/src/containers/BoardPickerContainer.js | 5 ++ client/src/reducers/allUsers.js | 30 ++++++++++ client/src/reducers/index.js | 6 +- 5 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 client/src/actions/allUsers.js create mode 100644 client/src/reducers/allUsers.js diff --git a/client/src/actions/allUsers.js b/client/src/actions/allUsers.js new file mode 100644 index 00000000..f6c0cc36 --- /dev/null +++ b/client/src/actions/allUsers.js @@ -0,0 +1,55 @@ +export const GET_ALL_USERS_REQUEST = "GET_ALL_USERS_REQUEST"; +export const GET_ALL_USERS_SUCCESS = "GET_ALL_USERS_SUCCESS"; +export const GET_ALL_USERS_FAILURE = "GET_ALL_USERS_FAILURE"; + +export function getAllUsersRequest() { + return { + type: GET_ALL_USERS_REQUEST + }; +} + +export function getAllUsersSuccess(data) { + return { + type: GET_ALL_USERS_SUCCESS, + data + }; +} + +export function getAllUsersFailure(error) { + return { + type: GET_ALL_USERS_FAILURE, + error + }; +} + +export function getAllUsers(token) { + let config = { + method: "GET", + headers: { Authorization: "Bearer " + token } + }; + + return dispatch => { + dispatch(getAllUsersRequest()); + + fetch(`api/v1/users`, config) + .then(response => { + if (!response.ok) { + throw new Error(`${response.status}: ${response.statusText}`); + } + + return response.json(); + }) + .then(json => { + let users = json.data.map(user => { + return { + id: user._id, + email: user.email + }; + }); + dispatch(getAllUsersSuccess(users)); + }) + .catch(error => { + dispatch(getAllUsersFailure(error)); + }); + }; +} diff --git a/client/src/components/CardModal.js b/client/src/components/CardModal.js index fdc22262..73d45311 100644 --- a/client/src/components/CardModal.js +++ b/client/src/components/CardModal.js @@ -74,7 +74,9 @@ class CardModal extends Component {

Description

-

{currentCard.description}

+ +

{currentCard.description}

+

Members

{memberTable} diff --git a/client/src/containers/BoardPickerContainer.js b/client/src/containers/BoardPickerContainer.js index 0830a4d6..3d30e6f5 100644 --- a/client/src/containers/BoardPickerContainer.js +++ b/client/src/containers/BoardPickerContainer.js @@ -2,6 +2,7 @@ import React, { Component } from "react"; import { connect } from "react-redux"; import BoardPicker from "../components/BoardPicker"; import { getAllBoardsInit } from "../actions/allBoards"; +import { getAllUsers } from "../actions/allUsers"; import { getSpecificBoard, createBoard, @@ -11,6 +12,7 @@ import { class BoardPickerContainer extends Component { componentDidMount() { this.props.getAllBoardsInit(this.props.token, this.props.userId); + this.props.getAllUsers(this.props.token); } render() { @@ -29,6 +31,9 @@ const mapStateToProps = state => { const mapDispatchToProps = (dispatch, ownProps) => { return { + getAllUsers: token => { + dispatch(getAllUsers(token)); + }, getAllBoardsInit: (token, userId) => { dispatch(getAllBoardsInit(token, userId)); }, diff --git a/client/src/reducers/allUsers.js b/client/src/reducers/allUsers.js new file mode 100644 index 00000000..0a716e1a --- /dev/null +++ b/client/src/reducers/allUsers.js @@ -0,0 +1,30 @@ +import * as Actions from "../actions/allUsers"; + +const initialState = { + data: [] +}; + +export const allUsers = (state = initialState, action) => { + switch (action.type) { + case Actions.GET_ALL_USERS_SUCCESS: + return { + ...state, + data: action.data, + isFetching: false + }; + case Actions.GET_ALL_USERS_REQUEST: + return { + ...state, + isFetching: true, + error: null + }; + case Actions.GET_ALL_USERS_FAILURE: + return { + ...state, + isFetching: false, + error: true + }; + default: + return state; + } +}; diff --git a/client/src/reducers/index.js b/client/src/reducers/index.js index 9c39c9e2..e8a49228 100644 --- a/client/src/reducers/index.js +++ b/client/src/reducers/index.js @@ -1,14 +1,16 @@ import { combineReducers } from "redux"; import { user } from "./auth"; -import { allBoards } from "./allBoards"; +import { allUsers } from "./allUsers"; import { specificBoard } from "./specificBoard"; +import { allBoards } from "./allBoards"; import { lists } from "./lists"; import { currentCard } from "./currentCard"; const djelloApp = combineReducers({ user, - allBoards, + allUsers, specificBoard, + allBoards, lists, currentCard }); From 40da145ebdf02cb5de55070b3145a7286cf2e130 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Fri, 21 Jul 2017 12:59:43 -0400 Subject: [PATCH 095/112] create add member to current card action --- client/src/actions/currentCard.js | 26 ++++++++++++++++++++++++++ server/routes/api/cards.js | 8 ++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/client/src/actions/currentCard.js b/client/src/actions/currentCard.js index f0ac17df..4a93d72f 100644 --- a/client/src/actions/currentCard.js +++ b/client/src/actions/currentCard.js @@ -50,6 +50,32 @@ export function getCurrentCard(token, cardId) { }; } +export function addMemberToCurrentCard(token, cardId, newMemberId) { + let config = { + method: "POST", + headers: { Authorization: "Bearer " + token } + }; + + return dispatch => { + dispatch(getCurrentCardRequest()); + + fetch(`api/v1/cards/${cardId}/users/${newMemberId}`, config) + .then(response => { + if (!response.ok) { + throw new Error(`${response.status}: ${response.statusText}`); + } + + return response.json(); + }) + .then(json => { + dispatch(getCurrentCardSuccess(json.data)); + }) + .catch(error => { + dispatch(getCurrentCardFailure(error)); + }); + }; +} + // export function editCurrentCard(token, boardId, form, userId) { // let config = { // method: "PUT", diff --git a/server/routes/api/cards.js b/server/routes/api/cards.js index 7ea4e656..a520f3bd 100644 --- a/server/routes/api/cards.js +++ b/server/routes/api/cards.js @@ -145,7 +145,7 @@ Card.findById(cardId) $addToSet: { members: userToAdd } }, { new: true } - ); + ).populate(['activities', 'members']); }) .then(result => { updatedCard = result; @@ -160,7 +160,7 @@ Card.findById(cardId) }) .then(result => { res.json({ - message: apiMessages.successfulPut, + message: apiMessages.successfulPost, data: updatedCard }); }) @@ -203,11 +203,11 @@ router.delete("/:id/users/:userId", (req, res, next) => { $pull: { members: userToRemove } }, { new: true } - ); + ).populate(['activities', 'members']); }) .then(result => { res.json({ - message: apiMessages.successfulPut, + message: apiMessages.successfulDelete, data: result }); }) From 97f2d07ea1b8658bf996c5642b49587360d74d05 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Fri, 21 Jul 2017 14:16:24 -0400 Subject: [PATCH 096/112] implement adding members to card --- client/src/components/CardModal.js | 40 +++++++++++++++++++-- client/src/containers/CardModalContainer.js | 12 +++++-- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/client/src/components/CardModal.js b/client/src/components/CardModal.js index 73d45311..50975141 100644 --- a/client/src/components/CardModal.js +++ b/client/src/components/CardModal.js @@ -1,7 +1,27 @@ import React, { Component } from 'react'; -import { Table, Button, Modal } from 'react-bootstrap'; +import { FormGroup, ControlLabel, FormControl, Table, Button, Modal } from 'react-bootstrap'; import EditableField from "./EditableField"; +const buildAddUserOptions = (cardMembers, allUsers) => { + let options = []; + + allUsers.forEach(user => { + let shouldAdd = true; + cardMembers.forEach(cardMember => { + if (cardMember._id === user.id) { + shouldAdd = false; + } + }); + + if (shouldAdd) { + options.push(user); + } + }); + return options.map(user => ( + + )); +}; + const buildActivityFeed = activities => { return activities.map(activity => { return ( @@ -51,9 +71,10 @@ class CardModal extends Component { } render() { - const { currentCard } = this.props; + const { currentCard, allUsers, onUserAdd } = this.props; let memberTable = buildMemberTable(currentCard.members); let activitiesFeed = buildActivityFeed(currentCard.activities); + let addUserOptions = buildAddUserOptions(currentCard.members, allUsers); return (
@@ -80,6 +101,21 @@ class CardModal extends Component {

Members

{memberTable} +
+ + Add a member: + + {addUserOptions} + + +
+ + +
+

Activity Feed

{activitiesFeed} diff --git a/client/src/containers/CardModalContainer.js b/client/src/containers/CardModalContainer.js index 860dfb4a..d696c6a6 100644 --- a/client/src/containers/CardModalContainer.js +++ b/client/src/containers/CardModalContainer.js @@ -1,7 +1,7 @@ import { connect } from "react-redux"; import CardModal from "../components/CardModal"; import serialize from "form-serialize"; -import { getCurrentCard } from "../actions/currentCard"; +import { getCurrentCard, addMemberToCurrentCard } from "../actions/currentCard"; import { editCard } from "../actions/lists"; @@ -9,7 +9,8 @@ const mapStateToProps = (state, ownProps) => { return { currentCard: state.currentCard.data, card: ownProps.card, - isFetching: state.currentCard.isFetching + isFetching: state.currentCard.isFetching, + allUsers: state.allUsers.data }; }; @@ -24,6 +25,13 @@ const mapDispatchToProps = (dispatch, ownProps) => { const data = serialize(form); dispatch(editCard(ownProps.token, ownProps.currentCard._id, data, ownProps.currentCard)); }, + onUserAdd: e => { + e.preventDefault(); + const form = e.target; + const newMember = serialize(form, {hash: true}).newMember; + console.log(newMember); + dispatch(addMemberToCurrentCard(ownProps.token, ownProps.currentCard._id, newMember)); + } }; }; From 41b6bfc154c98cdd4e60cd91137a415216e078b8 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Fri, 21 Jul 2017 14:21:29 -0400 Subject: [PATCH 097/112] implement removing members from card --- client/src/actions/currentCard.js | 26 +++++++++++++++++++++ client/src/components/CardModal.js | 12 ++++++---- client/src/containers/CardModalContainer.js | 10 ++++---- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/client/src/actions/currentCard.js b/client/src/actions/currentCard.js index 4a93d72f..906f731c 100644 --- a/client/src/actions/currentCard.js +++ b/client/src/actions/currentCard.js @@ -76,6 +76,32 @@ export function addMemberToCurrentCard(token, cardId, newMemberId) { }; } +export function removeMemberFromCurrentCard(token, cardId, memberId) { + let config = { + method: "DELETE", + headers: { Authorization: "Bearer " + token } + }; + + return dispatch => { + dispatch(getCurrentCardRequest()); + + fetch(`api/v1/cards/${cardId}/users/${memberId}`, config) + .then(response => { + if (!response.ok) { + throw new Error(`${response.status}: ${response.statusText}`); + } + + return response.json(); + }) + .then(json => { + dispatch(getCurrentCardSuccess(json.data)); + }) + .catch(error => { + dispatch(getCurrentCardFailure(error)); + }); + }; +} + // export function editCurrentCard(token, boardId, form, userId) { // let config = { // method: "PUT", diff --git a/client/src/components/CardModal.js b/client/src/components/CardModal.js index 50975141..88eb576d 100644 --- a/client/src/components/CardModal.js +++ b/client/src/components/CardModal.js @@ -30,11 +30,15 @@ const buildActivityFeed = activities => { }); } -const buildMemberTable = members => { +const buildMemberTable = (members, onUserRemove) => { let memberCells = members.map(member => ( {member.email} - Remove + + + )) @@ -71,8 +75,8 @@ class CardModal extends Component { } render() { - const { currentCard, allUsers, onUserAdd } = this.props; - let memberTable = buildMemberTable(currentCard.members); + const { currentCard, allUsers, onUserAdd, onUserRemove } = this.props; + let memberTable = buildMemberTable(currentCard.members, onUserRemove); let activitiesFeed = buildActivityFeed(currentCard.activities); let addUserOptions = buildAddUserOptions(currentCard.members, allUsers); diff --git a/client/src/containers/CardModalContainer.js b/client/src/containers/CardModalContainer.js index d696c6a6..6be4b7c8 100644 --- a/client/src/containers/CardModalContainer.js +++ b/client/src/containers/CardModalContainer.js @@ -1,10 +1,9 @@ import { connect } from "react-redux"; import CardModal from "../components/CardModal"; import serialize from "form-serialize"; -import { getCurrentCard, addMemberToCurrentCard } from "../actions/currentCard"; +import { getCurrentCard, addMemberToCurrentCard, removeMemberFromCurrentCard } from "../actions/currentCard"; import { editCard } from "../actions/lists"; - const mapStateToProps = (state, ownProps) => { return { currentCard: state.currentCard.data, @@ -29,12 +28,15 @@ const mapDispatchToProps = (dispatch, ownProps) => { e.preventDefault(); const form = e.target; const newMember = serialize(form, {hash: true}).newMember; - console.log(newMember); dispatch(addMemberToCurrentCard(ownProps.token, ownProps.currentCard._id, newMember)); + }, + onUserRemove: (e, memberId) => { + e.preventDefault(); + dispatch(removeMemberFromCurrentCard(ownProps.token, ownProps.currentCard._id, memberId)); } }; }; const CardModalContainer = connect(mapStateToProps, mapDispatchToProps)(CardModal); -export default CardModalContainer; +export default CardModalContainer; \ No newline at end of file From 395d652f1cf31aa0471ad1161fd8b300dfd3f0ac Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Fri, 21 Jul 2017 14:47:37 -0400 Subject: [PATCH 098/112] implement showing members on board --- client/src/actions/currentCard.js | 37 +--------------------------- client/src/components/BoardPicker.js | 1 - client/src/components/Card.js | 21 ++++++++++++---- server/routes/api/boards.js | 7 ++++-- server/routes/api/lists.js | 15 ++++++++--- server/routes/api/users.js | 2 +- 6 files changed, 34 insertions(+), 49 deletions(-) diff --git a/client/src/actions/currentCard.js b/client/src/actions/currentCard.js index 906f731c..c51ff97b 100644 --- a/client/src/actions/currentCard.js +++ b/client/src/actions/currentCard.js @@ -100,39 +100,4 @@ export function removeMemberFromCurrentCard(token, cardId, memberId) { dispatch(getCurrentCardFailure(error)); }); }; -} - -// export function editCurrentCard(token, boardId, form, userId) { -// let config = { -// method: "PUT", -// headers: { -// Authorization: "Bearer " + token, -// "Content-Type": "application/x-www-form-urlencoded" -// }, -// body: form -// }; - -// return dispatch => { -// dispatch(getCurrentCardRequest()); - -// fetch(`api/v1/boards/${boardId}`, config) -// .then(response => { -// if (!response.ok) { -// throw new Error(`${response.status}: ${response.statusText}`); -// } - -// return response.json(); -// }) -// .then(json => { -// let changedBoard = { -// id: json.data._id, -// title: json.data.title -// }; -// dispatch(getCurrentCardSuccess(json.data)); -// dispatch(setChangedBoard(changedBoard)); -// }) -// .catch(error => { -// dispatch(getCurrentCardFailure(error)); -// }); -// }; -// } \ No newline at end of file +} \ No newline at end of file diff --git a/client/src/components/BoardPicker.js b/client/src/components/BoardPicker.js index 4d9287db..08ff29f3 100644 --- a/client/src/components/BoardPicker.js +++ b/client/src/components/BoardPicker.js @@ -21,7 +21,6 @@ const BoardPicker = ({ {boardOptions} diff --git a/client/src/components/Card.js b/client/src/components/Card.js index 7408ce9e..f61b4853 100644 --- a/client/src/components/Card.js +++ b/client/src/components/Card.js @@ -1,9 +1,12 @@ import React from "react"; -import { Panel } from "react-bootstrap"; +import { Panel, Row, Col } from "react-bootstrap"; import EditableField from "./EditableField"; import CardModalContainer from "../containers/CardModalContainer"; const Card = ({ card, currentCard, token, onUpdateCard, onDeleteCard }) => { + let members = card.members.map(member => ( +

{member.email}

+ )); return ( {

{card.description}

- - onDeleteCard(e, card._id)} className="card-delete"> - Delete This Card - + + + + onDeleteCard(e, card._id)} className="card-delete"> + Delete This Card + + + + Current Members: + {members} + +
); }; diff --git a/server/routes/api/boards.js b/server/routes/api/boards.js index fc0d36af..4ef43737 100644 --- a/server/routes/api/boards.js +++ b/server/routes/api/boards.js @@ -17,7 +17,7 @@ router.get("/:id", (req, res, next) => { populate: { path: "cards", populate: { - path: "activities" + path: "members" } } }) @@ -227,7 +227,10 @@ router.get("/:id/lists", (req, res, next) => { .populate({ path: "lists", populate: { - path: "cards" + path: "cards", + populate: { + path: "members" + } } }) .then(board => { diff --git a/server/routes/api/lists.js b/server/routes/api/lists.js index 7a234fa4..eca73297 100644 --- a/server/routes/api/lists.js +++ b/server/routes/api/lists.js @@ -36,7 +36,13 @@ router.put("/:id", (req, res, next) => { description: description || list.description }, { new: true } - ).populate('cards'); + ) + .populate({ + path: "cards", + populate: { + path: "members" + } + }); }) .then(result => { res.json({ @@ -117,7 +123,7 @@ router.post("/:id/cards", (req, res, next) => { list: listId, activities: [], members: [req.user.id] - }); + }); }) .then(result => { newCard = result; @@ -125,10 +131,11 @@ router.post("/:id/cards", (req, res, next) => { $addToSet: { cards: result.id } }); }) - .then(() => { + .then(() => Card.findById(newCard.id).populate('members')) + .then(result => { res.json({ message: apiMessages.successfulPost, - data: newCard + data: result }); }) .catch(error => next(error)); diff --git a/server/routes/api/users.js b/server/routes/api/users.js index a1baf80e..522ea751 100644 --- a/server/routes/api/users.js +++ b/server/routes/api/users.js @@ -34,7 +34,7 @@ router.get("/:id/boards", (req, res, next) => { populate: { path: "cards", populate: { - path: "activities" + path: "members" } } } From e90bff538685a7bb15844861a80753f909ab575b Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Fri, 21 Jul 2017 14:49:45 -0400 Subject: [PATCH 099/112] update current card actions for member changes --- client/src/actions/currentCard.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/src/actions/currentCard.js b/client/src/actions/currentCard.js index c51ff97b..ba52586e 100644 --- a/client/src/actions/currentCard.js +++ b/client/src/actions/currentCard.js @@ -1,5 +1,4 @@ -// import { getAllBoardsInit, addNewBoard, setChangedBoard } from "./allBoards"; -// import { getListsSuccess } from "./lists"; +import { setChangedCard } from "./lists"; export const GET_CURRENT_CARD_REQUEST = "GET_CURRENT_CARD_REQUEST"; export const GET_CURRENT_CARD_SUCCESS = "GET_CURRENT_CARD_SUCCESS"; export const GET_CURRENT_CARD_FAILURE = "GET_CURRENT_CARD_FAILURE"; @@ -69,6 +68,7 @@ export function addMemberToCurrentCard(token, cardId, newMemberId) { }) .then(json => { dispatch(getCurrentCardSuccess(json.data)); + dispatch(setChangedCard(json.data)); }) .catch(error => { dispatch(getCurrentCardFailure(error)); @@ -95,6 +95,7 @@ export function removeMemberFromCurrentCard(token, cardId, memberId) { }) .then(json => { dispatch(getCurrentCardSuccess(json.data)); + dispatch(setChangedCard(json.data)); }) .catch(error => { dispatch(getCurrentCardFailure(error)); From d5d69ef82bff7ae8a972252db2847604f677b403 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Fri, 21 Jul 2017 14:50:30 -0400 Subject: [PATCH 100/112] code formatter --- client/src/actions/currentCard.js | 2 +- client/src/components/Board.js | 13 +- client/src/components/Card.js | 14 +- client/src/components/CardModal.js | 88 +++++---- client/src/components/List.js | 17 +- client/src/containers/CardModalContainer.js | 41 ++++- client/src/reducers/currentCard.js | 2 +- server/routes/api/boards.js | 66 +++---- server/routes/api/cards.js | 192 ++++++++++---------- server/routes/api/lists.js | 87 +++++---- server/seeds/seeds.js | 2 +- server/spec/board_spec.js | 1 - server/spec/card_spec.js | 6 +- 13 files changed, 288 insertions(+), 243 deletions(-) diff --git a/client/src/actions/currentCard.js b/client/src/actions/currentCard.js index ba52586e..b2f09c0c 100644 --- a/client/src/actions/currentCard.js +++ b/client/src/actions/currentCard.js @@ -101,4 +101,4 @@ export function removeMemberFromCurrentCard(token, cardId, memberId) { dispatch(getCurrentCardFailure(error)); }); }; -} \ No newline at end of file +} diff --git a/client/src/components/Board.js b/client/src/components/Board.js index 9936f94c..7c274abc 100644 --- a/client/src/components/Board.js +++ b/client/src/components/Board.js @@ -9,7 +9,14 @@ const buildLists = (lists, token) => { ); }; -const Board = ({ board, lists, isFetching, token, onChangeBoardTitle, onCreateList }) => { +const Board = ({ + board, + lists, + isFetching, + token, + onChangeBoardTitle, + onCreateList +}) => { if (isFetching) { return ( @@ -17,9 +24,9 @@ const Board = ({ board, lists, isFetching, token, onChangeBoardTitle, onCreateLi Loading... - ) + ); } - + let listPanels; if (lists.length === 0) { listPanels =

No Lists found! Create a new list to get started.

; diff --git a/client/src/components/Card.js b/client/src/components/Card.js index f61b4853..e0956a0c 100644 --- a/client/src/components/Card.js +++ b/client/src/components/Card.js @@ -4,9 +4,9 @@ import EditableField from "./EditableField"; import CardModalContainer from "../containers/CardModalContainer"; const Card = ({ card, currentCard, token, onUpdateCard, onDeleteCard }) => { - let members = card.members.map(member => ( + let members = card.members.map(member =>

{member.email}

- )); + ); return ( { - + onDeleteCard(e, card._id)} className="card-delete"> Delete This Card - Current Members: - {members} + Current Members: + {members} diff --git a/client/src/components/CardModal.js b/client/src/components/CardModal.js index 88eb576d..38e6a23e 100644 --- a/client/src/components/CardModal.js +++ b/client/src/components/CardModal.js @@ -1,5 +1,12 @@ -import React, { Component } from 'react'; -import { FormGroup, ControlLabel, FormControl, Table, Button, Modal } from 'react-bootstrap'; +import React, { Component } from "react"; +import { + FormGroup, + ControlLabel, + FormControl, + Table, + Button, + Modal +} from "react-bootstrap"; import EditableField from "./EditableField"; const buildAddUserOptions = (cardMembers, allUsers) => { @@ -17,62 +24,65 @@ const buildAddUserOptions = (cardMembers, allUsers) => { options.push(user); } }); - return options.map(user => ( + return options.map(user => - )); + ); }; const buildActivityFeed = activities => { return activities.map(activity => { return ( -

{activity.description} Date: {new Date(activity.createdAt).toLocaleString()}

- ) +

+ {activity.description} Date:{" "} + {new Date(activity.createdAt).toLocaleString()} +

+ ); }); -} +}; const buildMemberTable = (members, onUserRemove) => { - let memberCells = members.map(member => ( + let memberCells = members.map(member => {member.email} - - - )) + + ); return ( - + {memberCells}
Name
- ) + ); }; class CardModal extends Component { constructor() { - super() + super(); this.state = { showModal: false - } + }; } close = () => { this.setState({ showModal: false }); - } + }; - open = (e) => { + open = e => { this.props.onGetCard(this.props.card._id); this.setState({ showModal: true }); - } + }; render() { const { currentCard, allUsers, onUserAdd, onUserRemove } = this.props; @@ -82,24 +92,27 @@ class CardModal extends Component { return (
- - - - {currentCard.title} - - + + + {currentCard.title} + +

Description

- +

{currentCard.description}


@@ -107,18 +120,15 @@ class CardModal extends Component { {memberTable}
- Add a member: - - {addUserOptions} - + Add a member: + + {addUserOptions} + -
+
- -
+ +

Activity Feed

@@ -133,4 +143,4 @@ class CardModal extends Component { } } -export default CardModal; \ No newline at end of file +export default CardModal; diff --git a/client/src/components/List.js b/client/src/components/List.js index fadb16b9..0bf0dc67 100644 --- a/client/src/components/List.js +++ b/client/src/components/List.js @@ -34,18 +34,17 @@ const List = ({ list, token, onDeleteList, onUpdateList, onCreateCard }) => {
- {cardPanels} - + {cardPanels} + - onDeleteList(e, list._id)} className="list-delete"> Delete This List diff --git a/client/src/containers/CardModalContainer.js b/client/src/containers/CardModalContainer.js index 6be4b7c8..66c32445 100644 --- a/client/src/containers/CardModalContainer.js +++ b/client/src/containers/CardModalContainer.js @@ -1,7 +1,11 @@ import { connect } from "react-redux"; import CardModal from "../components/CardModal"; import serialize from "form-serialize"; -import { getCurrentCard, addMemberToCurrentCard, removeMemberFromCurrentCard } from "../actions/currentCard"; +import { + getCurrentCard, + addMemberToCurrentCard, + removeMemberFromCurrentCard +} from "../actions/currentCard"; import { editCard } from "../actions/lists"; const mapStateToProps = (state, ownProps) => { @@ -22,21 +26,42 @@ const mapDispatchToProps = (dispatch, ownProps) => { e.preventDefault(); const form = e.target; const data = serialize(form); - dispatch(editCard(ownProps.token, ownProps.currentCard._id, data, ownProps.currentCard)); - }, + dispatch( + editCard( + ownProps.token, + ownProps.currentCard._id, + data, + ownProps.currentCard + ) + ); + }, onUserAdd: e => { e.preventDefault(); const form = e.target; - const newMember = serialize(form, {hash: true}).newMember; - dispatch(addMemberToCurrentCard(ownProps.token, ownProps.currentCard._id, newMember)); + const newMember = serialize(form, { hash: true }).newMember; + dispatch( + addMemberToCurrentCard( + ownProps.token, + ownProps.currentCard._id, + newMember + ) + ); }, onUserRemove: (e, memberId) => { e.preventDefault(); - dispatch(removeMemberFromCurrentCard(ownProps.token, ownProps.currentCard._id, memberId)); + dispatch( + removeMemberFromCurrentCard( + ownProps.token, + ownProps.currentCard._id, + memberId + ) + ); } }; }; -const CardModalContainer = connect(mapStateToProps, mapDispatchToProps)(CardModal); +const CardModalContainer = connect(mapStateToProps, mapDispatchToProps)( + CardModal +); -export default CardModalContainer; \ No newline at end of file +export default CardModalContainer; diff --git a/client/src/reducers/currentCard.js b/client/src/reducers/currentCard.js index 3576525f..3b228e90 100644 --- a/client/src/reducers/currentCard.js +++ b/client/src/reducers/currentCard.js @@ -3,7 +3,7 @@ import * as Actions from "../actions/currentCard"; const initialState = { data: { members: [], - activities: [], + activities: [] }, isFetching: false, error: null diff --git a/server/routes/api/boards.js b/server/routes/api/boards.js index 4ef43737..9ffa4652 100644 --- a/server/routes/api/boards.js +++ b/server/routes/api/boards.js @@ -254,40 +254,40 @@ router.get("/:id/lists", (req, res, next) => { Delete Board ================ */ router.delete("/:id", (req, res, next) => { -const boardId = req.params.id; -let deletedBoard; - -Board.findById(boardId) - .then(board => { - if (!board) { - throw new Error(apiMessages.doesNotExist("Board")); - } - let canCurrentUserDelete = checkUserBoardPermissions(board, req.user.id); - if (!canCurrentUserDelete) { - throw new Error(apiMessages.failedAuth); - } + const boardId = req.params.id; + let deletedBoard; - return Board.findByIdAndRemove(boardId); - }) - .then(result => { - deletedBoard = result; - return User.update( - { boards: { $in: [deletedBoard.id] } }, - { - $pull: { boards: deletedBoard.id } - }, - {multi: true} - ); - }) - .then(() => { - res.json({ - message: apiMessages.successfulDelete, - data: { - deletedResource: deletedBoard + Board.findById(boardId) + .then(board => { + if (!board) { + throw new Error(apiMessages.doesNotExist("Board")); } - }); - }) - .catch(error => next(error)); + let canCurrentUserDelete = checkUserBoardPermissions(board, req.user.id); + if (!canCurrentUserDelete) { + throw new Error(apiMessages.failedAuth); + } + + return Board.findByIdAndRemove(boardId); + }) + .then(result => { + deletedBoard = result; + return User.update( + { boards: { $in: [deletedBoard.id] } }, + { + $pull: { boards: deletedBoard.id } + }, + { multi: true } + ); + }) + .then(() => { + res.json({ + message: apiMessages.successfulDelete, + data: { + deletedResource: deletedBoard + } + }); + }) + .catch(error => next(error)); }); -module.exports = router; \ No newline at end of file +module.exports = router; diff --git a/server/routes/api/cards.js b/server/routes/api/cards.js index a520f3bd..a26afc5c 100644 --- a/server/routes/api/cards.js +++ b/server/routes/api/cards.js @@ -59,112 +59,112 @@ router.get("/:id", (req, res, next) => { Update Card ================ */ router.put("/:id", (req, res, next) => { -const cardId = req.params.id; -const { title, description } = req.body; -let originalCard; + const cardId = req.params.id; + const { title, description } = req.body; + let originalCard; -Card.findById(cardId) - .populate({ - path: "list", - populate: { - path: "board" - } - }) - .then(card => { - if (!card) { - throw new Error(apiMessages.doesNotExist("Card")); - } + Card.findById(cardId) + .populate({ + path: "list", + populate: { + path: "board" + } + }) + .then(card => { + if (!card) { + throw new Error(apiMessages.doesNotExist("Card")); + } - let canCurrentUserDelete = checkUserBoardPermissions( - card.list.board, - req.user.id - ); - if (!canCurrentUserDelete) { - throw new Error(apiMessages.failedAuth); - } - originalCard = card; - let activityMessage = parseCardChange(title, description); - return Activity.create({ - description: activityMessage, - card: cardId - }); - }) - .then(activity => { - return Card.findByIdAndUpdate( - cardId, - { - title: title || originalCard.title, - description: description || originalCard.description, - $push: { activities: activity.id } - }, - { new: true } - ).populate(['activities', 'members']); - }) - .then(result => { - res.json({ - message: apiMessages.successfulPut, - data: result - }); - }) - .catch(error => next(error)); + let canCurrentUserDelete = checkUserBoardPermissions( + card.list.board, + req.user.id + ); + if (!canCurrentUserDelete) { + throw new Error(apiMessages.failedAuth); + } + originalCard = card; + let activityMessage = parseCardChange(title, description); + return Activity.create({ + description: activityMessage, + card: cardId + }); + }) + .then(activity => { + return Card.findByIdAndUpdate( + cardId, + { + title: title || originalCard.title, + description: description || originalCard.description, + $push: { activities: activity.id } + }, + { new: true } + ).populate(["activities", "members"]); + }) + .then(result => { + res.json({ + message: apiMessages.successfulPut, + data: result + }); + }) + .catch(error => next(error)); }); /* =============== Add Member to Card ================ */ router.post("/:id/users/:userId", (req, res, next) => { -const cardId = req.params.id; -const userToAdd = req.params.userId; -let board; -let updatedCard; + const cardId = req.params.id; + const userToAdd = req.params.userId; + let board; + let updatedCard; -Card.findById(cardId) - .populate({ - path: "list", - populate: { - path: "board" - } - }) - .then(card => { - if (!card) { - throw new Error(apiMessages.doesNotExist("Card")); - } + Card.findById(cardId) + .populate({ + path: "list", + populate: { + path: "board" + } + }) + .then(card => { + if (!card) { + throw new Error(apiMessages.doesNotExist("Card")); + } - let canCurrentUserDelete = checkUserBoardPermissions( - card.list.board, - req.user.id - ); - if (!canCurrentUserDelete) { - throw new Error(apiMessages.failedAuth); - } + let canCurrentUserDelete = checkUserBoardPermissions( + card.list.board, + req.user.id + ); + if (!canCurrentUserDelete) { + throw new Error(apiMessages.failedAuth); + } - board = card.list.board; - return Card.findByIdAndUpdate( - cardId, - { - $addToSet: { members: userToAdd } - }, - { new: true } - ).populate(['activities', 'members']); - }) - .then(result => { - updatedCard = result; - return Board.findByIdAndUpdate(board.id, { - $addToSet: { users: userToAdd } - }); - }) - .then(result => { - return User.findByIdAndUpdate(userToAdd, { - $addToSet: { boards: board.id } - }); - }) - .then(result => { - res.json({ - message: apiMessages.successfulPost, - data: updatedCard - }); - }) - .catch(error => next(error)); + board = card.list.board; + return Card.findByIdAndUpdate( + cardId, + { + $addToSet: { members: userToAdd } + }, + { new: true } + ).populate(["activities", "members"]); + }) + .then(result => { + updatedCard = result; + return Board.findByIdAndUpdate(board.id, { + $addToSet: { users: userToAdd } + }); + }) + .then(result => { + return User.findByIdAndUpdate(userToAdd, { + $addToSet: { boards: board.id } + }); + }) + .then(result => { + res.json({ + message: apiMessages.successfulPost, + data: updatedCard + }); + }) + .catch(error => next(error)); }); /* =============== @@ -203,7 +203,7 @@ router.delete("/:id/users/:userId", (req, res, next) => { $pull: { members: userToRemove } }, { new: true } - ).populate(['activities', 'members']); + ).populate(["activities", "members"]); }) .then(result => { res.json({ diff --git a/server/routes/api/lists.js b/server/routes/api/lists.js index eca73297..48367d00 100644 --- a/server/routes/api/lists.js +++ b/server/routes/api/lists.js @@ -36,13 +36,12 @@ router.put("/:id", (req, res, next) => { description: description || list.description }, { new: true } - ) - .populate({ - path: "cards", - populate: { - path: "members" - } - }); + ).populate({ + path: "cards", + populate: { + path: "members" + } + }); }) .then(result => { res.json({ @@ -56,43 +55,43 @@ router.put("/:id", (req, res, next) => { Delete List ================ */ router.delete("/:id", (req, res, next) => { -const listId = req.params.id; -let deletedList; -List.findById(listId) - .populate("board") - .then(list => { - if (!list) { - throw new Error(apiMessages.doesNotExist("List")); - } - - let canCurrentUserDelete = checkUserBoardPermissions( - list.board, - req.user.id - ); - if (!canCurrentUserDelete) { - throw new Error(apiMessages.failedAuth); - } - - return List.findByIdAndRemove(listId); - }) - .then(result => { - deletedList = result; - return Board.update( - { lists: { $in: [deletedList.id] } }, - { - $pop: { lists: deletedList } + const listId = req.params.id; + let deletedList; + List.findById(listId) + .populate("board") + .then(list => { + if (!list) { + throw new Error(apiMessages.doesNotExist("List")); } - ); - }) - .then(() => { - res.json({ - message: apiMessages.successfulDelete, - data: { - deletedResource: deletedList + + let canCurrentUserDelete = checkUserBoardPermissions( + list.board, + req.user.id + ); + if (!canCurrentUserDelete) { + throw new Error(apiMessages.failedAuth); } - }); - }) - .catch(error => next(error)); + + return List.findByIdAndRemove(listId); + }) + .then(result => { + deletedList = result; + return Board.update( + { lists: { $in: [deletedList.id] } }, + { + $pop: { lists: deletedList } + } + ); + }) + .then(() => { + res.json({ + message: apiMessages.successfulDelete, + data: { + deletedResource: deletedList + } + }); + }) + .catch(error => next(error)); }); /* =============== @@ -123,7 +122,7 @@ router.post("/:id/cards", (req, res, next) => { list: listId, activities: [], members: [req.user.id] - }); + }); }) .then(result => { newCard = result; @@ -131,7 +130,7 @@ router.post("/:id/cards", (req, res, next) => { $addToSet: { cards: result.id } }); }) - .then(() => Card.findById(newCard.id).populate('members')) + .then(() => Card.findById(newCard.id).populate("members")) .then(result => { res.json({ message: apiMessages.successfulPost, diff --git a/server/seeds/seeds.js b/server/seeds/seeds.js index b7491ba1..c89115b8 100644 --- a/server/seeds/seeds.js +++ b/server/seeds/seeds.js @@ -1,4 +1,4 @@ -const faker = require('faker'); +const faker = require("faker"); const MULTIPLIER = 5; module.exports = () => { diff --git a/server/spec/board_spec.js b/server/spec/board_spec.js index 1c67cd54..d021b513 100644 --- a/server/spec/board_spec.js +++ b/server/spec/board_spec.js @@ -298,6 +298,5 @@ describe("Board", () => { done(); }); }); - }); }); diff --git a/server/spec/card_spec.js b/server/spec/card_spec.js index 946b74a4..467e49ec 100644 --- a/server/spec/card_spec.js +++ b/server/spec/card_spec.js @@ -183,8 +183,10 @@ describe("Card", () => { .then(res => { expect(res.statusCode).toBe(200); expect(res.body.data.title).toBe("Test Original Card Title"); - expect(res.body.data.description).toBe("Test Original Card Description"); - done() + expect(res.body.data.description).toBe( + "Test Original Card Description" + ); + done(); }) .catch(error => { expect(error).toEqual(null); From 1af6b71d8f5677ecdfbd55a75528777b2559ac36 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Fri, 21 Jul 2017 18:13:20 -0400 Subject: [PATCH 101/112] add mark card completed button --- client/src/components/Card.js | 9 +++++---- client/src/components/CardModal.js | 10 +++++++++- client/src/containers/CardModalContainer.js | 5 ++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/client/src/components/Card.js b/client/src/components/Card.js index e0956a0c..3406d21d 100644 --- a/client/src/components/Card.js +++ b/client/src/components/Card.js @@ -1,5 +1,5 @@ import React from "react"; -import { Panel, Row, Col } from "react-bootstrap"; +import { Button, Panel, Row, Col } from "react-bootstrap"; import EditableField from "./EditableField"; import CardModalContainer from "../containers/CardModalContainer"; @@ -25,9 +25,10 @@ const Card = ({ card, currentCard, token, onUpdateCard, onDeleteCard }) => { token={token} card={card} /> - onDeleteCard(e, card._id)} className="card-delete"> - Delete This Card - +
+ Current Members: diff --git a/client/src/components/CardModal.js b/client/src/components/CardModal.js index 38e6a23e..e77d90a1 100644 --- a/client/src/components/CardModal.js +++ b/client/src/components/CardModal.js @@ -75,6 +75,12 @@ class CardModal extends Component { }; } + onDelete = (e) => { + e.preventDefault(); + this.setState({ showModal: false }); + this.props.onMarkComplete(); + }; + close = () => { this.setState({ showModal: false }); }; @@ -92,7 +98,7 @@ class CardModal extends Component { return (
- @@ -133,6 +139,8 @@ class CardModal extends Component {

Activity Feed

{activitiesFeed} +
+ diff --git a/client/src/containers/CardModalContainer.js b/client/src/containers/CardModalContainer.js index 66c32445..784d16e1 100644 --- a/client/src/containers/CardModalContainer.js +++ b/client/src/containers/CardModalContainer.js @@ -6,7 +6,7 @@ import { addMemberToCurrentCard, removeMemberFromCurrentCard } from "../actions/currentCard"; -import { editCard } from "../actions/lists"; +import { editCard, deleteSelectedCard } from "../actions/lists"; const mapStateToProps = (state, ownProps) => { return { @@ -56,6 +56,9 @@ const mapDispatchToProps = (dispatch, ownProps) => { memberId ) ); + }, + onMarkComplete: () => { + dispatch(deleteSelectedCard(ownProps.token, ownProps.currentCard._id,)); } }; }; From 564322437b0e4bc6193983619ee499b108ffe812 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Fri, 21 Jul 2017 18:14:35 -0400 Subject: [PATCH 102/112] apply auto code formatting --- client/src/components/Card.js | 7 ++++++- client/src/components/CardModal.js | 11 +++++++++-- client/src/containers/CardModalContainer.js | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/client/src/components/Card.js b/client/src/components/Card.js index 3406d21d..b7a91f5c 100644 --- a/client/src/components/Card.js +++ b/client/src/components/Card.js @@ -26,7 +26,12 @@ const Card = ({ card, currentCard, token, onUpdateCard, onDeleteCard }) => { card={card} />
- diff --git a/client/src/components/CardModal.js b/client/src/components/CardModal.js index e77d90a1..bee47794 100644 --- a/client/src/components/CardModal.js +++ b/client/src/components/CardModal.js @@ -75,7 +75,7 @@ class CardModal extends Component { }; } - onDelete = (e) => { + onDelete = e => { e.preventDefault(); this.setState({ showModal: false }); this.props.onMarkComplete(); @@ -140,7 +140,14 @@ class CardModal extends Component {

Activity Feed

{activitiesFeed}
- + diff --git a/client/src/containers/CardModalContainer.js b/client/src/containers/CardModalContainer.js index 784d16e1..2e5d4161 100644 --- a/client/src/containers/CardModalContainer.js +++ b/client/src/containers/CardModalContainer.js @@ -58,7 +58,7 @@ const mapDispatchToProps = (dispatch, ownProps) => { ); }, onMarkComplete: () => { - dispatch(deleteSelectedCard(ownProps.token, ownProps.currentCard._id,)); + dispatch(deleteSelectedCard(ownProps.token, ownProps.currentCard._id)); } }; }; From 2c14e8fa35f7c837974d8c0b1a6cf3bbcaa90af1 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Fri, 21 Jul 2017 18:41:12 -0400 Subject: [PATCH 103/112] improve styling and layout --- client/src/components/Card.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/client/src/components/Card.js b/client/src/components/Card.js index b7a91f5c..572e92ee 100644 --- a/client/src/components/Card.js +++ b/client/src/components/Card.js @@ -20,12 +20,10 @@ const Card = ({ card, currentCard, token, onUpdateCard, onDeleteCard }) => { - -
+ Current Members: + {members} + + - - Current Members: - {members} -
+ + + + + ); }; From 799789944ebd110ccc01cb97e98eed4e5fe19bb4 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Fri, 21 Jul 2017 23:54:48 -0400 Subject: [PATCH 104/112] add sortable hoc library --- client/package.json | 1 + client/src/components/List.js | 105 +++++++++++++++---------- client/src/containers/ListContainer.js | 3 +- client/yarn.lock | 13 ++- jsconfig.json | 6 ++ 5 files changed, 83 insertions(+), 45 deletions(-) create mode 100644 jsconfig.json diff --git a/client/package.json b/client/package.json index 4751185a..ad09f9ed 100644 --- a/client/package.json +++ b/client/package.json @@ -11,6 +11,7 @@ "react-bootstrap": "^0.31.1", "react-dom": "^15.6.1", "react-redux": "^5.0.5", + "react-sortable-hoc": "^0.6.5", "redux": "^3.7.2", "redux-thunk": "^2.2.0" }, diff --git a/client/src/components/List.js b/client/src/components/List.js index 0bf0dc67..61b34eca 100644 --- a/client/src/components/List.js +++ b/client/src/components/List.js @@ -1,4 +1,4 @@ -import React from "react"; +import React, { Component } from "react"; import { Button, Panel, Col, ListGroup, ListGroupItem } from "react-bootstrap"; import EditableField from "./EditableField"; import CardContainer from "../containers/CardContainer"; @@ -9,48 +9,69 @@ const buildCards = (cards, token) => { ); }; -const List = ({ list, token, onDeleteList, onUpdateList, onCreateCard }) => { - let cardPanels; - if (list.cards.length === 0) { - cardPanels =

No cards found.

; - } else { - cardPanels = buildCards(list.cards, token); +class List extends Component { + constructor(props) { + super(props) + this.state = { + cards: this.props.list.cards + }; } - return ( - - -

{list.title}

- - } - className="list-panel" - > - - - -

{list.description}

-
-
- - {cardPanels} - - -
-
- onDeleteList(e, list._id)} className="list-delete"> - Delete This List - - - ); -}; + componentWillReceiveProps(nextProps) { + console.log('ayyyy'); + if (!nextProps.isFetching) { + this.setState({ + cards: nextProps.list.cards + }); + } + } + + render() { + const { list, token, onDeleteList, onUpdateList, onCreateCard } = this.props; + let cardPanels; + + if (this.state.cards.length === 0) { + cardPanels =

No cards found.

; + } else { + cardPanels = buildCards(this.state.cards, token); + } + + return ( + + +

{list.title}

+ + } + className="list-panel" + > + + + +

{list.description}

+
+
+ + {cardPanels} + + +
+ +
+ onDeleteList(e, list._id)} className="list-delete"> + Delete This List + + + ); + } +} export default List; diff --git a/client/src/containers/ListContainer.js b/client/src/containers/ListContainer.js index 104f41c3..3ce0e5a4 100644 --- a/client/src/containers/ListContainer.js +++ b/client/src/containers/ListContainer.js @@ -6,7 +6,8 @@ import { editList, deleteSelectedList, createCard } from "../actions/lists"; const mapStateToProps = (state, ownProps) => { return { list: ownProps.list, - token: ownProps.token + token: ownProps.token, + isFetching: state.lists.isFetching }; }; diff --git a/client/yarn.lock b/client/yarn.lock index bfef3810..15c22e6c 100644 --- a/client/yarn.lock +++ b/client/yarn.lock @@ -3851,7 +3851,7 @@ lodash.uniq@^4.5.0: version "4.5.0" resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" -"lodash@>=3.5 <5", lodash@^4.0.0, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.17.2, lodash@^4.17.3, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0: +"lodash@>=3.5 <5", lodash@^4.0.0, lodash@^4.12.0, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.17.2, lodash@^4.17.3, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0: version "4.17.4" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" @@ -4840,7 +4840,7 @@ prop-types-extra@^1.0.1: dependencies: warning "^3.0.0" -prop-types@^15.5.10, prop-types@^15.5.8: +prop-types@^15.5.10, prop-types@^15.5.7, prop-types@^15.5.8: version "15.5.10" resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.5.10.tgz#2797dfc3126182e3a95e3dfbb2e893ddd7456154" dependencies: @@ -5067,6 +5067,15 @@ react-scripts@1.0.10: optionalDependencies: fsevents "1.1.2" +react-sortable-hoc@^0.6.5: + version "0.6.5" + resolved "https://registry.yarnpkg.com/react-sortable-hoc/-/react-sortable-hoc-0.6.5.tgz#e6b5d414476d51a0b621931298855d4fd608c227" + dependencies: + babel-runtime "^6.11.6" + invariant "^2.2.1" + lodash "^4.12.0" + prop-types "^15.5.7" + react@^15.6.1: version "15.6.1" resolved "https://registry.yarnpkg.com/react/-/react-15.6.1.tgz#baa8434ec6780bde997cdc380b79cd33b96393df" diff --git a/jsconfig.json b/jsconfig.json new file mode 100644 index 00000000..57d39d15 --- /dev/null +++ b/jsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "experimentalDecorators": true, + "allowJs": true + } +} \ No newline at end of file From dea425450258229cff916bd84f264d8b99e757da Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Sat, 22 Jul 2017 00:30:32 -0400 Subject: [PATCH 105/112] add drag handle css --- client/src/components/Card.js | 17 +++++++-- client/src/components/List.js | 65 +++++++++++++++++++++++++++++------ client/src/index.css | 11 +++++- 3 files changed, 78 insertions(+), 15 deletions(-) diff --git a/client/src/components/Card.js b/client/src/components/Card.js index 572e92ee..49bf778d 100644 --- a/client/src/components/Card.js +++ b/client/src/components/Card.js @@ -2,6 +2,13 @@ import React from "react"; import { Button, Panel, Row, Col } from "react-bootstrap"; import EditableField from "./EditableField"; import CardModalContainer from "../containers/CardModalContainer"; +import { SortableHandle } from 'react-sortable-hoc'; + +const DragHandle = SortableHandle(() => ( +
+ O +
+)); const Card = ({ card, currentCard, token, onUpdateCard, onDeleteCard }) => { let members = card.members.map(member => @@ -10,10 +17,14 @@ const Card = ({ card, currentCard, token, onUpdateCard, onDeleteCard }) => { return ( - {card.title} - +
+ + {card.title} + + +
} + className="panel-header" >

{card.description}

diff --git a/client/src/components/List.js b/client/src/components/List.js index 61b34eca..00c582f4 100644 --- a/client/src/components/List.js +++ b/client/src/components/List.js @@ -2,12 +2,38 @@ import React, { Component } from "react"; import { Button, Panel, Col, ListGroup, ListGroupItem } from "react-bootstrap"; import EditableField from "./EditableField"; import CardContainer from "../containers/CardContainer"; +import { + SortableContainer, + SortableElement, + SortableHandle, + arrayMove, +} from 'react-sortable-hoc'; -const buildCards = (cards, token) => { - return cards.map(card => - +const DragHandle = SortableHandle(() => ::); // This can be any component you want + +const SortableItem = SortableElement(({value, token}) => { + return ( +
+ +
); -}; +}); + +const SortableList = SortableContainer(({items, token}) => { + return ( +
+ {items.map((value, index) => ( + + ))} +
+ ) +}) + +// const buildCards = (cards, token) => { +// return cards.map(card => +// +// ); +// }; class List extends Component { constructor(props) { @@ -26,16 +52,31 @@ class List extends Component { } } + onSortEnd = ({oldIndex, newIndex}) => { + let {cards} = this.state; + + this.setState({ + cards: arrayMove(cards, oldIndex, newIndex), + }); + }; + render() { const { list, token, onDeleteList, onUpdateList, onCreateCard } = this.props; - let cardPanels; + // let cardPanels; - if (this.state.cards.length === 0) { - cardPanels =

No cards found.

; - } else { - cardPanels = buildCards(this.state.cards, token); - } + // if (this.state.cards.length === 0) { + // cardPanels =

No cards found.

; + // } else { + // cardPanels = buildCards(this.state.cards, token); + // } + let sortableCardPanels = + return ( - {cardPanels} + + {sortableCardPanels} + + + +
+

Activity Feed

+ {activitiesFeed} +
+ + + + + +
+ ); + return (
- - - - {currentCard.title} - - - - -

Description

- -

{currentCard.description}

-
-
-

Members

- {memberTable} -
- - Add a member: - - {addUserOptions} - - -
- - -
-
-
-

Activity Feed

- {activitiesFeed} -
- -
- - - + {isFetching ? : content}
); diff --git a/client/src/components/List.js b/client/src/components/List.js index 304a5f5b..e3d1c6fb 100644 --- a/client/src/components/List.js +++ b/client/src/components/List.js @@ -5,10 +5,11 @@ import CardContainer from "../containers/CardContainer"; import { SortableContainer, SortableElement, - arrayMove, -} from 'react-sortable-hoc'; + arrayMove +} from "react-sortable-hoc"; +import Loader from "./Loader"; -const SortableItem = SortableElement(({value, token}) => { +const SortableItem = SortableElement(({ value, token }) => { return (
@@ -16,19 +17,24 @@ const SortableItem = SortableElement(({value, token}) => { ); }); -const SortableList = SortableContainer(({items, token}) => { +const SortableList = SortableContainer(({ items, token }) => { return (
- {items.map((value, index) => ( - - ))} + {items.map((value, index) => + + )}
- ) -}) + ); +}); class List extends Component { constructor(props) { - super(props) + super(props); this.state = { cards: this.props.list.cards }; @@ -42,25 +48,42 @@ class List extends Component { } } - onSortEnd = ({oldIndex, newIndex}) => { - let {cards} = this.state; + onSortEnd = ({ oldIndex, newIndex }) => { + let { cards } = this.state; this.setState({ - cards: arrayMove(cards, oldIndex, newIndex), + cards: arrayMove(cards, oldIndex, newIndex) }); }; render() { - const { list, token, onDeleteList, onUpdateList, onCreateCard } = this.props; + const { + list, + token, + isFetching, + onDeleteList, + onUpdateList, + onCreateCard + } = this.props; - let sortableCardPanels = - + let sortableCardPanels = ( + + ); + if (isFetching) { + return ( + + + + + + ); + } return ( - + onDeleteList(e, list._id)} className="list-delete"> Delete This List diff --git a/client/src/components/Loader.js b/client/src/components/Loader.js new file mode 100644 index 00000000..3b0fafda --- /dev/null +++ b/client/src/components/Loader.js @@ -0,0 +1,5 @@ +import React from "react"; + +const Loader = () => ; + +export default Loader; diff --git a/client/src/index.css b/client/src/index.css index 91e3a3f1..b1336a4a 100644 --- a/client/src/index.css +++ b/client/src/index.css @@ -60,4 +60,11 @@ a { .draggable-active { opacity: 0.7; +} + +span.img-loader { + display: inline-block; + background-image: url("/ajax-loader.gif"); + height: 1em; + width: 1em; } \ No newline at end of file diff --git a/client/src/index.js b/client/src/index.js index 7aab869e..2fb13120 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -1,7 +1,7 @@ import React from "react"; import ReactDOM from "react-dom"; import "bootswatch/flatly/bootstrap.min.css"; -import 'font-awesome/css/font-awesome.css' +import "font-awesome/css/font-awesome.css"; import "./index.css"; import AppContainer from "./containers/AppContainer"; import { Provider } from "react-redux"; From b094ddeb09e43da8705ecffffe37e7e949a0472d Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Sat, 22 Jul 2017 12:28:31 -0400 Subject: [PATCH 109/112] add production link --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b48c05b3..91bff03c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,8 @@ # assignment_djello -Project management with that great wobbly taste. \ No newline at end of file +Project management with that great wobbly taste. + +[Production link here](https://salty-dawn-77328.herokuapp.com/) + +You may log in using the following credentials: +Email: foobar0@gmail.com -OR- foobar1@gmail.com +Password: password \ No newline at end of file From 98241c72014301dc3d3f6445188856c3346a7322 Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Mon, 24 Jul 2017 13:16:32 -0400 Subject: [PATCH 110/112] update readme --- README.md | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 91bff03c..f86a6e6f 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,36 @@ -# assignment_djello -Project management with that great wobbly taste. +# Project Djello -[Production link here](https://salty-dawn-77328.herokuapp.com/) +## Introduction +Project Djello is a reproduction of Trello using a fullstack JavaScript stack. + +## Technologies Used +This project uses Express and MongoDB on the back-end, and React/Redux on the front-end. Authentication is done through JSON web-tokens, which are provided upon initial login to the client and are used to authenticate all API requests. + +React-sortable-hoc was used to provide basic drag-and-drop functionality for the project. + +Jasmine is used for the full-featured test suite on the back end, which can be run with `npm run test` or `yarn test` while inside the server directory. + +## Getting Started +To set this project up in your local environment, first clone the repository, then install the dependencies inside the root, server, and client directories using either `npm install` or `yarn`. Then, set up the environmental variable `JWT_SECRET`, either in your shell or in a .env file in the project root directory. This will be used to hash the JSON Web Token. + +Finally, run either `npm run seed` or `yarn seed` inside the server directory to populate your local database. Make sure to have MongoDB running in the background. To test that the server was populated correctly, either run the test suite, or use the REPL provided in the project by running `npm run c`/`yarn run c` or `npm run console`/`yarn run console`. You can use this to run manual queries like the following: + +```javascript +User.find().then(lg); +``` + +To start the project, run `yarn start` in the root directory. If you do not have yarn installed and want to use a different runner, you will need to edit the `start-client.js` file and make the appropriate changes. + +## Deployment Link +A deployed version of this project may be found [here.](https://salty-dawn-77328.herokuapp.com/) You may log in using the following credentials: Email: foobar0@gmail.com -OR- foobar1@gmail.com -Password: password \ No newline at end of file +Password: password + +## Additional Notes +Whenever a new user is added to a card, they are automatically given full access and editing privileges to that entire board. You can test this by creating a board using foobar0@gmail.com, then adding foobar1@gmail.com. If you then login with foobar1@gmail.com, you will see that they have access to the board as well. + +All editable fields can be changed simply by clicking on them. Pressing enter or the submit button will save the changes and clicking away or cancel will dismiss the changes. + +Bootswatch's Flatly theme was used to help style the entire project. \ No newline at end of file From c6300779cacc4ca5d6a4ed9060a68a170e238fee Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Mon, 24 Jul 2017 13:17:30 -0400 Subject: [PATCH 111/112] update readme paragraph formatting --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f86a6e6f..068a6700 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,9 @@ To start the project, run `yarn start` in the root directory. If you do not have A deployed version of this project may be found [here.](https://salty-dawn-77328.herokuapp.com/) You may log in using the following credentials: + Email: foobar0@gmail.com -OR- foobar1@gmail.com + Password: password ## Additional Notes From acb98b172649c68d30e5b25dacc40791e721441d Mon Sep 17 00:00:00 2001 From: Christian Florez Date: Sat, 29 Jul 2017 10:49:02 -0400 Subject: [PATCH 112/112] add img to readme --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 068a6700..d13cd713 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # Project Djello +[![Project Djello](http://i.imgur.com/KXHUCzg.png)](https://salty-dawn-77328.herokuapp.com/) + + ## Introduction Project Djello is a reproduction of Trello using a fullstack JavaScript stack. @@ -35,4 +38,4 @@ Whenever a new user is added to a card, they are automatically given full access All editable fields can be changed simply by clicking on them. Pressing enter or the submit button will save the changes and clicking away or cancel will dismiss the changes. -Bootswatch's Flatly theme was used to help style the entire project. \ No newline at end of file +Bootswatch's Flatly theme was used to help style the entire project.