Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import './App.css';
import Board from './components/Board';

class App extends Component {


render() {
return (
<section>
Expand All @@ -11,7 +13,7 @@ class App extends Component {
</header>
<Board
url="https://inspiration-board.herokuapp.com/boards/"
boardName={`Ada-Lovelace`}
boardName={`Jessie Zhang`}
/>
</section>
);
Expand Down
5 changes: 5 additions & 0 deletions src/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ describe('App', () => {
});

});

it('matches the snapshot', ()=>{
const wrapper = shallow(<App />);
expect(wrapper).toMatchSnapshot();
});
211 changes: 211 additions & 0 deletions src/__snapshots__/App.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`matches the snapshot 1`] = `
ShallowWrapper {
Symbol(enzyme.__root__): [Circular],
Symbol(enzyme.__unrendered__): <App />,
Symbol(enzyme.__renderer__): Object {
"batchedUpdates": [Function],
"getNode": [Function],
"render": [Function],
"simulateError": [Function],
"simulateEvent": [Function],
"unmount": [Function],
},
Symbol(enzyme.__node__): Object {
"instance": null,
"key": undefined,
"nodeType": "host",
"props": Object {
"children": Array [
<header
className="header"
>
<h1
className="header__h1"
>
<span
className="header__text"
>
Inspiration Board
</span>
</h1>
</header>,
<Board
boardName="Jessie Zhang"
url="https://inspiration-board.herokuapp.com/boards/"
/>,
],
},
"ref": null,
"rendered": Array [
Object {
"instance": null,
"key": undefined,
"nodeType": "host",
"props": Object {
"children": <h1
className="header__h1"
>
<span
className="header__text"
>
Inspiration Board
</span>
</h1>,
"className": "header",
},
"ref": null,
"rendered": Object {
"instance": null,
"key": undefined,
"nodeType": "host",
"props": Object {
"children": <span
className="header__text"
>
Inspiration Board
</span>,
"className": "header__h1",
},
"ref": null,
"rendered": Object {
"instance": null,
"key": undefined,
"nodeType": "host",
"props": Object {
"children": "Inspiration Board",
"className": "header__text",
},
"ref": null,
"rendered": "Inspiration Board",
"type": "span",
},
"type": "h1",
},
"type": "header",
},
Object {
"instance": null,
"key": undefined,
"nodeType": "class",
"props": Object {
"boardName": "Jessie Zhang",
"url": "https://inspiration-board.herokuapp.com/boards/",
},
"ref": null,
"rendered": null,
"type": [Function],
},
],
"type": "section",
},
Symbol(enzyme.__nodes__): Array [
Object {
"instance": null,
"key": undefined,
"nodeType": "host",
"props": Object {
"children": Array [
<header
className="header"
>
<h1
className="header__h1"
>
<span
className="header__text"
>
Inspiration Board
</span>
</h1>
</header>,
<Board
boardName="Jessie Zhang"
url="https://inspiration-board.herokuapp.com/boards/"
/>,
],
},
"ref": null,
"rendered": Array [
Object {
"instance": null,
"key": undefined,
"nodeType": "host",
"props": Object {
"children": <h1
className="header__h1"
>
<span
className="header__text"
>
Inspiration Board
</span>
</h1>,
"className": "header",
},
"ref": null,
"rendered": Object {
"instance": null,
"key": undefined,
"nodeType": "host",
"props": Object {
"children": <span
className="header__text"
>
Inspiration Board
</span>,
"className": "header__h1",
},
"ref": null,
"rendered": Object {
"instance": null,
"key": undefined,
"nodeType": "host",
"props": Object {
"children": "Inspiration Board",
"className": "header__text",
},
"ref": null,
"rendered": "Inspiration Board",
"type": "span",
},
"type": "h1",
},
"type": "header",
},
Object {
"instance": null,
"key": undefined,
"nodeType": "class",
"props": Object {
"boardName": "Jessie Zhang",
"url": "https://inspiration-board.herokuapp.com/boards/",
},
"ref": null,
"rendered": null,
"type": [Function],
},
],
"type": "section",
},
],
Symbol(enzyme.__options__): Object {
"adapter": ReactSixteenAdapter {
"options": Object {
"enableComponentDidUpdateOnSetState": true,
"lifecycles": Object {
"componentDidUpdate": Object {
"onSetState": true,
},
"getDerivedStateFromProps": true,
"getSnapshotBeforeUpdate": true,
"setState": Object {
"skipsComponentDidUpdateOnNullish": true,
},
},
},
},
},
}
`;
110 changes: 104 additions & 6 deletions src/components/Board.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,125 @@ import Card from './Card';
import NewCardForm from './NewCardForm';
import CARD_DATA from '../data/card-data.json';



class Board extends Component {
constructor() {
super();

this.state = {
cards: [],
};
}
};

componentDidMount(){

axios.get(`${this.props.url}${this.props.boardName}`+"/cards")
.then((response)=>{
const cards = response.data.map((cardObj)=>{
const newCard = {
...cardObj.card,
};
return newCard;
});
this.setState({
cards:cards,
});
})
.catch((error)=>{
this.setState({
errorMessage: error.message,
});
});
};

deleteCard = (cardId) => {
axios.delete("https://inspiration-board.herokuapp.com/cards/"+`${cardId}`)
.then(response =>{
const cardList =[...this.state.cards];
let deleteIndex = undefined;

cardList.forEach((card, index) => {
if (cardId === card.id) {
deleteIndex = index;
}
});

cardList.splice(deleteIndex, 1);

this.setState({
cards: cardList,

});
}).catch(error => {
console.log(error.message);
this.setState({
errorMessage: error.message
});
});


};

addCard = (newCard) => {
console.log("add card method");
const url = 'https://inspiration-board.herokuapp.com/boards/Jessie Zhang/cards';
axios.post(url, newCard)
.then((response)=>{
console.log("added");
const {cards} =this.state;

cards.push(newCard);

this.setState({
cards: cards,

});
})
.catch((error)=>{
this.setState({
errorMessage:`Failure ${error.message}`,
})
console.log(error)
});

};

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

return <Card
key={card.id}
id={card.id}
text={card.text}
emoji={card.emoji}
deleteCardCallback={this.deleteCard}
/>
});



return (

<div>
Board
<section>
{ this.state.errorMessage}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good that you're displaying an error message, might be better to give more details (validation errors etc).

</section>
<section className="board">
<span className="card">
<NewCardForm addCardCallback={this.addCard}/>
</span>
{cardList}
</section>
</div>
)
}
);

}
}
};

Board.propTypes = {

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

export default Board;
Loading