-
Notifications
You must be signed in to change notification settings - Fork 45
Sigrid Benezra - Edges - Inspiration Board #20
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,18 +4,33 @@ import emoji from 'emoji-dictionary'; | |
|
|
||
| import './Card.css'; | ||
|
|
||
|
|
||
| class Card extends Component { | ||
|
|
||
| render() { | ||
| const deleteCard = () => { | ||
| console.log(`This is the index from card props: ${this.props.index}`); | ||
| console.log(`This is the id from card props: ${this.props.id}`); | ||
| this.props.onDeleteCallback(this.props.index, this.props.id); | ||
| } | ||
|
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. It might make more sense to define this function |
||
| return ( | ||
| <div className="card"> | ||
| Card | ||
| <div className="card__content"> | ||
| <p className="card__content-text">{this.props.text}</p> | ||
| <p className="card__content-emoji">{emoji.getUnicode(`${this.props.emoji}`)}</p> | ||
| <button onClick={deleteCard} className="card__delete">Delete</button> | ||
| </div> | ||
| </div> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| Card.propTypes = { | ||
|
|
||
| onDeleteCallback: PropTypes.func, | ||
|
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. Would expect index, id, text, and emoji to be declared in propTypes |
||
| id: PropTypes.number, | ||
| text: PropTypes.string, | ||
| emoji: PropTypes.string, | ||
| index: PropTypes.number, | ||
| }; | ||
|
|
||
| export default Card; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,81 @@ | ||
| 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 { | ||
| static propTypes = { | ||
| addCardCallback: PropTypes.func.isRequired | ||
| }; | ||
|
|
||
| constructor(props) { | ||
| super(props); | ||
|
|
||
| this.state = { | ||
| cards:[{ | ||
| cardID: { | ||
| card: {text: '', emoji: '',} | ||
| } | ||
| }] | ||
| } | ||
| } | ||
|
|
||
| onInputChange = (event) => { | ||
| const field = event.target.name; | ||
| const value = event.target.value; | ||
|
|
||
| const newState = {}; | ||
| newState[field] = value; | ||
| this.setState(newState) | ||
| } | ||
|
|
||
| resetState = () => { | ||
| this.setState({ | ||
| cards:[{cardID: {card: {text: '', emoji: '',}}}] | ||
| }); | ||
| } | ||
|
|
||
|
|
||
| onFormSubmit = (event) => { | ||
| event.preventDefault(); | ||
|
|
||
| const card = { | ||
| text: this.state.message, | ||
| emoji: this.state.emoji, | ||
| } | ||
| this.resetState(); | ||
| this.props.addCardCallback(card) | ||
| } | ||
|
|
||
| render() { | ||
| const emojiList = EMOJI_LIST.map((item, i) => { | ||
| return <option key={i} value={item}>{item}</option> | ||
| }); | ||
|
|
||
| return( | ||
| <form onSubmit={this.onFormSubmit} className="new-card-form" > | ||
| <header className="new-card-form__header"> | ||
| Add a New Card! | ||
| </header> | ||
| <p></p> | ||
| <section> | ||
| <label htmlFor="message" className="new-card-form__form-label">Your Message</label> | ||
| <input name="message" type="text" value={this.state.message} onChange={this.onInputChange} className="new-card-form__form-textarea"/> | ||
| <select onChange={this.onInputChange} name="emoji" className="new-card-form__form-select"> | ||
| {emojiList} | ||
| </select> | ||
| </section> | ||
| <p></p> | ||
| <input type="submit" value="Add message" className="new-card-form__form-button" /> | ||
| </form> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| NewCardForm.propTypes = { | ||
| addCardCallback: PropTypes.func, | ||
| }; | ||
|
|
||
| export default NewCardForm; |
| 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', () => { | ||
| test('that it matches an existing snapshot', () => { | ||
| // First Mount the Component in the testing DOM | ||
| // Arrange | ||
| const wrapper = shallow( | ||
| <Card | ||
| text = 'text' | ||
| emoji = 'emoji' | ||
| /> | ||
| ); | ||
|
|
||
| // Assert that it looks like the last snapshot | ||
| expect(wrapper).toMatchSnapshot(); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import React from 'react'; | ||
| import NewCardForm from '../NewCardForm'; | ||
| import { shallow } from 'enzyme'; | ||
|
|
||
| describe('New Card Form', () => { | ||
| test('that it matches an existing snapshot', () => { | ||
| // First Mount the Component in the testing DOM | ||
| // Arrange | ||
| const wrapper = shallow( | ||
| <NewCardForm | ||
| message = 'message' | ||
| emoji = 'emoji' | ||
| /> | ||
| ); | ||
|
|
||
| // Assert that it looks like the last snapshot | ||
| expect(wrapper).toMatchSnapshot(); | ||
| }); | ||
| }); |
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.
Hm, it'd be nice if you could have used the props
boardNameandurlwith this too