From 34bfccd7a59955b2c48a6cdc023ac2c383e423d2 Mon Sep 17 00:00:00 2001 From: Yefim Vedernikoff Date: Mon, 26 Jun 2023 15:36:13 -0700 Subject: [PATCH] Add and remove RSVP from list (#96) --- app/templates/attendee_rsvp.html | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/app/templates/attendee_rsvp.html b/app/templates/attendee_rsvp.html index ad88a52..38e336e 100644 --- a/app/templates/attendee_rsvp.html +++ b/app/templates/attendee_rsvp.html @@ -132,6 +132,16 @@ submitRSVP("not_attending"); }); + function removeSelfFromList() { + const li = [...$attendeesList.children].find((el) => { + return el.innerText === "{{attendee.attendee.split()[0]}}"; + }); + + if (li) { + $attendeesList.removeChild(li); + } + } + function submitRSVP(status) { const junction_pub = document.getElementById("junction_pub").value; const attendeeStatus = document.getElementById("attendee_status"); @@ -150,12 +160,18 @@ switch (status) { case "attending": + removeSelfFromList(); + const li = document.createElement("li"); + li.innerText = "{{attendee.attendee.split()[0]}}"; + $attendeesList.appendChild(li); consoleText([attendeeStatus.innerText, "attending"]); break; case "maybe": + removeSelfFromList(); consoleText([attendeeStatus.innerText, "a maybe for"]); break; case "not_attending": + removeSelfFromList(); consoleText([ attendeeStatus.innerText, "unable to make it for", @@ -208,11 +224,11 @@ /* Populate list of attendees. */ const ATTENDEE_DATA = "ATTENDEES_UNKNOWN".split(","); - const listEl = document.getElementById("attendees-list"); + const $attendeesList = document.getElementById("attendees-list"); ATTENDEE_DATA.forEach((attendee) => { const li = document.createElement("li"); li.innerText = attendee; - listEl.appendChild(li); + $attendeesList.appendChild(li); }); function consoleText(words, id, colors) {