Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 11 additions & 4 deletions controllers/bjjControllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,19 @@ function show(req, res) {





function destroy(req, res) {


db.Bjj.findByIdAndRemove({_id: req.params.bjjId}, (err, response) => {

res.status(200).send(response);
console.log("shit did work: buh bye")
});
}

module.exports = {
index: index,
create: create,
show: show

show: show,
destroy: destroy
}
24 changes: 16 additions & 8 deletions public/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ $.ajax({
});



Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Short and sweet, works.

function formData(e){
e.preventDefault();
var formData = $(this).serialize();
Expand All @@ -18,19 +17,16 @@ $.ajax({
}

// form submission event handler
$('.form-horizontal').on('submit', formData)



$('.form-horizontal').on('submit', formData);
$('#gymDisplay').on("click", ".deleteBtn", handleDeleteBjj);
});



// loop through data and render to html
function renderMultipleReviews(reviews) {

console.log(reviews);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation 😭

reviews.forEach(function(review) {
console.log(review)
renderBjj(review);
});

Expand All @@ -42,7 +38,7 @@ function renderBjj(bjj) {

var bjjHtml = (`

<div class="container forms">
<div class="container forms" data-bjj='${bjj._id}'>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be indented to reflect HTML structure.

<div class="row">
<div class="col-sm-12">
<div class="card" style="width: 75%;">
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

manually setting width is so sad! could add another class so you can still use class-based styling for these cards.

Expand All @@ -56,6 +52,7 @@ function renderBjj(bjj) {
<li class="list-group-item"><span class="desc">Review:</span> ${bjj.reviews}</li>

</ul>
<button class="deleteBtn btn-danger" type="click">Remove review</button>
</div>
</div>

Expand All @@ -72,3 +69,14 @@ function renderBjj(bjj) {



function handleDeleteBjj(e) {
console.log('delete-song clicked!');
var currentBjjId = $(this).closest('.forms').attr('data-bjj'); // "5665ff1678209c64e51b4e7b"
var currentBjjElem =$(this).closest('.card');
console.log(currentBjjId);
$.ajax({
method:"DELETE",
url: '/api/bjj/'+currentBjjId,
success: currentBjjElem.remove()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This removes that element immediately, not as a callback! It'll remove from the page whether or not the API call is successful. It should instead be:

success: function() {
  currentBjjElem.remove();
}

})
}
4 changes: 1 addition & 3 deletions public/styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ body {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just doing what is needed.

.forms{
margin:75px;


}

.card-img-top {
Expand All @@ -21,10 +19,10 @@ body {
background-color:black;
color:white;
}

.list-group-flush {
color:black;
font-weight:bold;

}

.desc {
Expand Down
1 change: 1 addition & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ app.get('/api', controllers.api.index);
app.get('/api/bjj', controllers.bjj.index);
app.post('/api/bjj', controllers.bjj.create);
app.get('/api/bjj', controllers.bjj.show);
app.delete('/api/bjj/:bjjId', controllers.bjj.destroy);


/**********
Expand Down