diff --git a/index.html b/index.html index c22c173..54e7484 100644 --- a/index.html +++ b/index.html @@ -2223,70 +2223,70 @@ function formatCommentText(text) { } // Function to submit a new comment -async function submitComment(proposalId, form) { - const commentInput = form.querySelector('.comment-input'); - const submitButton = form.querySelector('.comment-submit'); - - const commentText = commentInput.value.trim(); - - if (!commentText) return; - - // Disable form while submitting - commentInput.disabled = true; - submitButton.disabled = true; - - try { - const response = await safeFetch(`${API_BASE_URL}/comments`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - proposalId: proposalId, - userId: currentUser.id, - commentText: commentText - }) - }); +async function submitComment(proposalId, commentText) { + // If commentText is an element, extract the value (backward compatibility) + if (typeof commentText !== 'string') { + const form = commentText; + const commentInput = form.querySelector('.comment-input'); + commentText = commentInput.value.trim(); - if (!response.ok) { - throw new Error('Failed to submit comment'); + // Disable form while submitting + commentInput.disabled = true; + const submitButton = form.querySelector('.comment-submit'); + submitButton.disabled = true; + + // Enable form when done + const enableForm = () => { + commentInput.disabled = false; + submitButton.disabled = false; + }; + + // Return early if empty + if (!commentText) { + enableForm(); + return; } - // Clear input + // Clear input optimistically commentInput.value = ''; - - // Reload comments to show the new one - const commentsContainer = document.querySelector(`.comments-container[data-proposal-id="${proposalId}"]`); - const commentsContent = commentsContainer.querySelector('.comments-content'); - - // Add new comment to the top (optimistic update) - const newComment = await response.json(); - const tempCommentHtml = ` -