diff --git a/src/components/Board.js b/src/components/Board.js index 9222fd88..03d60cae 100644 --- a/src/components/Board.js +++ b/src/components/Board.js @@ -16,10 +16,71 @@ class Board extends Component { }; } + componentDidMount() { + axios.get('https://inspiration-board.herokuapp.com/boards/ultra_princess/cards') + .then((res) => { + this.setState({ cards: res.data }) + }) + .catch((error) => { + alert('hm ur cards didnt load maybe u should refresh lol'); + }); + } + + delCard = (id) => { + const url = 'https://inspiration-board.herokuapp.com/cards/' + id.toString(); + + axios.delete(url) + .then(() => { + let index; + let newState = this.state; + + newState.cards.forEach((card, i) => { + if (card.card.id === id) { + index = i; + } + }); + + newState.cards.splice(index, 1); + + this.setState(newState); + }) + .catch((e) => { + alert('sry could not delete ?? idk tbh..'); + console.log(e); + }); + } + + addCard = (newCard) => { + const url = `https://inspiration-board.herokuapp.com/boards/ultra_princess/cards?text=${newCard.text}&emoji=${newCard.emoji}`; + + axios.post(url) + .then((res) => { + let newState = this.state; + newState.cards.push(res.data); + + this.setState(newState); + }) + .catch((e) => { + alert('sry could not add card ?? idk tbh..'); + console.log(e); + }); + } + render() { + const cards = this.state.cards.map((e, i) => { + return ( + + ) + }); + return ( -
- Board +
+ { cards } +
) } diff --git a/src/components/Card.js b/src/components/Card.js index 6788cc03..827fd2f8 100644 --- a/src/components/Card.js +++ b/src/components/Card.js @@ -8,7 +8,11 @@ class Card extends Component { render() { return (
- Card +
+

{ this.props.text }

+

{ this.props.emoji ? emoji.getUnicode(this.props.emoji) : "" }

+ +
) } diff --git a/src/components/NewCardForm.js b/src/components/NewCardForm.js index 47331423..2daa688a 100644 --- a/src/components/NewCardForm.js +++ b/src/components/NewCardForm.js @@ -4,3 +4,69 @@ 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: '', + }; + } + + resetState = () => { + this.setState({ + text: '', + emoji: '', + }); + } + + onFormChange = (event) => { + const field = event.target.name; + const value = event.target.value; + + const updatedState = {}; + updatedState[field] = value; + this.setState(updatedState); + } + + onSubmit = (event) => { + event.preventDefault(); + const { text, emoji } = this.state; + const newCard = { text: text, emoji: emoji }; + + this.props.addCB(newCard); + } + + render() { + return( +
+

+ Add a Card! +

+
+ +