Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amy Reid #31

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
a5e6436
draft
juancgarcia May 31, 2017
c3028c6
title change
juancgarcia May 31, 2017
8e163e1
add clarifications and framing to questions
superbuggy Jul 12, 2017
ed231f1
Merge pull request #17 from ga-wdi-exercises/wdi16_updates
amaseda Jul 13, 2017
4c82d8a
update
amaseda Jul 13, 2017
f04d936
additional touches
amaseda Jul 13, 2017
ab428fe
update last question
amaseda Jul 13, 2017
4299d10
change wrong component name
juancgarcia Sep 12, 2017
116c3b3
start building out test suite for checkpoint
Dec 12, 2017
656ac92
finish routing and app
Dec 12, 2017
cbec1e5
remove draft test suite
Dec 12, 2017
0339e33
remove test config; rewrite readme with checkpoint instructions
Dec 12, 2017
4aa7c55
update readme and finalize checkpoint
Dec 12, 2017
b45611b
add sample contact
Dec 12, 2017
f60bab1
remove vscode settings dir
Dec 12, 2017
96535f4
add rubric to readme
Dec 19, 2017
c940cf6
update readme
Feb 26, 2018
b79a2b7
update readme and test suite
Mar 20, 2018
cb8142d
Merge branch 'master' into merge-test
Mar 20, 2018
3653a28
add circleci 2.0
Jul 9, 2018
0dc8e65
add enzyme adapter
Jul 12, 2018
07b022c
update circleci config
Aug 15, 2018
a3f61c1
readme updates
Oct 16, 2018
2302c92
better instructions
Oct 16, 2018
9410f11
update tests to match rendering
Oct 18, 2018
1191874
updated contact.test
dmc2015 Nov 29, 2018
99f75cc
Merge pull request #139 from ga-wdi-exercises/fixes-contacttest
dmc2015 Nov 29, 2018
deb7fe7
update readme for clarity
Feb 12, 2019
457ca8a
more directions
Feb 12, 2019
9a6c2cc
more readme
Feb 12, 2019
b4397eb
update test files again to match renders
Feb 12, 2019
3779a30
Add comment about using `a` at the prompt to run all test with `npm
tomatohammado Mar 12, 2019
c53d73f
times up
arreid08 Jan 13, 2020
8982ea0
Update with Answers for review
arreid08 Jan 13, 2020
417b13a
16 out of 18
arreid08 Jan 24, 2020
a091ccc
16 out of 18
arreid08 Jan 24, 2020
7f296cf
fixed main file issues due to wrong github connection
arreid08 Jan 24, 2020
03d7646
figured out the last two
arreid08 Jan 24, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
Expand Down
130 changes: 130 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Checkpoint: React

## Setup

Fork and clone this repo.

**Before you begin anything, run `npm install`.**

## Before You Begin

Every component has a test suite associated with it. There are 18 tests in
total, grouped into 5 suites.

To run the tests in the terminal, run `npm test`. The tests will rerun every
time you save a file. When running `npm test` in the root of the repo there is
an prompt to run all of the tests by entering `a`.

When you start, all of the tests will be failing; your goal is to make as many
pass as you can in the hour provided.

> HINT: read the output of the failing tests.

> Don't write anything in the `.test.js` files.

## Instructions

You're going to build a simple contact list manager using React and React
Router. An initial set of contacts has been provided in `contacts.json` and some
CSS has been provided in `src/styles/index.css`.

> See a demo of the final app at
> [http://quickest-beam.surge.sh/](http://quickest-beam.surge.sh/)

Add Tweety as a contact in `contacts.json`:

```
{
name: "Tweety",
email: "tweety@gmail.com",
profile_picture: "https://upload.wikimedia.org/wikipedia/en/0/02/Tweety.svg"
}
```

### Setup

Inside `index.js`, import React Router and pass it to `ReactDOM.render()` as the
root component with `<App>` as a child component. We've imported the starter
contacts for you, pass these in to your `<App>` component as a prop, `contacts`.

### `<App>`

Your `<App>` component should accept `contacts` as a prop and use them to set
the initial state for your component. Setting props as initial state looks like
this:

```js
constructor(props) {
super(props)

this.state = {
contacts: props.contacts
}
}
```

Your `<App>` component should also render:

- A div with a class name of `'App'`
- Your `<Header>` component
- Two `<Route />` components
- If the route is `"/"` then render the `<ContactList>` component; if the route
is `"/new-contact"` then render the `<NewContact>` component;

### `<Header>`

Your `<Header>` component should render:

- A `<header>` element with an `<h1>`
- A `<nav>` containing two React Router `<Link>`s, one to the homepage (`"/"`)
and the other to create a new contact (`"/new-contact"`).

### `<ContactList>`

`<ContactList>` should take `contacts` as a prop

It should render:

- A `<Contact>` component for each contact object inside of the `contacts` prop.
- A `<div>` with a class of `contact-list`.

### `<Contact>`

Your `<Contact>` component will render a single contact.

It should render:

- An outer `<div>` with a class of `contact`
- An include an `<img>` for the `profile_picture`,
- `<h3>` for the `name`
- `<h4>` for the `email`.

### `<NewContact>`

Your `<NewContact>` component should render:

- An `<h1>` with a text of `New Contact`
- A form with inputs for the `name`, `email` and `profile_picture`.

When submitted, you should save the new contact by updating your state inside of
`<App>` and redirect the user back to the homepage/list of contacts.

## Rubric

- App component is defined and exported
- App component accepts the `contacts` json objects as a prop and the `contacts`
json object is properly passed
- Router is defined and setup using the browser History API
- Router includes a route for the homepage (`"/"`) and for the new contact page
(`"/new-contact"`)
- Header component is defined and exported
- Header component contains a title and two `<Link>`s, one to the homepage and
the other to the new contact page
- ContactList component is defined and exported
- ContactList component iterates through the contacts, rendering a Contact
component for each
- Contact component is defined and exported
- Contact component is rendering the image, name and email address of a contact
- NewContact is defined and exported
- NewContact contains a form that adds a new contact to the parent App component
state
15 changes: 15 additions & 0 deletions controllers/notes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const express = require("express")
const router = express.Router()
const Note = require("../models/Note")

router.get("/", (req, res) => {
Note.find({}).then(note => res.json(note))
})

router.get("/:id", (req, res) => {
console.log(req.params.id)
const noteId = req.params.id
Note.findOne({ _id: noteId }).then(note => res.json(note))
})

module.exports = router
15 changes: 15 additions & 0 deletions controllers/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const express = require("express")
const router = express.Router()
const User = require("../models/User")

router.get("/", (req, res) => {
User.find({}).then(user => res.json(user))
})

router.get("/:id", (req, res) => {
console.log(req.params.id)
const userId = req.params.id
User.findOne({ _id: userId }).then(user => res.json(user))
})

module.exports = router
27 changes: 27 additions & 0 deletions db/seed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const Note = require('../models/Note')
const User = require('../models/User')
const seedData = require('./seedData')

User.deleteMany({}).then(() => {
User.collection.insert(seedData)
.then(user => {
console.log(user)
process.exit()
})
.catch(err => {
console.log(err)
process.exit()
})
})

Note.deleteMany({}).then(() => {
Note.collection.insert(seedData)
.then(Note => {
console.log(Note)
process.exit()
})
.catch(err => {
console.log(err)
process.exit()
})
})
16 changes: 16 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
const express = require('express')
const parser = require('body-parser')
const app = express()
const usersController = require("./controllers/users")
const notesController = require("./controllers/notes")

app.use(parser.urlencoded({ extended: true }))
app.use(parser.json())

app.get("/", (req, res) => {
res.redirect("/notes")
})

app.use("/users/", usersController)
app.use("/notes/", notesController)

app.listen(3000, () => console.log('app is running'))

// DO NOT REMOVE THIS LINE:
Expand Down
12 changes: 11 additions & 1 deletion models/Note.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
const mongoose = require('../db/connection')

const noteSchema = new mongoose.Schema({})
const noteSchema = new mongoose.Schema({
title: String,
body: String,
author: [
{
ref: "User",
type: mongoose.Schema.Types.ObjectId
}
]

})

module.exports = mongoose.model('Note', noteSchema)
9 changes: 8 additions & 1 deletion models/User.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
const mongoose = require('../db/connection')

const userSchema = new mongoose.Schema({})
const userSchema = new mongoose.Schema({
username: String,
email: String,
notes: [{
ref: "Note",
type: mongoose.Schema.Types.ObjectId
}]
})

module.exports = mongoose.model('User', userSchema)
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {},
"dependencies": {
"express": "^4.17.1",
"mongoose": "^5.8.9"
},
"devDependencies": {
"chai": "*",
"chai-http": "^4.3.0",
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ For this checkpoint, you need to build a simple application for tracking Notes.
Fork this repository and clone your fork locally. Commit as you go. When you are
finished, push to GitHub.

**Wait until the end of the hour to make your Pull Request**
**Wait until the end of the hour to make your Pull Request**