From c6900a4c0afb98a2a98c46477915363e943c4a67 Mon Sep 17 00:00:00 2001 From: Manna Kong Date: Thu, 1 Jul 2021 18:47:44 -0500 Subject: [PATCH] done with CRUD in reviews --- public/javascripts/index.js | 37 +++++++++++++++++++------------------ routes/index.js | 1 + 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/public/javascripts/index.js b/public/javascripts/index.js index a4abd3e..b5bbed1 100644 --- a/public/javascripts/index.js +++ b/public/javascripts/index.js @@ -7,38 +7,39 @@ window.addEventListener("load", (event)=>{ event.preventDefault(); const id = event.target.id let area = document.querySelector(`#text-${id}`); - area.parentElement.innerHTML = ` `; + area.parentElement.innerHTML = ` `; + + 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 = ``; - - // 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 +// diff --git a/routes/index.js b/routes/index.js index 8785f7a..c91297a 100644 --- a/routes/index.js +++ b/routes/index.js @@ -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}`) } }) );