diff --git a/src/App.js b/src/App.js index c4854e15..aed4b578 100644 --- a/src/App.js +++ b/src/App.js @@ -3,6 +3,7 @@ import './App.css'; import Board from './components/Board'; class App extends Component { + render() { return (
@@ -11,7 +12,7 @@ class App extends Component {
); diff --git a/src/components/Board.js b/src/components/Board.js index 9222fd88..5e3973f1 100644 --- a/src/components/Board.js +++ b/src/components/Board.js @@ -13,21 +13,105 @@ class Board extends Component { this.state = { cards: [], + errorMessage: null, + }; } + + componentDidMount() { + const myURL = this.props.url + this.props.boardName + "/cards"; + axios.get(myURL) + .then((response) => { + console.log(response.data); + const cards = response.data.map((info) => { + const newCard = { + text: info.text, + emoji: info.emoji, + id: info.id + } + return newCard; + }) + this.setState({ + cards + }); + }) + .catch((error) => { + this.setState({ errorMessage: error.message }) + }); + } + + onDeleteCard =(id) => { + const myURL = this.props.url + this.props.boardName + "/cards"; + const updatedCards = this.state.cards.filter(card => card.id !== id); + + this.setState({ + cards: updatedCards + }) + + axios.delete(myURL/`${id}`) + .then((response) => { + console.log('Card deleted id:', response.data.card.id) + }) + .catch((error) => { + this.setState({ + errorMessage: error.message + }) + }) + + + } + //from Ada Pets + addCardCallback = (card) => { + const myURL = this.props.url + this.props.boardName + "/cards"; + + axios.post(myURL, card) + .then((response) => { + const info = response.data["card"] + let updatedCard = this.state.cards; + updatedCard.push({ + id: info.id, + text: card.text, + emoji: card.emoji + }); + this.setState({cards: updatedCard}); + }) + .catch((error) => { + this.setState({ errorMessage: error.message }) + }); + } + render() { + const displayCards = this.state.cards.map((card, i) => { + return () + }) + + const errors = this.state.error; return ( -
- Board -
+
+
+ {errors ? errors : this.state.message} +
+
+ + {displayCards} +
+
+ ) } } Board.propTypes = { - + boardName: PropTypes.string, + myUrl: PropTypes.string.isRequired, }; export default Board; diff --git a/src/components/Card.js b/src/components/Card.js index 6788cc03..63041ffe 100644 --- a/src/components/Card.js +++ b/src/components/Card.js @@ -3,18 +3,36 @@ import PropTypes from 'prop-types'; import emoji from 'emoji-dictionary'; import './Card.css'; +import Axios from 'axios'; class Card extends Component { + render() { + const id = this.props.id + const emojis = (this.props.emoji) ? this.props.emoji : "" return (
- Card +
+
+ {this.props.text} +
+
+ {emoji.getUnicode(emojis)} +
+
+ +
+
) } } Card.propTypes = { + id: PropTypes.number, + text: PropTypes.string, + emoji: PropTypes.string, }; diff --git a/src/components/NewCardForm.js b/src/components/NewCardForm.js index 47331423..8d068622 100644 --- a/src/components/NewCardForm.js +++ b/src/components/NewCardForm.js @@ -4,3 +4,72 @@ 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: "", + emoi: "", + } + } + + onCardChange = (event) => { + const updateCardState = {}; + + const field = event.target.name; + const value = event.target.value; + + updateCardState[field] = value; + this.setState(updateCardState); + } + + addCardSubmit = (event) => { + event.preventDefault(); + const addCard = { + text: this.state.text, + emoji: this.state.emoji, + } + this.props.addCardCallback(addCard) + + this.clearForm() + } + + clearForm = () => { + this.setState({ + text: "", + emoji: "", + }) + } + + render() { + return ( +
+
+
+ What Inspires You? +
+
+ +
+