From 96d468355073853fc6d38b41332cbf2b7e384bd6 Mon Sep 17 00:00:00 2001 From: Shiva Bodhireddy <{ID}+{username}@users.noreply.github.com> Date: Wed, 26 Mar 2025 15:41:44 -0700 Subject: [PATCH 1/4] Initial commit; html setup --- index.html | 39 +++++++++++++++++++++++++++++++++++++++ main.js | 0 style.css | 0 3 files changed, 39 insertions(+) create mode 100644 index.html create mode 100644 main.js create mode 100644 style.css diff --git a/index.html b/index.html new file mode 100644 index 00000000..4a1c0267 --- /dev/null +++ b/index.html @@ -0,0 +1,39 @@ + + + ReReddit + + + +
+
+ + + +
+
+ +
+ +
+ +
+ +
+ +
+ + +
+ +
+
+ + + + \ No newline at end of file diff --git a/main.js b/main.js new file mode 100644 index 00000000..e69de29b diff --git a/style.css b/style.css new file mode 100644 index 00000000..e69de29b From 58e11e905eec2b889e969aac32b99b35f333abe1 Mon Sep 17 00:00:00 2001 From: Shiva Bodhireddy <{ID}+{username}@users.noreply.github.com> Date: Wed, 26 Mar 2025 16:07:46 -0700 Subject: [PATCH 2/4] Event Listener- Post Comments --- main.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/main.js b/main.js index e69de29b..0eda4f23 100644 --- a/main.js +++ b/main.js @@ -0,0 +1,21 @@ +//Event listener for clicking on submit button +document.getElementById('submit').addEventListener('click', function () { + var name = document.getElementById('name').value; + var text = document.getElementById('message').value; + + var postsDiv = document.querySelector('.posts'); + + var newPostDiv = document.createElement('div'); + + var newPostP = document.createElement('p'); + var newPostNode = document.createTextNode(`${text} - Posted By: ${name}`); + newPostP.appendChild(newPostNode); + + var newPostHR = document.createElement('hr'); + + newPostDiv.append(newPostP); + newPostDiv.append(newPostHR); + + postsDiv.append(newPostDiv); + +}) \ No newline at end of file From c7ade8978f2f703c6d06ebff668ce02f9a78227f Mon Sep 17 00:00:00 2001 From: Shiva Bodhireddy <{ID}+{username}@users.noreply.github.com> Date: Wed, 26 Mar 2025 16:47:09 -0700 Subject: [PATCH 3/4] Add remove post and comment buttons --- index.html | 2 +- main.js | 30 +++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/index.html b/index.html index 4a1c0267..9102b891 100644 --- a/index.html +++ b/index.html @@ -1,7 +1,7 @@ ReReddit - +
diff --git a/main.js b/main.js index 0eda4f23..0c4a94a9 100644 --- a/main.js +++ b/main.js @@ -1,21 +1,37 @@ //Event listener for clicking on submit button document.getElementById('submit').addEventListener('click', function () { - var name = document.getElementById('name').value; - var text = document.getElementById('message').value; + const name = document.getElementById('name').value; + const text = document.getElementById('message').value; - var postsDiv = document.querySelector('.posts'); + const postsDiv = document.querySelector('.posts'); - var newPostDiv = document.createElement('div'); + //Create wrapper for individual post + const newPostDiv = document.createElement('div'); - var newPostP = document.createElement('p'); - var newPostNode = document.createTextNode(`${text} - Posted By: ${name}`); + //Create

and text node for post + const newPostP = document.createElement('p'); + const newPostNode = document.createTextNode(`${text} - Posted By: ${name}`); newPostP.appendChild(newPostNode); - var newPostHR = document.createElement('hr'); + //Create remove button + const removeButton = document.createElement('button'); + removeButton.textContent = 'Remove Post'; + //Create comments button + const commentButton = document.createElement('button'); + commentButton.textContent = 'See Comments'; + + //Create


+ const newPostHR = document.createElement('hr'); + + //Append the remove link, post, and hr to the post div + newPostDiv.append(removeButton); + newPostDiv.append(commentButton); newPostDiv.append(newPostP); newPostDiv.append(newPostHR); + //Append the post to postDiv postsDiv.append(newPostDiv); + }) \ No newline at end of file From 7511aa19af913bcd18e5a2eb03fbbaee52c70595 Mon Sep 17 00:00:00 2001 From: Shiva Bodhireddy <{ID}+{username}@users.noreply.github.com> Date: Fri, 28 Mar 2025 11:20:23 -0700 Subject: [PATCH 4/4] Added post, comment and remove functionality --- main.js | 143 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 118 insertions(+), 25 deletions(-) diff --git a/main.js b/main.js index 0c4a94a9..855fd9ff 100644 --- a/main.js +++ b/main.js @@ -1,37 +1,130 @@ -//Event listener for clicking on submit button +// Handle new post submission document.getElementById('submit').addEventListener('click', function () { - const name = document.getElementById('name').value; - const text = document.getElementById('message').value; + // Get and trim input values + const name = document.getElementById('name').value.trim(); + const text = document.getElementById('message').value.trim(); + + // Clear inputs + document.getElementById('name').value = ''; + document.getElementById('message').value = ''; + + // Validate input + if (!name || !text) { + alert("Please fill out both fields!"); + return; + } + + // Create post const postsDiv = document.querySelector('.posts'); - //Create wrapper for individual post - const newPostDiv = document.createElement('div'); + // Post container + const postPanel = document.createElement('div'); + postPanel.className = 'panel panel-default'; + + const postBody = document.createElement('div'); + postBody.className = 'panel-body'; + + // Post content + const postText = document.createElement('p'); + postText.textContent = `${text} - Posted By: ${name}`; + postText.style.marginTop = '10px'; + postText.style.marginBottom = '15px'; + + // Action buttons + const removeButton = document.createElement('button'); + removeButton.textContent = 'Remove Post'; + removeButton.className = 'btn btn-danger btn-xs'; + + const commentButton = document.createElement('button'); + commentButton.textContent = 'Comments'; + commentButton.className = 'btn btn-default btn-xs'; + + //Create comment section + + const commentsDiv = document.createElement('div'); + commentsDiv.style.display = 'none'; + + const commentsList = document.createElement('div'); + commentsList.style.marginTop = '10px'; + + const commentInput = document.createElement('input'); + commentInput.className = 'form-control'; + commentInput.placeholder = 'Comment'; + + const nameInput = document.createElement('input'); + nameInput.className = 'form-control'; + nameInput.placeholder = 'Your Name'; + + const postCommentButton = document.createElement('button'); + postCommentButton.textContent = 'Post'; + postCommentButton.className = 'btn btn-primary btn-sm'; + + // Assemble comment section + commentsDiv.appendChild(commentsList); + commentsDiv.appendChild(commentInput); + commentsDiv.appendChild(nameInput); + commentsDiv.appendChild(postCommentButton); + + // Assemble post + postBody.appendChild(removeButton); + postBody.appendChild(commentButton); + postBody.appendChild(postText); + postBody.appendChild(commentsDiv); + + postPanel.appendChild(postBody); + postsDiv.appendChild(postPanel); + + // Buttons + + // Remove entire post + removeButton.addEventListener('click', function () { + postPanel.remove(); + }); + + // Toggle comment section + commentButton.addEventListener('click', function () { + commentsDiv.style.display = (commentsDiv.style.display === 'none') ? 'block' : 'none'; + }); - //Create

and text node for post - const newPostP = document.createElement('p'); - const newPostNode = document.createTextNode(`${text} - Posted By: ${name}`); - newPostP.appendChild(newPostNode); + // Handle comment submission + postCommentButton.addEventListener('click', function () { + const commentText = commentInput.value.trim(); + const commenterName = nameInput.value.trim(); - //Create remove button - const removeButton = document.createElement('button'); - removeButton.textContent = 'Remove Post'; + // Validate comment input + if (!commentText || !commenterName) { + alert("Please fill out both fields!"); + return; + } - //Create comments button - const commentButton = document.createElement('button'); - commentButton.textContent = 'See Comments'; + // Add well for first comment + if (commentsList.children.length === 0) { + commentsList.className = 'well well-sm'; + } - //Create


- const newPostHR = document.createElement('hr'); + // Create comment element + const comment = document.createElement('p'); + comment.textContent = `${commentText} - Posted By: ${commenterName}`; - //Append the remove link, post, and hr to the post div - newPostDiv.append(removeButton); - newPostDiv.append(commentButton); - newPostDiv.append(newPostP); - newPostDiv.append(newPostHR); + // Create remove link for comment + const removeLink = document.createElement('a'); + removeLink.href = '#'; + removeLink.textContent = ' x'; + removeLink.style.marginLeft = '10px'; + removeLink.style.color = 'red'; + removeLink.style.cursor = 'pointer'; - //Append the post to postDiv - postsDiv.append(newPostDiv); + removeLink.addEventListener('click', function (e) { + e.preventDefault(); + comment.remove(); + }); + comment.appendChild(removeLink); + commentsList.appendChild(comment); -}) \ No newline at end of file + // Clear comment inputs + commentInput.value = ''; + nameInput.value = ''; + }); +}); \ No newline at end of file