forked from AdaGold/inspiration-board
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Anne Watson - Octos - Inspiration Board #25
Open
annehwatson
wants to merge
12
commits into
Ada-C9:master
Choose a base branch
from
annehwatson: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
12 commits
Select commit
Hold shift + click to select a range
e9c0fea
initial install and hardcoded card
annehwatson a72dd0c
second card
annehwatson 2e03745
hardcoded data for real this time
annehwatson 999f0e5
emoji
annehwatson e1828c0
card styles
annehwatson de3e9c9
shallow tests
annehwatson aafcd9f
fixed addCard error by pushing the right item
annehwatson 0aadd1d
adding cardID as attribute on Card
annehwatson e365da8
deletion
annehwatson 94cb4cd
actual correct deletion
annehwatson 33dabaf
test for newCardForm
annehwatson f438817
changed mount to shallow in NewCardForm test
annehwatson 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
This file contains 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 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,33 +1,110 @@ | ||
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'; | ||
|
||
const CARDS_URL = 'https://inspiration-board.herokuapp.com/boards/watson/cards/' | ||
|
||
class Board extends Component { | ||
constructor() { | ||
constructor(props) { | ||
super(); | ||
|
||
this.state = { | ||
cards: [], | ||
cards: [] | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
this.props.updateStatusCallback("loading cards...", "success"); | ||
axios.get(CARDS_URL) | ||
.then((response) => { | ||
|
||
this.setState({ cards: response.data }); | ||
|
||
this.props.updateStatusCallback("successfully loaded cards", "success"); | ||
}) | ||
|
||
.catch((error) => { | ||
this.setState({ error: error.message }); | ||
|
||
this.props.updateStatusCallback(error.message, 'error'); | ||
|
||
this.setState({ | ||
status: { | ||
message: `Failed to load cards: ${error.message}`, | ||
type: 'error' | ||
} | ||
}) | ||
|
||
}); | ||
} | ||
|
||
|
||
addCard = (card) => { | ||
axios.post(CARDS_URL, card) | ||
.then((response) => { | ||
this.props.updateStatusCallback(`successfully added card ${ card.text }`, "success"); | ||
|
||
let updatedCards = this.state.cards; | ||
updatedCards.push(response.data); | ||
|
||
this.setState({ cards: updatedCards }); | ||
}) | ||
.catch((error) => { | ||
this.props.updateStatusCallback(`Error adding card ${ card.name }`, 'error'); | ||
}); | ||
} | ||
|
||
deleteCard = (cardID) => { | ||
axios.delete(CARDS_URL + cardID) | ||
.then((response) => { | ||
this.props.updateStatusCallback(`successfully deleted card`, "success"); | ||
|
||
let updatedCards = this.state.cards | ||
|
||
let targetCard = updatedCards.findIndex((card) => { | ||
return card.card.id === cardID; | ||
}); | ||
|
||
updatedCards.splice(targetCard, 1) | ||
|
||
this.setState({ cards: updatedCards }); | ||
|
||
}) | ||
.catch((error) => { | ||
this.props.updateStatusCallback(`Error deleting card`, "error"); | ||
}); | ||
} | ||
|
||
render() { | ||
const cards = this.state.cards.map((cardObj, index) => { | ||
return( | ||
<Card key={index} | ||
text={cardObj.card.text} | ||
emoji={cardObj.card.emoji} | ||
cardID={cardObj.card.id} | ||
deleteCardCallback={this.deleteCard} | ||
/> | ||
) | ||
}); | ||
|
||
return ( | ||
<div> | ||
Board | ||
<div className="board"> | ||
<NewCardForm | ||
addCardCallback={this.addCard} | ||
/> | ||
{ cards } | ||
</div> | ||
) | ||
} | ||
|
||
} | ||
|
||
Board.propTypes = { | ||
|
||
updateStatusCallback: PropTypes.func.isRequired | ||
}; | ||
|
||
export default Board; |
This file contains 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,14 @@ | ||
import React from 'react'; | ||
import Board from './Board'; | ||
import { mount, shallow } from 'enzyme'; | ||
|
||
describe('Board', () => { | ||
test('shallow mount', () => { | ||
const board = shallow( | ||
<Board updateStatusCallback={() => {}} /> | ||
); | ||
|
||
expect(board).toMatchSnapshot(); | ||
}); | ||
|
||
}); |
This file contains 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,44 @@ | ||
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 { | ||
class Card extends React.Component { | ||
constructor(props) { | ||
super(); | ||
} | ||
|
||
onDelete = (event) => { | ||
event.preventDefault(); | ||
let cardID = this.cardID; | ||
this.props.deleteCardCallback(this.props.cardID); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div className="card"> | ||
Card | ||
</div> | ||
<section> | ||
<div className="card"> | ||
<button className="card__delete" onClick={this.onDelete}>Delete Card</button> | ||
<div className="card__content"> | ||
<div className="card__content-text">{this.props.text}</div> | ||
<div className="card__content-emoji">{this.getEmoji(this.props.emoji)}</div> | ||
</div> | ||
</div> | ||
</section> | ||
) | ||
} | ||
|
||
getEmoji = (emojicon) => { | ||
return emoji.getUnicode(emojicon) | ||
} | ||
} | ||
|
||
Card.propTypes = { | ||
|
||
text: PropTypes.string, | ||
emoji: PropTypes.string, | ||
cardID: PropTypes.number, | ||
deleteCard: PropTypes.func | ||
}; | ||
|
||
export default Card; |
This file contains 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,15 @@ | ||
import React from 'react'; | ||
import Card from './Card'; | ||
import { mount, shallow } from 'enzyme'; | ||
|
||
describe('Card', () => { | ||
test('shallow mount', () => { | ||
const card = mount( | ||
<Card text="test text" emoji="grinning" /> | ||
); | ||
|
||
expect(card).toMatchSnapshot(); | ||
|
||
card.unmount(); | ||
}); | ||
}); |
This file contains 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 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,51 @@ | ||
import React from 'react'; | ||
import NewCardForm from './NewCardForm'; | ||
import { mount, shallow } from 'enzyme'; | ||
|
||
describe('NewCardForm', () => { | ||
test('that it matches an existing snapshot', () => { | ||
const cardForm = shallow( <NewCardForm addCardCallback={() => {} } />); | ||
|
||
expect(cardForm).toMatchSnapshot(); | ||
|
||
// cardForm.unmount(); | ||
}); | ||
|
||
test('Invokes callback on form submission', () => { | ||
const callback = jest.fn(); | ||
const cardForm = shallow( | ||
<NewCardForm addCardCallback={ callback } /> | ||
); | ||
|
||
cardForm.find('form').simulate('submit', { | ||
preventDefault: () => {} | ||
}); | ||
|
||
expect(callback).toHaveBeenCalled(); | ||
expect(callback.mock.calls[0][0]).toEqual({ | ||
text: '', | ||
emoji: '' | ||
}); | ||
}); | ||
|
||
test('Keeps track of user input', () => { | ||
const value = "new text value" | ||
const cardForm = shallow( | ||
<NewCardForm addCardCallback={() => {} } /> | ||
); | ||
|
||
let textInput = cardForm.find('input[name="text"]'); | ||
textInput.simulate('change', { | ||
target: { | ||
name: "text", | ||
value: value | ||
} | ||
}); | ||
|
||
cardForm.update(); | ||
|
||
textInput = cardForm.find('input[name="text"]'); | ||
|
||
expect(textInput.getElement().props.value).toEqual("new text value"); | ||
}); | ||
}); |
This file contains 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,21 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
class Status extends React.Component { | ||
static propTypes = { | ||
message: PropTypes.string, | ||
type: PropTypes.string | ||
} | ||
|
||
render() { | ||
|
||
return ( | ||
<section className={`status ${this.props.type}`}> | ||
{ this.props.message } | ||
</section> | ||
); | ||
} | ||
} | ||
|
||
|
||
export default Status; |
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.
The emoji input should be a dropdown menu - otherwise how will the user know what their options are?