What Do You Want?
I Want My Own _________.

Maybe We're Here To Decide What We Want
What The People Want:
Loading what the people want...
Nothing here yet.
'; return; } submissions.forEach(item => { const entry = document.createElement('div'); entry.className = 'iwmo-want'; let answer = item.answer.trim(); /* Remove "I want my own" if they already typed it */ answer = answer.replace(/^i\s+want\s+my\s+own\s*/i, ''); const prefix = document.createElement('div'); prefix.className = 'iwmo-prefix'; prefix.textContent = 'I Want My Own'; const answerText = document.createElement('div'); answerText.className = 'iwmo-answer'; answerText.textContent = answer; /* Voting controls */ const votes = document.createElement('div'); votes.className = 'iwmo-votes'; const upButton = document.createElement('button'); upButton.className = 'iwmo-vote'; upButton.type = 'button'; upButton.textContent = '👍'; upButton.setAttribute('aria-label', 'Like'); const downButton = document.createElement('button'); downButton.className = 'iwmo-vote'; downButton.type = 'button'; downButton.textContent = '👎'; downButton.setAttribute('aria-label', 'Dislike'); if (savedVotes[item.id] === 1) { upButton.classList.add('active'); } if (savedVotes[item.id] === -1) { downButton.classList.add('active'); } upButton.addEventListener('click', function () { toggleVote(item.id, 1, upButton, downButton); }); downButton.addEventListener('click', function () { toggleVote(item.id, -1, upButton, downButton); }); votes.appendChild(upButton); votes.appendChild(downButton); entry.appendChild(prefix); entry.appendChild(answerText); entry.appendChild(votes); container.appendChild(entry); }); } catch (error) { console.error(error); container.innerHTML = ''; } })(); 
IWMO ADMIN
Sign in to continue
IWMO ADMIN
Pending Submissions
Loading submissions...
VOTE ACTIVITY
Loading votes...
SUBSCRIBERS
Loading subscribers...
Loading submissions...
'; try { const response = await fetch( SUPABASE_URL + '/rest/v1/Submissions' + '?select=id,answer,created_at' + '&approved=eq.false' + '&reviewed=eq.false' + '&order=created_at.desc', { headers: { 'apikey': API_KEY, 'Authorization': 'Bearer ' + accessToken } } ); if (!response.ok) { throw new Error('Could not load submissions'); } const submissions = await response.json(); list.innerHTML = ''; if (submissions.length === 0) { list.innerHTML = 'All caught up.
'; return; } submissions.forEach(function(item) { const card = document.createElement('div'); card.className = 'iwmo-admin-card'; const answer = document.createElement('div'); answer.className = 'iwmo-admin-answer'; answer.textContent = item.answer; const date = document.createElement('div'); date.className = 'iwmo-admin-date'; date.textContent = new Date(item.created_at).toLocaleString(); const actions = document.createElement('div'); actions.className = 'iwmo-admin-actions'; const approve = document.createElement('button'); approve.className = 'iwmo-approve'; approve.textContent = 'APPROVE'; const deny = document.createElement('button'); deny.className = 'iwmo-deny'; deny.textContent = 'DENY'; approve.addEventListener( 'click', function() { reviewSubmission( item.id, true, card, approve, deny ); } ); deny.addEventListener( 'click', function() { reviewSubmission( item.id, false, card, approve, deny ); } ); actions.appendChild(approve); actions.appendChild(deny); card.appendChild(answer); card.appendChild(date); card.appendChild(actions); list.appendChild(card); }); } catch (error) { console.error(error); list.innerHTML = 'Could not load submissions.
'; } } /* ---------------- VOTE ACTIVITY ---------------- */ async function loadVotes() { voteList.innerHTML = 'Loading votes...
'; try { const response = await fetch( SUPABASE_URL + '/rest/v1/rpc/get_vote_summary', { method: 'POST', headers: { 'apikey': API_KEY, 'Authorization': 'Bearer ' + accessToken, 'Content-Type': 'application/json' } } ); if (!response.ok) { throw new Error('Could not load votes'); } const votes = await response.json(); voteList.innerHTML = ''; if (votes.length === 0) { voteList.innerHTML = 'No votes yet.
'; return; } votes.forEach(function(item) { const card = document.createElement('div'); card.className = 'iwmo-vote-card'; const answer = document.createElement('div'); answer.className = 'iwmo-vote-answer'; answer.textContent = 'I Want My Own ' + item.answer; const stats = document.createElement('div'); stats.className = 'iwmo-vote-stats'; stats.textContent = '👍 ' + item.thumbs_up + ' 👎 ' + item.thumbs_down + ' NET ' + (item.net_votes > 0 ? '+' : '') + item.net_votes; card.appendChild(answer); card.appendChild(stats); voteList.appendChild(card); }); } catch (error) { console.error(error); voteList.innerHTML = 'Could not load votes.
'; } } /* ---------------- SUBSCRIBERS ---------------- */ async function loadSubscribers() { subscriberList.innerHTML = 'Loading subscribers...
'; try { const response = await fetch( SUPABASE_URL + '/rest/v1/subscribers?select=email,created_at,submission_id,Submissions(answer)&order=created_at.desc', { headers: { 'apikey': API_KEY, 'Authorization': 'Bearer ' + accessToken } } ); if (!response.ok) { throw new Error('Could not load subscribers'); } const subscribers = await response.json(); subscriberList.innerHTML = ''; if (subscribers.length === 0) { subscriberList.innerHTML = 'No subscribers yet.
'; return; } subscribers.forEach(function(item) { const card = document.createElement('div'); card.className = 'iwmo-subscriber-card'; const email = document.createElement('div'); email.className = 'iwmo-subscriber-email'; email.textContent = item.email; const want = document.createElement('div'); want.className = 'iwmo-subscriber-want'; want.textContent = item.Submissions && item.Submissions.answer ? 'I Want My Own ' + item.Submissions.answer : 'Submission #' + item.submission_id; const date = document.createElement('div'); date.className = 'iwmo-subscriber-date'; date.textContent = new Date(item.created_at).toLocaleDateString(); card.appendChild(email); card.appendChild(want); card.appendChild(date); subscriberList.appendChild(card); }); } catch (error) { console.error(error); subscriberList.innerHTML = 'Could not load subscribers.
'; } } /* ---------------- APPROVE / DENY ---------------- */ async function reviewSubmission( id, approved, card, approveButton, denyButton ) { approveButton.disabled = true; denyButton.disabled = true; try { const response = await fetch( SUPABASE_URL + '/rest/v1/Submissions?id=eq.' + encodeURIComponent(id), { method: 'PATCH', headers: { 'apikey': API_KEY, 'Authorization': 'Bearer ' + accessToken, 'Content-Type': 'application/json', 'Prefer': 'return=minimal' }, body: JSON.stringify({ approved: approved, reviewed: true }) } ); if (!response.ok) { throw new Error( 'Could not update submission' ); } card.remove(); if ( list.querySelectorAll( '.iwmo-admin-card' ).length === 0 ) { list.innerHTML = 'All caught up.
'; } } catch (error) { console.error(error); approveButton.disabled = false; denyButton.disabled = false; alert( 'Something went wrong. Try again.' ); } } /* ---------------- LOG OUT ---------------- */ document .getElementById('iwmo-logout') .addEventListener('click', function() { accessToken = null; sessionStorage.removeItem( 'iwmo_admin_token' ); dashboard.style.display = 'none'; loginArea.style.display = 'block'; document.getElementById( 'iwmo-password' ).value = ''; loginMessage.textContent = ''; }); /* ---------------- EXISTING SESSION ---------------- */ const savedToken = sessionStorage.getItem( 'iwmo_admin_token' ); if (savedToken) { accessToken = savedToken; loginArea.style.display = 'none'; dashboard.style.display = 'block'; await loadSubmissions(); await loadVotes(); await loadSubscribers(); } })();