forked from AdaGold/inspiration-board
-
Notifications
You must be signed in to change notification settings - Fork 45
maryams-inspirationalboard #31
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
Open
marshi23
wants to merge
5
commits into
Ada-C10:master
Choose a base branch
from
marshi23:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,32 +2,142 @@ import React, { Component } from 'react'; | |
| import PropTypes from 'prop-types'; | ||
| import axios from 'axios'; | ||
|
|
||
|
|
||
| import './Board.css'; | ||
| import Card from './Card'; | ||
| import NewCardForm from './NewCardForm'; | ||
| import CARD_DATA from '../data/card-data.json'; | ||
| // import CARD_DATA from '../data/card-data.json'; | ||
|
|
||
|
|
||
| class Board extends Component { | ||
| constructor() { | ||
| super(); | ||
|
|
||
| this.state = { | ||
| cards: [], | ||
| }; | ||
| errors: undefined, | ||
| } | ||
| }; | ||
|
|
||
| componentDidMount() { | ||
|
|
||
| axios.get(this.props.url+this.props.boardName+'/cards') | ||
| .then((response) => { | ||
| const cards = response.data.map((card) => { | ||
|
|
||
| const newCard = { | ||
| ...card.card | ||
| }; | ||
| return newCard; | ||
| }); | ||
|
|
||
| this.setState({ | ||
| cards: cards, | ||
| }); | ||
| }) | ||
|
|
||
| .catch((error) => { | ||
| let { errors } = this.state | ||
| errors.push(error.message) | ||
|
|
||
| this.setState({ | ||
| errors: errors | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a note you could do: this.setState({
errors,
}); |
||
| }) | ||
| }) | ||
| } | ||
|
|
||
| displayCards = () => { | ||
| return this.state.cards.map((card, i) => { | ||
| return <Card | ||
| key={i} | ||
| id={card.id} | ||
| text={card.text} | ||
| emoji={card.emoji} | ||
| deleteCardCallback={this.removeCard} | ||
| /> | ||
| }); | ||
| } | ||
|
|
||
| removeCard = (cardId) => { | ||
| console.log('where deleting happends') | ||
| let deleteIndex = -1; | ||
| const { cards } = this.state | ||
|
|
||
| cards.forEach((card, index) => { | ||
| if (cardId === card.id) { | ||
| deleteIndex = index; | ||
| } | ||
| }) | ||
|
|
||
| cards.splice(deleteIndex, 1); | ||
| this.setState({ | ||
| cards | ||
| }) | ||
|
|
||
|
|
||
| const url = 'https://inspiration-board.herokuapp.com/cards/' | ||
| axios.delete(url + cardId) | ||
| .then((response) => { | ||
| // let deletedCard = response.data.card | ||
|
|
||
| this.setState({ | ||
| errorMessage: `Card Deleted`, | ||
| }) | ||
| }) | ||
| .catch((error) => { | ||
| let { errors } = this.state | ||
| errors.push(error.message) | ||
|
|
||
| this.setState({ | ||
| errors: errors | ||
| }) | ||
| }) | ||
| } | ||
|
|
||
| addCard = (newCard) => { | ||
|
|
||
| const apiPayload = `text=${newCard.text}&emoji=${newCard.emoji}` | ||
|
|
||
| axios.post(this.props.url+this.props.boardName+'/cards?' + apiPayload) | ||
| .then((response) => { | ||
|
|
||
| let { cards } = this.state; | ||
| const newCard = response.data.card; | ||
|
|
||
| cards.push(newCard) | ||
|
|
||
| this.setState({ | ||
| cards: cards, | ||
| errorMessage: `Card Added` | ||
| }); | ||
| }) | ||
| .catch((error) => { | ||
| this.setState({ | ||
| errorMessage: `Failure ${error.message}` | ||
| }); | ||
| }) | ||
| } | ||
|
|
||
| render() { | ||
|
|
||
| return ( | ||
| <div> | ||
| Board | ||
| </div> | ||
| <section className="board"> | ||
| <section className="errorMessages"> | ||
| {this.state.errors ? `${this.state.errors}` : ""} | ||
| </section> | ||
| <section> | ||
| <NewCardForm addCardCallback={this.addCard}/> | ||
| </section> | ||
| {this.displayCards()} | ||
| </section> | ||
| ) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| Board.propTypes = { | ||
|
|
||
| url: PropTypes.string.isRequired, | ||
| boardName: PropTypes.string.isRequired | ||
| }; | ||
|
|
||
| export default Board; | ||
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,33 @@ | ||
| import React, { Component } from 'react'; | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import emoji from 'emoji-dictionary'; | ||
|
|
||
| import './Card.css'; | ||
|
|
||
| class Card extends Component { | ||
| render() { | ||
| const Card = (props) => { | ||
|
|
||
| return ( | ||
| <div className="card"> | ||
| Card | ||
| <section className="card__content"> | ||
| <p className="card__content-text">{props.text}</p> | ||
|
|
||
| {props.emoji && ( | ||
| <p className="card__content-emoji"> | ||
| {emoji.getUnicode(props.emoji)} | ||
| </p>)} | ||
|
|
||
| <button onClick={() => props.deleteCardCallback(props.id)} type="button" className="card__delete">X</button> | ||
| </section> | ||
| </div> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| Card.propTypes = { | ||
|
|
||
| Card.propTypes = { | ||
| id: PropTypes.number, | ||
| text: PropTypes.string, | ||
| emoji: PropTypes.string, | ||
| deleteCardCallback: PropTypes.func, | ||
| }; | ||
|
|
||
| export default Card; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ | |
| width: 50%; | ||
| margin: auto; | ||
| padding-bottom: 4rem; | ||
| padding-right: 4rem; | ||
|
|
||
| } | ||
|
|
||
| .new-card-form__header { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,75 @@ | ||
| import React, { Component } from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import emoji from 'emoji-dictionary'; | ||
| // import emoji from 'emoji-dictionary'; | ||
| import './NewCardForm.css'; | ||
|
|
||
| const EMOJI_LIST = ["", "heart_eyes", "beer", "clap", "sparkling_heart", "heart_eyes_cat", "dog"] | ||
|
|
||
| class NewCardForm extends Component { | ||
| constructor(props) { | ||
| super(props); | ||
|
|
||
| this.state = { | ||
| text: "", | ||
| emoji: "" | ||
| }; | ||
| } | ||
|
|
||
| resetState = () => { | ||
| this.setState({ | ||
| text: "", | ||
| emoji: "", | ||
| }) | ||
| } | ||
|
|
||
| onFormChange = (event) => { | ||
| const field = event.target.name; | ||
| const value = event.target.value | ||
|
|
||
| const updatedState = {}; | ||
| updatedState[field] = value; | ||
| this.setState(updatedState) | ||
| } | ||
|
|
||
| onNewCardSubmit = (event) => { | ||
| event.preventDefault(); | ||
|
|
||
| this.props.addCardCallback(this.state); | ||
| this.resetState(); | ||
| } | ||
|
|
||
| render() { | ||
|
|
||
| const emojiOptions = EMOJI_LIST.map((emoji, index) => { | ||
| return <option key={index} value={emoji}>{emoji}</option> | ||
| }) | ||
|
|
||
| return ( | ||
| <form className="" onSubmit={this.onNewCardSubmit}> | ||
| <header className="form-header">Add Inspiration Card</header> | ||
|
|
||
| <div> | ||
| <label className="" htmlFor="text">Text</label> | ||
| </div> | ||
| <textarea className="" placeholder="Text" name="text" onChange={this.onFormChange} value={this.state.text}></textarea> | ||
|
|
||
| <div> | ||
| <label className="">Emoji</label> | ||
| </div> | ||
| <select name="emoji" onChange={this.onFormChange} className=""> | ||
| {emojiOptions} | ||
| </select> | ||
|
|
||
| <section> | ||
| <input className="form-button" type="submit" value="Add Card"/> | ||
| </section> | ||
| </form> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| NewCardForm.propTypes = { | ||
| addCardCallback: PropTypes.func.isRequired, | ||
| }; | ||
|
|
||
| export default NewCardForm; |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import React from 'react'; | ||
| import Board from '../Board'; | ||
| import { shallow } from 'enzyme'; | ||
|
|
||
|
|
||
| describe('Board', () => { | ||
| it('test it matches and exisiting snapshot', () => { | ||
| const wrapper = shallow( | ||
| <Board | ||
| url="https://inspiration-board.herokuapp.com/boards/" | ||
| boardName={"maryam"} | ||
| />); | ||
|
|
||
| expect(wrapper).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import React from 'react'; | ||
| import Card from '../Card'; | ||
| import { shallow } from 'enzyme'; | ||
|
|
||
|
|
||
| describe('Card', () => { | ||
| it ('test it matches and exisiting snapshot', () => { | ||
| const wrapper = shallow( | ||
| <Card | ||
| id={1} | ||
| text="hello there" | ||
| emoji="heart_eyes" | ||
| deleteCardCallback={() => {}} | ||
| />); | ||
|
|
||
| expect(wrapper).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import React from 'react'; | ||
| import NewCardForm from '../NewCardForm'; | ||
| import { shallow } from 'enzyme'; | ||
|
|
||
|
|
||
| describe('NewCardForm', () => { | ||
| it('test it matches and exisiting snapshot', () => { | ||
| const wrapper = shallow( | ||
| <NewCardForm | ||
| addCardCallback={() => {}} | ||
| />); | ||
|
|
||
| expect(wrapper).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should also initialize
errorsto[].