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

Ports - Jillianne #38

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
7 changes: 0 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: 2 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class App extends Component {
<h1 className="header__h1"><span className="header__text">Inspiration Board</span></h1>
</header>
<Board
url="https://inspiration-board.herokuapp.com/boards/"
boardName={`Ada-Lovelace`}
url="https://inspiration-board.herokuapp.com/"
boardName={`jr`}
/>
</section>
);
Expand Down
35 changes: 33 additions & 2 deletions src/components/Board.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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() {
Expand All @@ -16,10 +16,41 @@ class Board extends Component {
};
}

componentDidMount() {
axios.get(`${this.props.url}boards/${this.props.boardName}/cards`)
.then((response) => {
this.setState({ cards: response.data });
})
.catch((error) => {
this.setState({ error: error.message });
});
}

deleteCardCallback = (cardID) => {
axios.delete(`${this.props.url}cards/${cardID}`)
.then((prevState) => {
const newBoard = prevState.cards.flatMap(card => {
if (card.card.id !== cardID) {
return card
}
return []
})

this.setState({ cards: newBoard });
})
.catch((error) => {
this.setState({ error: error.message });
});
}

render() {
const allCards = this.state.cards.map((card, i) => {
return <div key={i}><Card id={card.card.id} text={card.card.text} emoji={card.card.emoji} deleteCardCallback={this.deleteCardCallback}/></div>
});

return (
<div>
Board
{allCards}
</div>
)
}
Expand Down
31 changes: 23 additions & 8 deletions src/components/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,33 @@ import emoji from 'emoji-dictionary';

import './Card.css';

class Card extends Component {
render() {
return (
<div className="card">
Card
</div>
)
const Card = (props) => {
const deleteCard = () => {
props.deleteCardCallback(props.id)
}

console.log(props.text)

return (
<div className="card">
<div className="card__content">
<div className="card__content-text">
{props.text && `Text: ${props.text}`}
</div>
<div className="card__content-emoji">
{props.emoji && `Emoji: ${emoji.getUnicode(props.emoji)}`}
</div>
<div className="card__delete">
<button onClick={deleteCard}>Delete Card</button>
</div>
</div>
</div>
)
}

Card.propTypes = {

text: PropTypes.string,
emoji: PropTypes.string,
};

export default Card;
2 changes: 1 addition & 1 deletion src/data/card-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
{
"text": "",
"Emoji": "heart_eyes"
"emoji": "heart_eyes"
},
{
"text": "REST is part of work"
Expand Down