From a8bb387487ece62a572f68b9fdbfbd32e19d3aa2 Mon Sep 17 00:00:00 2001 From: Victoria Garcia Date: Sat, 16 Jun 2018 22:10:47 -0700 Subject: [PATCH 01/13] Card component is working with default props, and rendering appropriately on the board. --- src/App.js | 9 ++++++++- src/components/Board.js | 10 ++++++++-- src/components/Card.js | 37 +++++++++++++++++++++++++++++++++++-- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/App.js b/src/App.js index c4854e15..036a87da 100644 --- a/src/App.js +++ b/src/App.js @@ -1,8 +1,14 @@ import React, { Component } from 'react'; import './App.css'; +import Card from './components/Card'; import Board from './components/Board'; class App extends Component { + + constructor(props) { + super(props); + } + render() { return (
@@ -11,8 +17,9 @@ class App extends Component { +
); } diff --git a/src/components/Board.js b/src/components/Board.js index 9222fd88..928388bd 100644 --- a/src/components/Board.js +++ b/src/components/Board.js @@ -12,14 +12,20 @@ class Board extends Component { super(); this.state = { - cards: [], + cards: [ + , + , + , + ], }; } + + render() { return (
- Board + {this.state.cards}
) } diff --git a/src/components/Card.js b/src/components/Card.js index 6788cc03..ba1b1b53 100644 --- a/src/components/Card.js +++ b/src/components/Card.js @@ -5,17 +5,50 @@ import emoji from 'emoji-dictionary'; import './Card.css'; class Card extends Component { + + constructor(props) { + super(props); + this.state = { + cardText: "INSPIRATION! THAT'S WHAT THIS IS!", + cardEmoji: emoji.getUnicode('heart') + } + } + + tick() { + this.setState({count: this.state.count + 1}); + } + + addCardEmoji = (emoji) => { + if (this.props.emojiDesc){ + this.setState( + { + cardEmoji: emoji.getUnicode(this.props.emojiDesc) + } + ); + } + } + render() { return (
- Card +
+
+

{this.state.cardText}

+

WHATEVER

+
+
+ {emoji.getUnicode('grimacing')} +

{this.state.cardEmoji}

+
+
) } } Card.propTypes = { - + cardText: PropTypes.string.isRequired, + emojiDesc: PropTypes.string, }; export default Card; From 61f6ae496ec10ebeff565ab1ac968c5d984956ef Mon Sep 17 00:00:00 2001 From: Victoria Garcia Date: Sat, 16 Jun 2018 23:13:04 -0700 Subject: [PATCH 02/13] Conditional rendering for emojis now is working. --- README.md | 40 ++++++++++++++++++++++++++++++++++++++++ src/components/Board.js | 38 ++++++++++++++++++++++++++++++++------ src/components/Card.js | 33 ++++++++++----------------------- 3 files changed, 82 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 1ef9a904..d03ae082 100644 --- a/README.md +++ b/README.md @@ -75,3 +75,43 @@ Possible optional enhancements include: ## What we're looking for You can see what your instructors are looking for [here](./feedback.md) + + +#### CODE PARKING LOT: + +render() { + return ( +
+
+
+

{this.props.cardText}

+
+
+ {this.addCardEmoji} +
+
+
+ ) +} +} + + + +constructor(props) { + super(props); + + this.state = { + cardText: this.props.cardText, + } +} + + +addCardEmoji = (emoji) => { + if (this.props.emojiDesc){ + this.setState( + { + cardEmoji: emoji.getUnicode(this.props.emojiDesc) + } + ); + } +} diff --git a/src/components/Board.js b/src/components/Board.js index 928388bd..aa3965a7 100644 --- a/src/components/Board.js +++ b/src/components/Board.js @@ -1,7 +1,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; +import emoji from 'emoji-dictionary'; import axios from 'axios'; - import './Board.css'; import Card from './Card'; import NewCardForm from './NewCardForm'; @@ -13,19 +13,45 @@ class Board extends Component { this.state = { cards: [ - , - , - , + { + inspoText: 'Be Here Now.', + + }, + { + inspoText: 'Ok, now be somewhere else', + + }, + { + inspoText: 'Being present in the present is the greatest present you can give yourself', + inspoEmoji: 'gift', + }, ], }; } - render() { + + console.log("In render function, this is the current set of cards, before converting to card components:"); + + console.log(this.state.cards); + + const cardComponents = this.state.cards.map((card, index) => { + return ( +
  • + +
  • + ); + }); + return (
    - {this.state.cards} +
      + {cardComponents} +
    ) } diff --git a/src/components/Card.js b/src/components/Card.js index ba1b1b53..91333711 100644 --- a/src/components/Card.js +++ b/src/components/Card.js @@ -8,37 +8,24 @@ class Card extends Component { constructor(props) { super(props); - this.state = { - cardText: "INSPIRATION! THAT'S WHAT THIS IS!", - cardEmoji: emoji.getUnicode('heart') - } - } - - tick() { - this.setState({count: this.state.count + 1}); - } - - addCardEmoji = (emoji) => { - if (this.props.emojiDesc){ - this.setState( - { - cardEmoji: emoji.getUnicode(this.props.emojiDesc) - } - ); - } } render() { + + const hasEmoji = this.props.cardEmoji; + let displayEmoji; + if (hasEmoji) { + displayEmoji = emoji.getUnicode(this.props.cardEmoji) + } else { displayEmoji = "" } + return (
    -

    {this.state.cardText}

    -

    WHATEVER

    +

    {this.props.cardText}

    - {emoji.getUnicode('grimacing')} -

    {this.state.cardEmoji}

    +

    {displayEmoji}

    @@ -48,7 +35,7 @@ class Card extends Component { Card.propTypes = { cardText: PropTypes.string.isRequired, - emojiDesc: PropTypes.string, + cardEmoji: PropTypes.string, }; export default Card; From 7aac8568b849fbec289101c000d52fd129c3c707 Mon Sep 17 00:00:00 2001 From: Victoria Garcia Date: Sun, 17 Jun 2018 02:40:08 -0700 Subject: [PATCH 03/13] Pulling down cards from the API and displaying them nicely. --- README.md | 73 +++++++++++++++++++++++++++++++++++++++++ src/components/Board.js | 67 ++++++++++++++++++++++--------------- src/components/Card.js | 9 +++-- 3 files changed, 118 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index d03ae082..67627304 100644 --- a/README.md +++ b/README.md @@ -115,3 +115,76 @@ addCardEmoji = (emoji) => { ); } } + + +componentDidMount() { + axios.get(`https://jsonplaceholder.typicode.com/users`) + .then(res => { + const persons = res.data; + this.setState({ persons }); + }) +} + +const cardComponents = Object.keys(this.state.cards).map(card => + ({ + cardId: card["id"], + cardText: card["text"], + cardEmoji: card["emoji"], + }) +) + + + +render() { + return ( +
    + {Object.keys(this.state.dataGoal.milestones).map((milestone) =>{ + return {this.state.dataGoal.milestones[milestone].tasks.map((task, idx)=>{ + return ( + //whatever you wish to do with the task item + ) +}) + })} + +
    + ) +} + +const cardComponents = this.state.cards.map((card, index) => { + return ( +
  • + +
  • + ); +}); + +axios.get(allTripsUrl) + .then((response) => { + reportStatus(`Successfully loaded ${response.data.length} trips`); + response.data.forEach((trip) => { + allTrips.append(`
  • ${trip.name}
  • `); + }); + }) + .catch((error) => { + reportStatus(`Encountered an error while loading trips: ${error.message}`); + console.log(error); + }); +}; + + +this.state = { + cards: [ + { + text: 'Be Here Now.', + }, + { + text: 'Ok, now be somewhere else.', + }, + { + text: 'Being present in the present is the greatest present you can present to yourself.', + emoji: 'gift', + }, + ], +}; diff --git a/src/components/Board.js b/src/components/Board.js index aa3965a7..279e40e3 100644 --- a/src/components/Board.js +++ b/src/components/Board.js @@ -1,6 +1,5 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; -import emoji from 'emoji-dictionary'; import axios from 'axios'; import './Board.css'; import Card from './Card'; @@ -12,46 +11,62 @@ class Board extends Component { super(); this.state = { - cards: [ - { - inspoText: 'Be Here Now.', - - }, - { - inspoText: 'Ok, now be somewhere else', - - }, - { - inspoText: 'Being present in the present is the greatest present you can give yourself', - inspoEmoji: 'gift', - }, - ], + cards: [], }; } - render() { - console.log("In render function, this is the current set of cards, before converting to card components:"); - console.log(this.state.cards); - const cardComponents = this.state.cards.map((card, index) => { + componentDidMount() { + axios.get('https://inspiration-board.herokuapp.com/boards/victoria/cards') + .then((response) => { + console.log('Here is the response'); + console.log(response); + this.setState({ cards: response.data }); + console.log('now reporting state:') + console.log(this.state.cards) + console.log('now reporting the first state element:') + console.log(this.state.cards[0]) + console.log('now trying to dig:') + console.log(this.state.cards[0]["card"]["id"]) + }) + .catch((error) => { + this.setState({ error: error.message }); + }); + } + + render() { + + const cardKeysAttempt = Object.keys(this.state.cards).map( + key => + ({ + cardId: this.state.cards[key]["card"]["id"], + cardTxt: this.state.cards[key]["card"]["text"], + cardEmo: this.state.cards[key]["card"]["emoji"] + }) + ) + + const cardComponents = cardKeysAttempt.map((card) => { return ( -
  • +
  • - ); + ) }); + console.log('Here is cardKeysAttempt') + console.log(cardKeysAttempt) + console.log('Here is cardComponents') + console.log(cardComponents) + return (
    -
      - {cardComponents} -
    + {cardComponents}
    ) } diff --git a/src/components/Card.js b/src/components/Card.js index 91333711..e59706f7 100644 --- a/src/components/Card.js +++ b/src/components/Card.js @@ -6,12 +6,10 @@ import './Card.css'; class Card extends Component { - constructor(props) { - super(props); - } - render() { + const cardIdent = this.props.cardId + const cardWords = this.props.cardText const hasEmoji = this.props.cardEmoji; let displayEmoji; if (hasEmoji) { @@ -22,7 +20,7 @@ class Card extends Component {
    -

    {this.props.cardText}

    +

    {cardWords}

    {displayEmoji}

    @@ -34,6 +32,7 @@ class Card extends Component { } Card.propTypes = { + cardId: PropTypes.number, cardText: PropTypes.string.isRequired, cardEmoji: PropTypes.string, }; From f0862f26c7c006bfd8f08283323a34e29527ba4b Mon Sep 17 00:00:00 2001 From: Victoria Garcia Date: Sun, 17 Jun 2018 12:30:58 -0700 Subject: [PATCH 04/13] Deletion is working, basically, but still at a loss as to how to get it to reload the page after. --- README.md | 94 ----------------------------------------- src/components/Board.js | 15 +------ src/components/Card.css | 4 +- src/components/Card.js | 44 +++++++++++++------ 4 files changed, 37 insertions(+), 120 deletions(-) diff --git a/README.md b/README.md index 67627304..e0aaadae 100644 --- a/README.md +++ b/README.md @@ -79,100 +79,6 @@ You can see what your instructors are looking for [here](./feedback.md) #### CODE PARKING LOT: -render() { - return ( -
    -
    -
    -

    {this.props.cardText}

    -
    -
    - {this.addCardEmoji} -
    -
    -
    - ) -} -} - - - -constructor(props) { - super(props); - - this.state = { - cardText: this.props.cardText, - } -} - - -addCardEmoji = (emoji) => { - if (this.props.emojiDesc){ - this.setState( - { - cardEmoji: emoji.getUnicode(this.props.emojiDesc) - } - ); - } -} - - -componentDidMount() { - axios.get(`https://jsonplaceholder.typicode.com/users`) - .then(res => { - const persons = res.data; - this.setState({ persons }); - }) -} - -const cardComponents = Object.keys(this.state.cards).map(card => - ({ - cardId: card["id"], - cardText: card["text"], - cardEmoji: card["emoji"], - }) -) - - - -render() { - return ( -
    - {Object.keys(this.state.dataGoal.milestones).map((milestone) =>{ - return {this.state.dataGoal.milestones[milestone].tasks.map((task, idx)=>{ - return ( - //whatever you wish to do with the task item - ) -}) - })} - -
    - ) -} - -const cardComponents = this.state.cards.map((card, index) => { - return ( -
  • - -
  • - ); -}); - -axios.get(allTripsUrl) - .then((response) => { - reportStatus(`Successfully loaded ${response.data.length} trips`); - response.data.forEach((trip) => { - allTrips.append(`
  • ${trip.name}
  • `); - }); - }) - .catch((error) => { - reportStatus(`Encountered an error while loading trips: ${error.message}`); - console.log(error); - }); -}; - this.state = { cards: [ diff --git a/src/components/Board.js b/src/components/Board.js index 279e40e3..0bb54649 100644 --- a/src/components/Board.js +++ b/src/components/Board.js @@ -15,22 +15,10 @@ class Board extends Component { }; } - - - - componentDidMount() { axios.get('https://inspiration-board.herokuapp.com/boards/victoria/cards') .then((response) => { - console.log('Here is the response'); - console.log(response); this.setState({ cards: response.data }); - console.log('now reporting state:') - console.log(this.state.cards) - console.log('now reporting the first state element:') - console.log(this.state.cards[0]) - console.log('now trying to dig:') - console.log(this.state.cards[0]["card"]["id"]) }) .catch((error) => { this.setState({ error: error.message }); @@ -52,6 +40,7 @@ class Board extends Component { return (
  • @@ -65,7 +54,7 @@ class Board extends Component { console.log(cardComponents) return ( -
    +
    {cardComponents}
    ) diff --git a/src/components/Card.css b/src/components/Card.css index e86d4329..5f68310f 100644 --- a/src/components/Card.css +++ b/src/components/Card.css @@ -11,7 +11,7 @@ border-radius: 5px; display: grid; - grid-template-columns: 1fr 5fr 1fr; + grid-template-columns: 1fr 3fr 1fr; align-items: center; } @@ -43,5 +43,7 @@ .card__delete { align-self: start; + border: 2px solid black; + border-radius: 5px; font-family: 'Permanent Marker', Helvetica, sans-serif; } diff --git a/src/components/Card.js b/src/components/Card.js index e59706f7..fd192194 100644 --- a/src/components/Card.js +++ b/src/components/Card.js @@ -1,39 +1,59 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; +import axios from 'axios'; import emoji from 'emoji-dictionary'; import './Card.css'; class Card extends Component { + constructor(props) { + super(); + this.state = { + cardId: props.cardID, + cardWorden: props.cardText, + cardEmoji: props.cardEmoji, + } + } + + handleSubmit = event => { + let deleteURL = `https://inspiration-board.herokuapp.com/boards/victoria/cards/${this.props.cardID}` + console.log(deleteURL) + axios.delete(deleteURL) + .then(response => { + console.log(response); + console.log(response.data); + }) + } + render() { - const cardIdent = this.props.cardId - const cardWords = this.props.cardText - const hasEmoji = this.props.cardEmoji; + const hasEmoji = this.state.cardEmoji; let displayEmoji; if (hasEmoji) { displayEmoji = emoji.getUnicode(this.props.cardEmoji) } else { displayEmoji = "" } + console.log('trying to report cardID') + console.log(this.state.cardId) return (
    -
    -
    -

    {cardWords}

    -
    -
    -

    {displayEmoji}

    -
    +
    +
    {this.state.cardWorden}
    +
    {displayEmoji}
    +
    {this.state.cardId}
    +
    + +
    ) } } Card.propTypes = { - cardId: PropTypes.number, - cardText: PropTypes.string.isRequired, + cardID: PropTypes.number, + cardText: PropTypes.string, cardEmoji: PropTypes.string, }; From 3cfe7f98fb6e655716675da1321dad0e056c342e Mon Sep 17 00:00:00 2001 From: Victoria Garcia Date: Sun, 17 Jun 2018 13:25:09 -0700 Subject: [PATCH 05/13] Ok, now it's reloading after deletion. Party. --- src/components/Card.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/Card.js b/src/components/Card.js index fd192194..b89057b0 100644 --- a/src/components/Card.js +++ b/src/components/Card.js @@ -16,16 +16,24 @@ class Card extends Component { } } - handleSubmit = event => { + handleDelete = event => { + event.preventDefault(); let deleteURL = `https://inspiration-board.herokuapp.com/boards/victoria/cards/${this.props.cardID}` + console.log('In the delete handler: ') console.log(deleteURL) axios.delete(deleteURL) .then(response => { + console.log('response to API request is happening') console.log(response); console.log(response.data); + console.log("about to reload") + console.log(window.parent.location.href) + window.parent.location.reload() }) } + + render() { const hasEmoji = this.state.cardEmoji; @@ -43,7 +51,7 @@ class Card extends Component {
    {displayEmoji}
    {this.state.cardId}
    -
    +
    From dcf2a0b1be0c6e9954dce4b0084a5c11fdef6605 Mon Sep 17 00:00:00 2001 From: Victoria Garcia Date: Sun, 17 Jun 2018 18:57:44 -0700 Subject: [PATCH 06/13] Post method is now working nicely. Emoji needs to become a dropdown, and tests need to be added, but this is nearly done. --- src/components/Board.js | 34 ++++++++++++++-- src/components/Card.js | 5 ++- src/components/NewCardForm.js | 76 +++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 5 deletions(-) diff --git a/src/components/Board.js b/src/components/Board.js index 0bb54649..63c99aa0 100644 --- a/src/components/Board.js +++ b/src/components/Board.js @@ -25,6 +25,31 @@ class Board extends Component { }); } + addCard = (card) => { + axios.post('https://inspiration-board.herokuapp.com/boards/victoria/cards', + card) + .then((response) => { + console.log('Post attempt is happening') + console.log(response) + console.log(response.data) + this.setState({ + message: `Successfully Added A Card!` + }); + console.log('HREF for current window:') + console.log(window.location.HREF) + console.log('HREF for parent window:') + console.log(window.parent.location.href) + console.log('Now trying to reload') + window.parent.location.reload() + }) + .catch((error) => { + console.log(error.message); + this.setState({ + message: error.message, + }); + }); + } + render() { const cardKeysAttempt = Object.keys(this.state.cards).map( @@ -54,16 +79,19 @@ class Board extends Component { console.log(cardComponents) return ( -
    +
    +
    + {this.state.message ? this.state.message: "" } +
    {cardComponents} -
    + + ) } } Board.propTypes = { - }; export default Board; diff --git a/src/components/Card.js b/src/components/Card.js index b89057b0..8662fef8 100644 --- a/src/components/Card.js +++ b/src/components/Card.js @@ -19,8 +19,6 @@ class Card extends Component { handleDelete = event => { event.preventDefault(); let deleteURL = `https://inspiration-board.herokuapp.com/boards/victoria/cards/${this.props.cardID}` - console.log('In the delete handler: ') - console.log(deleteURL) axios.delete(deleteURL) .then(response => { console.log('response to API request is happening') @@ -30,6 +28,9 @@ class Card extends Component { console.log(window.parent.location.href) window.parent.location.reload() }) + .catch((error) => { + this.setState({ error: error.message }); + }); } diff --git a/src/components/NewCardForm.js b/src/components/NewCardForm.js index 47331423..76fe7ecf 100644 --- a/src/components/NewCardForm.js +++ b/src/components/NewCardForm.js @@ -4,3 +4,79 @@ 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() { + super(); + this.state = { + text:'', + emoji: '', + }; + } + + onFieldChange = (event) => { + const fieldName = event.target.name; + const fieldValue = event.target.value; + const updateState = {}; + updateState[fieldName] = fieldValue; + this.setState(updateState); + } + + valid = () => { + return this.state.text.length > 0 || + this.state.emoji.length > 0; + } + + clearForm = () => { + this.setState({ + text: '', + emoji: '', + }); + } + + onFormSubmit = (event) => { + event.preventDefault(); + if (this.valid()) { + this.props.addCardCallback(this.state); + this.clearForm(); + } + } + + render() { + return ( +
    +

    Add An Edifying Post-It of Your Very Own:

    +
    +
    + + +
    +
    + + +
    + +
    +
    + ); + } +} + +NewCardForm.propTypes = { + addCardCallback: PropTypes.func.isRequired, +}; + +export default NewCardForm; From c1d22d2c6b816a09dc2c1bcf0e70a26d3f990613 Mon Sep 17 00:00:00 2001 From: Victoria Garcia Date: Sun, 17 Jun 2018 19:31:17 -0700 Subject: [PATCH 07/13] Emoji selector is now working. Want to turn the other part of the form into a text area, but other than that, we're golden. --- src/components/Card.css | 4 ++++ src/components/Card.js | 2 +- src/components/NewCardForm.js | 26 ++++++++++++++++++-------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/components/Card.css b/src/components/Card.css index 5f68310f..a4cf91cb 100644 --- a/src/components/Card.css +++ b/src/components/Card.css @@ -36,6 +36,10 @@ font-size: 3rem; } +.card_content-id { + font-size: 1rem; +} + .card__content-text, .card__content-emoji { padding: 0; margin: 0; diff --git a/src/components/Card.js b/src/components/Card.js index 8662fef8..4e47f329 100644 --- a/src/components/Card.js +++ b/src/components/Card.js @@ -50,7 +50,7 @@ class Card extends Component {
    {this.state.cardWorden}
    {displayEmoji}
    -
    {this.state.cardId}
    +
    Inspiration Quantum Number: {this.state.cardId}
    diff --git a/src/components/NewCardForm.js b/src/components/NewCardForm.js index 76fe7ecf..ea11df57 100644 --- a/src/components/NewCardForm.js +++ b/src/components/NewCardForm.js @@ -43,7 +43,19 @@ class NewCardForm extends Component { } } + render() { + + const emojiPicker = EMOJI_LIST.map((emoj, index) => { + return ( + + ) + }); + + console.log('reporting emojiPicker result:') + console.log(emojiPicker) + + return (

    Add An Edifying Post-It of Your Very Own:

    @@ -59,14 +71,12 @@ class NewCardForm extends Component { />
  • - - +
    From 65faf32a741e6cc6ef4889a9cf2fcaceb3ec032e Mon Sep 17 00:00:00 2001 From: Victoria Garcia Date: Sun, 17 Jun 2018 19:43:06 -0700 Subject: [PATCH 08/13] Changes in the form to dropdown and select are now working. Testing is all that's left. --- src/components/Card.js | 2 +- src/components/NewCardForm.js | 15 +++------------ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/components/Card.js b/src/components/Card.js index 4e47f329..3c2aa976 100644 --- a/src/components/Card.js +++ b/src/components/Card.js @@ -50,7 +50,7 @@ class Card extends Component {
    {this.state.cardWorden}
    {displayEmoji}
    -
    Inspiration Quantum Number: {this.state.cardId}
    +
    This is Quantum of Inspiration Number: {this.state.cardId}
    diff --git a/src/components/NewCardForm.js b/src/components/NewCardForm.js index ea11df57..4beab972 100644 --- a/src/components/NewCardForm.js +++ b/src/components/NewCardForm.js @@ -52,23 +52,14 @@ class NewCardForm extends Component { ) }); - console.log('reporting emojiPicker result:') - console.log(emojiPicker) - - return (

    Add An Edifying Post-It of Your Very Own:

    - - +