From b25e011cfd1b22030c0de8fdda13176f9323bb9b Mon Sep 17 00:00:00 2001 From: zepp Date: Sat, 22 Feb 2025 11:51:12 -0500 Subject: [PATCH] create ability to list comments on guestbook pages basic testing for now. will need to style and add conditionals --- src/pages/site/guestbook.astro | 4 ++++ src/scripts/guestbook-list-comments.js | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/pages/site/guestbook.astro b/src/pages/site/guestbook.astro index b1f6a8b..d8ab47a 100644 --- a/src/pages/site/guestbook.astro +++ b/src/pages/site/guestbook.astro @@ -67,6 +67,10 @@ const pageTitle = "emma's guestbook"

comments

+ + \ No newline at end of file diff --git a/src/scripts/guestbook-list-comments.js b/src/scripts/guestbook-list-comments.js index 65cf0e8..b6e9ebd 100644 --- a/src/scripts/guestbook-list-comments.js +++ b/src/scripts/guestbook-list-comments.js @@ -10,3 +10,25 @@ const { data, error } = await supabase .from("guestbook-comments") .select() .eq("approved", true); + +const commentList = document.querySelector(".comments"); + +data.forEach((el) => { + const listItem = document.createElement("li"); + const container = document.createElement("div"); + const commenter = document.createElement("div"); + const commenterData = document.createElement("p"); + + commenterData.textContent = `name: ${el.name} website: ${el.website}`; + const commentData = document.createElement("div"); + const commentText = document.createElement("p"); + + commentText.textContent = el.comment; + commentData.appendChild(commentText); + commenter.appendChild(commenterData); + container.appendChild(commenter); + container.appendChild(commentData); + listItem.appendChild(container); + + commentList.appendChild(listItem); +});