Skip to content

Commit

Permalink
done with CRUD in reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
makon57 committed Jul 1, 2021
1 parent f578431 commit c6900a4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
37 changes: 19 additions & 18 deletions public/javascripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,39 @@ window.addEventListener("load", (event)=>{
event.preventDefault();
const id = event.target.id
let area = document.querySelector(`#text-${id}`);
area.parentElement.innerHTML = `<textarea>${area.innerText}</textarea> <button id="save-btn">Save</button>`;
area.parentElement.innerHTML = `<textarea id="review-text">${area.innerText}</textarea> <button id="save-btn">Save</button>`;

let body;

const saveBtn = document.querySelector('#save-btn');
console.log(saveBtn);
if (saveBtn) {
saveBtn.addEventListener('click', async (event) => {
// event.preventDefault();
// const id = event.target.id
// console.log(id);

const review = await fetch(`http://localhost:8080/review/${id}`, {
method: "PUT",
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({body}),
});
const update = await review.json();
window.location.href = `/trail/${update.trailId}`
});
}

const updateValue = async (event) => {
const body = event.target.value;
body = event.target.value;
console.log(body);
// area.parentElement.innerHTML = `<textarea>${area.innerText}</textarea>`;

// const review = await fetch(`http://localhost:8080/review/${id}`, {
// method: "PUT",
// headers: { 'Content-Type': 'application/json' },
// body: JSON.stringify({body}),
// });
// const update = await review.json();

}

area.addEventListener('change', updateValue)


let areaThing = document.querySelector(`#review-text`);
areaThing.addEventListener('change', updateValue)
console.log(areaThing);
})

}


});

// Listen to the text inside of areaThing, ONCE it exists
// Set your text in your put request to the new thing area thINg
//
1 change: 1 addition & 0 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ router.put(
console.log(req.body.body);
await review.update({ text: req.body.body });
res.json(review)
// res.redirect(`/trail/${review.trailId}`)
}
})
);
Expand Down

0 comments on commit c6900a4

Please sign in to comment.