diff --git a/index.html b/index.html index 1b77f33..897ee34 100644 --- a/index.html +++ b/index.html @@ -750,7 +750,8 @@ function initializeShareButtons() { 'Accept': 'application/json' }, mode: 'cors', - credentials: 'same-origin' + credentials: 'same-origin', + cache: 'no-store' }); // Log the response details @@ -1174,7 +1175,7 @@ async function submitVoteToServer(proposalId, voteType, isPetition = false, peti voteData.petitionDetails = petitionDetails; } - const response = await safeFetch(`${API_BASE_URL}/votes`, { + return await safeFetch(`${API_BASE_URL}/votes`, { method: 'POST', headers: { 'Content-Type': 'application/json' @@ -1183,12 +1184,6 @@ async function submitVoteToServer(proposalId, voteType, isPetition = false, peti mode: 'cors', credentials: 'same-origin' }); - - if (!response.ok) { - throw new Error('Failed to submit vote'); - } - - return await response.json(); } // Replace the old submitVote function @@ -2172,7 +2167,7 @@ async function handleCommentVote(commentId, voteType) { // Submit vote to server try { - const response = await safeFetch(`${API_BASE_URL}/comment-votes`, { + await safeFetch(`${API_BASE_URL}/comment-votes`, { method: 'POST', headers: { 'Content-Type': 'application/json' @@ -2183,16 +2178,6 @@ async function handleCommentVote(commentId, voteType) { voteType: voteType }) }); - - if (!response.ok) { - throw new Error('Failed to submit comment vote'); - } - - const result = await response.json(); - - // If the server response indicates we should update the UI differently, we could handle that here - // But generally the optimistic UI update above should match the server result - } catch (error) { console.error('Error voting on comment:', error); showToastMessage('Hmm, your comment vote didn\'t count. Please try again.', '#ff0099'); @@ -2700,13 +2685,12 @@ function updateCommentCount(proposalId) { if (!commentsToggle) return; safeFetch(`${API_BASE_URL}/comments?proposalId=${proposalId}`) - .then(response => response.json()) .then(comments => { - const commentCount = comments.length; + const commentCount = Array.isArray(comments) ? comments.length : 0; const commentText = commentCount === 1 ? 'comment' : 'comments'; commentsToggle.innerHTML = ` ${commentCount} ${commentText}`; }) - .catch(error => { + .catch(() => { commentsToggle.innerHTML = ` 0 comments`; }); } @@ -2738,12 +2722,6 @@ function submitComment(proposalId, commentText) { commentText: commentText }) }) - .then(response => { - if (!response.ok) { - throw new Error('Failed to post comment'); - } - return response.json(); - }) .then(data => { loadComments(proposalId); updateCommentCount(proposalId); diff --git a/worker.js b/worker.js index e7c80da..9150bcd 100644 --- a/worker.js +++ b/worker.js @@ -1099,7 +1099,7 @@ async function getProposals(request, env) { total: proposals.results?.length || 0, hasMore: proposals.results?.length === limit } - }); + }, 200, 0); } catch (error) { console.error('Error retrieving proposals:', error); return createResponse({ @@ -2147,7 +2147,7 @@ function escapeHTML(text) { // Update the getShareableImageUrl function to use the SVG endpoint function getShareableImageUrl(proposal) { // Use the dynamic SVG endpoint with the proposal ID - return `https://theradicalparty.com/api//petition-svg?id=${proposal.id}`; + return `https://theradicalparty.com/api/petition-svg?id=${proposal.id}`; } // Update the serveCustomizedHtml function to use the SVG URL for meta tags diff --git a/wrangler.toml b/wrangler.toml index b9ff90a..c572ee8 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -45,10 +45,5 @@ zone_name = "theradicalparty.com" pattern = "theradicalparty.com/styles.css" zone_name = "theradicalparty.com" -# Pages integration -[pages] -build_command = "npm run build" -build_output_dir = "dist" -