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

Sockets - Jansen #36

Open
wants to merge 62 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
bab1f2e
Initialize project; Add board name
JansenMartin Jun 20, 2019
5a7cc95
Add card data to Board state. Render card data
JansenMartin Jun 20, 2019
296d5a8
Revise mapping of card data to correctly pass text
JansenMartin Jun 20, 2019
64059b2
Revise componentDidMount method
JansenMartin Jun 21, 2019
d334f76
Add conditionals accounting for undefined values inside cards
JansenMartin Jun 21, 2019
58e8b1a
Change render to only show emoji, and not text
JansenMartin Jun 21, 2019
2583879
Prepare for merge
JansenMartin Jun 21, 2019
03a8fa0
Account for card.Emoji in hardcoded data
JansenMartin Jun 21, 2019
671700e
Install axios
JansenMartin Jun 21, 2019
1348019
Set up request with axios
JansenMartin Jun 21, 2019
b265b08
Add functionality that pulls cards from API; add logic to conditional…
JansenMartin Jun 21, 2019
f0fb5e8
Add API functionality for my specific board by using props
JansenMartin Jun 21, 2019
1851478
Add delete button to card
JansenMartin Jun 21, 2019
e79c61a
Add event handler to delete button
JansenMartin Jun 21, 2019
079db06
Add deleteCard function to Card as prop
JansenMartin Jun 21, 2019
892506d
Adjust callback function's position inside Board; Add callback functi…
JansenMartin Jun 21, 2019
511945a
Add card id to cards
JansenMartin Jun 21, 2019
4df86b9
Pass card id as prop
JansenMartin Jun 21, 2019
849fc88
Add card id to delete button
JansenMartin Jun 21, 2019
774234d
Pass card id through callback function to Board.js
JansenMartin Jun 21, 2019
7c7d334
Clean up comments
JansenMartin Jun 21, 2019
6cf1b3b
Add functionality to delete card from API
JansenMartin Jun 21, 2019
05cb47a
Update deleteCard function to update Board state
JansenMartin Jun 21, 2019
efa3699
Create class for NewCardForm
JansenMartin Jun 21, 2019
3bdb07c
Start building form
JansenMartin Jun 21, 2019
36b29ac
Add event handler to form submit button; Add preventDefault method
JansenMartin Jun 21, 2019
8c02af5
Add callback function to Board; Move newCardForm to Board
JansenMartin Jun 21, 2019
5a7855b
Pass addCardCallback as props to NewCardForm
JansenMartin Jun 21, 2019
2362200
Add state to NewCardForm
JansenMartin Jun 23, 2019
b9ac743
Add onChange event handler to textarea
JansenMartin Jun 23, 2019
0e07490
Add name and value to textarea
JansenMartin Jun 23, 2019
a868ed8
Update text state to reflect value of textarea
JansenMartin Jun 23, 2019
b180897
Pass new card info via addCardCallback
JansenMartin Jun 23, 2019
1e6bfc2
Add POST request for new card
JansenMartin Jun 23, 2019
fa0ab52
Add index prop to card
JansenMartin Jun 23, 2019
37c14d9
Adjust PropTypes to account for numbers
JansenMartin Jun 23, 2019
ac841c3
Assign ID to generated card; Pass index into deleteCard callback
JansenMartin Jun 23, 2019
436f310
Install library for testing
JansenMartin Jun 23, 2019
e6d2f42
Tell Jest how to serialize enzyme data
JansenMartin Jun 23, 2019
f4bb512
Revise file to match lecture notes
JansenMartin Jun 23, 2019
5e29ff9
Add snapshop test
JansenMartin Jun 23, 2019
65a8a98
Add test file for Card component
JansenMartin Jun 23, 2019
a417b60
Add test for Card component
JansenMartin Jun 23, 2019
b1632c5
Add propTypes to Board component
JansenMartin Jun 24, 2019
b8ef581
Deconstruct props inside component DidMount
JansenMartin Jun 24, 2019
8001846
Deconstruct props inside addCard
JansenMartin Jun 24, 2019
9789f5f
Clean up comments
JansenMartin Jun 24, 2019
cd13a6c
Clean up comments
JansenMartin Jun 24, 2019
ad13f3b
Require addCardCallback inside of NewCardForm component
JansenMartin Jun 24, 2019
dfe4707
Add emoji options to newCardForm component
JansenMartin Jun 24, 2019
4bb08d4
Add name ref to select element
JansenMartin Jun 24, 2019
c22126b
Add error state to Board component; Comment out unused CARD_DATA
JansenMartin Jun 24, 2019
650e6f9
Revise error message inside componentDidMount
JansenMartin Jun 24, 2019
aa7f465
Add error message to addCard function
JansenMartin Jun 24, 2019
cd656ec
Add error message to deleteCard
JansenMartin Jun 24, 2019
81a4d49
Add place for validation errors
JansenMartin Jun 24, 2019
d47a5fd
Add this.state.errors to validation errors section
JansenMartin Jun 24, 2019
6c85619
Comment unused NewCardForm inside App
JansenMartin Jun 24, 2019
1c49e9c
Add class names to emoji and text inside Card
JansenMartin Jun 24, 2019
c34f067
Remove comments
JansenMartin Jun 24, 2019
ac18d46
Remove comments and console.log functions
JansenMartin Jun 24, 2019
a457589
Update snapshots
JansenMartin Jun 24, 2019
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
16 changes: 9 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
"devDependencies": {
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.14.0",
"enzyme-to-json": "^3.3.5",
"gh-pages": "^2.0.1"
},
"jest": {
"snapshotSerializers": ["enzyme-to-json/serializer"]
}
}
3 changes: 2 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component } from 'react';
import './App.css';
import Board from './components/Board';
// import NewCardForm from './components/NewCardForm';

class App extends Component {
render() {
Expand All @@ -11,7 +12,7 @@ class App extends Component {
</header>
<Board
url="https://inspiration-board.herokuapp.com/boards/"
boardName={`Ada-Lovelace`}
boardName={`jansen-martin`}
/>
</section>
);
Expand Down
3 changes: 3 additions & 0 deletions src/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ describe('App', () => {
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);

console.log(div.innerHTML);

ReactDOM.unmountComponentAtNode(div);
});

Expand Down
105 changes: 102 additions & 3 deletions src/components/Board.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,128 @@ 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: [],
error: "",
};

}

componentDidMount() {
const { url, boardName } = this.props;

const getURL = url + boardName + "/cards";

axios.get(getURL)
.then((response) => {

const cardList = response.data.map((card) => {


const newCard = {
id: card.card.id,
text: card.card.text,
emoji: card.card.emoji,
}

return newCard;
})

this.setState({ cards: cardList });

})
.catch((error) => {
this.setState({ error: `${error.message} while loading your cards!` });
});
}

addCard = (cardInfo) => {

const { url, boardName } = this.props;
const postURL = url + boardName + "/cards";

axios.post(postURL, cardInfo)
.then((response) => {
cardInfo.id = response.data.card.id;
let updatedCards = [...this.state.cards];
updatedCards.push(cardInfo);
this.setState({cards: updatedCards});

})
.catch((error) => {
this.setState({ error: `${error.message} while adding your card!` })
})
}


deleteCard = (index) => {

let updatedCards = this.state.cards;
let id = updatedCards[index].id;

const deleteUrl = "https://inspiration-board.herokuapp.com/cards/" + id;

axios.delete(deleteUrl)
.then((response) => {

updatedCards.splice(index, 1);

this.setState({
cards: updatedCards,
});

})
.catch((error) => {
this.setState({ error: `${error.message} while deleting your card!`})
})
};


render() {
const cards = this.state.cards.map((card, i) => {

return (
<li key={i}>
<Card
id={card.id}
index={i}
quote={card.text}
emoji={card.emoji}
deleteCardCallback={this.deleteCard} />
</li>
);
});


return (
<section>

<div className="validation-errors-display validation-errors-display__list">
{this.state.errors}
</div>

<div className="board">
{cards}
</div>

<div>
Board
<NewCardForm addCardCallback={this.addCard}/>
</div>
</section>
)
}

}

Board.propTypes = {

url: PropTypes.string,
boardName: PropTypes.string,
};

export default Board;
Empty file removed src/components/Board.test.js
Empty file.
19 changes: 15 additions & 4 deletions src/components/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,28 @@ import emoji from 'emoji-dictionary';
import './Card.css';

class Card extends Component {

onDeleteButtonClick = (event) => {
this.props.deleteCardCallback(this.props.index);
}
render() {

return (
<div className="card">
Card
</div>
<section className="card">
<div className="card__content-text card__content">{this.props.quote}</div>
<div className="card__content-emoji card__content">{this.props.emoji && emoji.getUnicode(this.props.emoji)}</div>
{<button id={this.props.id} className="card__delete" onClick={this.onDeleteButtonClick}>Delete</button>}
</section>
)
}
}

Card.propTypes = {

id: PropTypes.number,
index: PropTypes.number,
quote: PropTypes.string,
emoji: PropTypes.string,
deleteCardCallback: PropTypes.func,
};

export default Card;
97 changes: 97 additions & 0 deletions src/components/NewCardForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,100 @@ 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: "",
}
}


onSubmitCardButtonClick = (event) => {
event.preventDefault();

const newCard = {
text: this.state.text,
emoji: this.state.emoji
};

this.setState({
text: "",
emoji: ""
})

this.props.addCardCallback(newCard);
}

onInputChange = (event) => {
const updatedCard = {};

const field = event.target.name;
const value = event.target.value;

console.log(event.target.name);
console.log(event.target.value);

updatedCard[field] = value;
this.setState(updatedCard);
}

emojiList = () => {
return EMOJI_LIST.map((emojiChoice, i) => {
return <option key={ i } value={ emojiChoice }>{ emoji.getUnicode(emojiChoice) }</option>
});
}

render() {

const { text, emoji } = this.state;

return (
<div className="new-card-form">
<h3 className="new-card-form__header">Submit a New Card</h3>
<form className="new-card-form__form">

<div>
<textarea
name="text"
value={text}
onChange={this.onInputChange}
className="new-card-form__form-textarea"
placeholder="Enter Stuff Here">
</textarea>
</div>

<div>
<label
className="new-card-form__form-label"
htmlFor="emoji">
Emoji
</label>
<select
className="new-card-form_form-select"
onChange={this.onInputChange}
name="emoji"
value={emoji}>
{this.emojiList()}
</select>
</div>

<div>
<input onClick={this.onSubmitCardButtonClick} className="new-card-form__form-button" type="submit" value="Submit Card" />
</div>

</form>
</div>
)
}
}

export default NewCardForm;

NewCardForm.propTypes = {
addCardCallback: PropTypes.func.isRequired,
};
Empty file removed src/components/NewCardForm.test.js
Empty file.
14 changes: 14 additions & 0 deletions src/components/test/Card.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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 deleteCardCallback={() => {} } />);

// Assert that it looks like the last snapshot
expect(wrapper).toMatchSnapshot();
});
});
16 changes: 16 additions & 0 deletions src/components/test/NewCardForm.test.js
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', () => {
test('that it matches an existing snapshot', () => {
// First Mount the Component in the testing DOM
// Arrange
const wrapper = shallow( <NewCardForm addCardCallback={() => {} } />);

// Assert that it looks like the last snapshot
expect(wrapper).toMatchSnapshot();
});
});


20 changes: 20 additions & 0 deletions src/components/test/__snapshots__/Card.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Card that it matches an existing snapshot 1`] = `
<section
className="card"
>
<div
className="card__content-text card__content"
/>
<div
className="card__content-emoji card__content"
/>
<button
className="card__delete"
onClick={[Function]}
>
Delete
</button>
</section>
`;
Loading