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

Bp delete card feature #9

Merged
merged 4 commits into from
Jun 30, 2021
Merged
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
33 changes: 27 additions & 6 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ function App() {
});

useEffect(() => {
axios.get(`${process.env.REACT_APP_BACKEND_URL}/boards`, {
}).then((response) => {
axios.get(`${process.env.REACT_APP_BACKEND_URL}/boards`).then((response) => {
setBoardsData(response.data);
})
}, []);
Expand All @@ -43,6 +42,7 @@ function App() {
console.log('Error:', error);
alert('Couldn\'t create a new board.');
})}

const upvoteCard = (selectedCardId) => {
axios
.put(`${process.env.REACT_APP_BACKEND_URL}/cards/${selectedCardId}/upvote`)
Expand All @@ -55,6 +55,25 @@ function App() {
})
};


const deleteCard = (selectedCardId) => {
axios
.delete(`${process.env.REACT_APP_BACKEND_URL}/cards/${selectedCardId}`)
.then((response) => {
axios
.get(`${process.env.REACT_APP_BACKEND_URL}/boards/${selectedBoard.id}/cards`)
.then((response) => {
setCardsData(response.data)
})
.catch((error) => {
console.log(error.data.details)
})
})
.catch((error) => {
console.log(error.data.details)
})
};

const updateCardsList = (selectedCard) => {
const cards = cardsData.map(card => {
if (selectedCard.id === card.id) {
Expand All @@ -64,7 +83,7 @@ function App() {
}
});
setCardsData(cards)
}
};

return (
<div>
Expand All @@ -83,18 +102,20 @@ function App() {
<h2>Choose A Board</h2>
< BoardList
boardsData= { boardsData }
selectedBoard={setSelectedBoard}
selectedBoard={ setSelectedBoard }
/>
</section>
<section>
< CardList
cardsData= { cardsData }
upvoteCard = {upvoteCard}
upvoteCard = { upvoteCard }
deleteCard = { deleteCard }
/>
</section>
</main>
</div>

);
}
};

export default App;
10 changes: 6 additions & 4 deletions src/components/Card.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import React from 'react';

const Card = (props) => {
console.log(props)



const upvoteClick = () => {
const selectedCardId = props.id
console.log(selectedCardId)
props.upvoteCard(selectedCardId);
props.upvoteCard(selectedCardId);

};


const deleteCardClick = () => {
const selectedCardId = props.id
props.deleteCard(selectedCardId)
};

return (
<section>
Expand All @@ -21,6 +22,7 @@ const Card = (props) => {
<li>Board ID: { props.boardId }</li>
<li>Message: { props.message }</li>
<button type='button' onClick={upvoteClick}> Upvote: {props.likesCount}</button>
<button type='button' onClick={deleteCardClick}>Delete</button>
</ul>
</section>
)
Expand Down
3 changes: 2 additions & 1 deletion src/components/CardList.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const CardList = (props) => {
message={ card.message }
likesCount= { card.likes_count}
boardId= {card.board_id }
upvoteCard={props.upvoteCard}/>
upvoteCard={props.upvoteCard}
deleteCard={props.deleteCard}/>
</li>
);
});
Expand Down