829 lines
No EOL
28 KiB
HTML
829 lines
No EOL
28 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>RADICAL - Australia's Democratic Revolution</title>
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@300;400;500;600;700&display=swap" rel="stylesheet">
|
|
<style>
|
|
:root {
|
|
--primary: #ff0099;
|
|
--primary-light: #ff66c4;
|
|
--primary-dark: #cc007a;
|
|
--secondary: #ffffff;
|
|
--accent: #ff0099;
|
|
--dark: #000000;
|
|
--darker: #111111;
|
|
--light: #ffffff;
|
|
--border: #333333;
|
|
--text: #ffffff;
|
|
--text-muted: #aaaaaa;
|
|
--success: #ff0099;
|
|
--danger: #ff0099;
|
|
--card-bg: rgba(0, 0, 0, 0.8);
|
|
}
|
|
|
|
* {
|
|
box-sizing: border-box;
|
|
margin: 0;
|
|
padding: 0;
|
|
font-family: 'Roboto Mono', monospace;
|
|
}
|
|
|
|
body {
|
|
background-color: var(--dark);
|
|
color: var(--text);
|
|
line-height: 1.6;
|
|
overflow-x: hidden;
|
|
}
|
|
|
|
.container {
|
|
max-width: 800px;
|
|
margin: 0 auto;
|
|
padding: 40px 20px;
|
|
}
|
|
|
|
header {
|
|
text-align: center;
|
|
margin-bottom: 50px;
|
|
padding: 40px 20px;
|
|
border-radius: 0;
|
|
background: var(--card-bg);
|
|
border: 1px solid var(--primary);
|
|
box-shadow: 0 0 20px rgba(255, 0, 153, 0.3);
|
|
}
|
|
|
|
header h1 {
|
|
font-size: 4rem;
|
|
font-weight: 700;
|
|
letter-spacing: -2px;
|
|
margin-bottom: 5px;
|
|
text-transform: uppercase;
|
|
color: var(--primary);
|
|
text-shadow: 0 0 10px rgba(255, 0, 153, 0.5);
|
|
}
|
|
|
|
header p {
|
|
font-size: 1.1rem;
|
|
font-weight: 400;
|
|
margin-top: 10px;
|
|
max-width: 600px;
|
|
margin-left: auto;
|
|
margin-right: auto;
|
|
color: var(--text);
|
|
}
|
|
|
|
.tagline {
|
|
display: inline-block;
|
|
background-color: var(--primary);
|
|
padding: 8px 20px;
|
|
border-radius: 0;
|
|
font-size: 0.9rem;
|
|
margin-top: 20px;
|
|
letter-spacing: 1px;
|
|
text-transform: uppercase;
|
|
color: var(--dark);
|
|
font-weight: 600;
|
|
}
|
|
|
|
.new-proposal {
|
|
background: var(--card-bg);
|
|
border-radius: 0;
|
|
padding: 30px;
|
|
margin-bottom: 40px;
|
|
box-shadow: 0 0 20px rgba(255, 0, 153, 0.2);
|
|
border: 1px solid var(--border);
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.new-proposal:hover {
|
|
box-shadow: 0 0 30px rgba(255, 0, 153, 0.3);
|
|
border-color: var(--primary);
|
|
}
|
|
|
|
.proposal-input {
|
|
width: 100%;
|
|
padding: 20px;
|
|
border: none;
|
|
border-radius: 0;
|
|
resize: none;
|
|
font-size: 16px;
|
|
margin-bottom: 15px;
|
|
background-color: rgba(17, 17, 17, 1);
|
|
color: var(--text);
|
|
box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
|
|
transition: all 0.3s ease;
|
|
border: 1px solid var(--border);
|
|
font-family: 'Roboto Mono', monospace;
|
|
}
|
|
|
|
.proposal-input:focus {
|
|
outline: none;
|
|
box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5), 0 0 0 2px rgba(255, 0, 153, 0.3);
|
|
border-color: var(--primary);
|
|
}
|
|
|
|
.proposal-input::placeholder {
|
|
color: var(--text-muted);
|
|
}
|
|
|
|
.char-counter {
|
|
font-size: 14px;
|
|
color: var(--text-muted);
|
|
text-align: right;
|
|
margin-bottom: 20px;
|
|
font-weight: 400;
|
|
}
|
|
|
|
.char-counter.limit {
|
|
color: var(--primary);
|
|
font-weight: 700;
|
|
}
|
|
|
|
.post-button {
|
|
background-color: var(--primary);
|
|
color: var(--dark);
|
|
border: none;
|
|
border-radius: 0;
|
|
padding: 12px 30px;
|
|
font-size: 16px;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
float: right;
|
|
text-transform: uppercase;
|
|
letter-spacing: 1px;
|
|
box-shadow: 0 0 10px rgba(255, 0, 153, 0.3);
|
|
transition: all 0.3s ease;
|
|
font-family: 'Roboto Mono', monospace;
|
|
}
|
|
|
|
.post-button:hover {
|
|
background-color: var(--primary-light);
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 0 15px rgba(255, 0, 153, 0.4);
|
|
}
|
|
|
|
.post-button:active {
|
|
transform: translateY(1px);
|
|
box-shadow: 0 0 5px rgba(255, 0, 153, 0.4);
|
|
}
|
|
|
|
.post-button:disabled {
|
|
background-color: #333;
|
|
color: #555;
|
|
cursor: not-allowed;
|
|
box-shadow: none;
|
|
transform: none;
|
|
}
|
|
|
|
.proposals {
|
|
margin-top: 40px;
|
|
}
|
|
|
|
.filter-bar {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 30px;
|
|
border-bottom: 1px solid var(--border);
|
|
padding-bottom: 15px;
|
|
}
|
|
|
|
.filter-title {
|
|
font-size: 1.1rem;
|
|
font-weight: 600;
|
|
text-transform: uppercase;
|
|
letter-spacing: 1px;
|
|
color: var(--primary);
|
|
}
|
|
|
|
.sort-select {
|
|
padding: 10px 20px;
|
|
border-radius: 0;
|
|
border: 1px solid var(--border);
|
|
background-color: var(--darker);
|
|
color: var(--text);
|
|
font-size: 14px;
|
|
cursor: pointer;
|
|
transition: all 0.3s ease;
|
|
font-family: 'Roboto Mono', monospace;
|
|
}
|
|
|
|
.sort-select:hover {
|
|
border-color: var(--primary);
|
|
}
|
|
|
|
.sort-select:focus {
|
|
outline: none;
|
|
box-shadow: 0 0 0 2px rgba(255, 0, 153, 0.3);
|
|
}
|
|
|
|
.proposal-card {
|
|
background: var(--card-bg);
|
|
border-radius: 0;
|
|
padding: 30px;
|
|
margin-bottom: 25px;
|
|
box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
|
|
border: 1px solid var(--border);
|
|
transition: all 0.3s ease;
|
|
position: relative;
|
|
}
|
|
|
|
.proposal-card:hover {
|
|
transform: translateY(-3px);
|
|
box-shadow: 0 0 30px rgba(255, 0, 153, 0.2);
|
|
border-color: var(--primary);
|
|
}
|
|
|
|
.proposal-author {
|
|
font-weight: 600;
|
|
margin-bottom: 15px;
|
|
font-size: 1rem;
|
|
color: var(--primary);
|
|
}
|
|
|
|
.proposal-text {
|
|
margin-bottom: 25px;
|
|
word-wrap: break-word;
|
|
font-size: 1.1rem;
|
|
line-height: 1.7;
|
|
color: var(--text);
|
|
}
|
|
|
|
.proposal-stats {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
font-size: 14px;
|
|
border-top: 1px solid var(--border);
|
|
padding-top: 15px;
|
|
}
|
|
|
|
.vote-buttons {
|
|
display: flex;
|
|
gap: 15px;
|
|
}
|
|
|
|
.vote-button {
|
|
background: var(--darker);
|
|
border: 1px solid var(--border);
|
|
cursor: pointer;
|
|
display: flex;
|
|
align-items: center;
|
|
color: var(--text-muted);
|
|
font-size: 14px;
|
|
transition: all 0.2s ease;
|
|
padding: 6px 14px;
|
|
border-radius: 0;
|
|
font-family: 'Roboto Mono', monospace;
|
|
}
|
|
|
|
.vote-button:hover {
|
|
background-color: var(--darker);
|
|
color: var(--text);
|
|
border-color: var(--primary);
|
|
}
|
|
|
|
.vote-button.upvoted {
|
|
color: var(--dark);
|
|
background-color: var(--primary);
|
|
border-color: var(--primary);
|
|
}
|
|
|
|
.vote-button.downvoted {
|
|
color: var(--primary);
|
|
background-color: transparent;
|
|
border-color: var(--primary);
|
|
}
|
|
|
|
.vote-icon {
|
|
margin-right: 8px;
|
|
font-size: 16px;
|
|
}
|
|
|
|
.vote-count {
|
|
font-weight: 600;
|
|
}
|
|
|
|
.net-votes {
|
|
margin-left: 10px;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.net-votes.positive {
|
|
color: var(--primary);
|
|
}
|
|
|
|
.net-votes.negative {
|
|
color: var(--text-muted);
|
|
}
|
|
|
|
.proposal-time {
|
|
color: var(--text-muted);
|
|
font-size: 0.85rem;
|
|
}
|
|
|
|
.empty-state {
|
|
text-align: center;
|
|
padding: 60px 40px;
|
|
color: var(--text-muted);
|
|
background: var(--card-bg);
|
|
border-radius: 0;
|
|
border: 1px dashed var(--border);
|
|
}
|
|
|
|
.empty-state p {
|
|
font-size: 1.2rem;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.power-badge {
|
|
position: absolute;
|
|
top: 20px;
|
|
right: 20px;
|
|
background-color: var(--primary);
|
|
color: var(--dark);
|
|
padding: 5px 12px;
|
|
border-radius: 0;
|
|
font-size: 12px;
|
|
font-weight: 600;
|
|
text-transform: uppercase;
|
|
letter-spacing: 1px;
|
|
}
|
|
|
|
.trending-badge {
|
|
background-color: var(--light);
|
|
color: var(--dark);
|
|
}
|
|
|
|
footer {
|
|
text-align: center;
|
|
margin-top: 80px;
|
|
padding: 30px 20px;
|
|
color: var(--text-muted);
|
|
font-size: 14px;
|
|
border-top: 1px solid var(--border);
|
|
}
|
|
|
|
.footer-links {
|
|
display: flex;
|
|
justify-content: center;
|
|
gap: 30px;
|
|
margin-top: 20px;
|
|
}
|
|
|
|
.footer-links a {
|
|
color: var(--primary);
|
|
text-decoration: none;
|
|
transition: all 0.3s ease;
|
|
font-weight: 500;
|
|
}
|
|
|
|
.footer-links a:hover {
|
|
color: var(--primary-light);
|
|
text-decoration: underline;
|
|
}
|
|
|
|
.loading-indicator {
|
|
text-align: center;
|
|
padding: 30px;
|
|
color: var(--text-muted);
|
|
}
|
|
|
|
.loading-spinner {
|
|
display: inline-block;
|
|
width: 30px;
|
|
height: 30px;
|
|
border: 3px solid var(--primary);
|
|
border-radius: 50%;
|
|
border-top-color: transparent;
|
|
animation: spin 1s linear infinite;
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
@keyframes spin {
|
|
to { transform: rotate(360deg); }
|
|
}
|
|
|
|
.error-state {
|
|
text-align: center;
|
|
padding: 40px;
|
|
color: var(--text-muted);
|
|
background: var(--card-bg);
|
|
border-radius: 0;
|
|
border: 1px dashed var(--primary);
|
|
}
|
|
|
|
.error-state p {
|
|
font-size: 1.2rem;
|
|
margin-bottom: 20px;
|
|
color: var(--primary);
|
|
}
|
|
|
|
.retry-button {
|
|
background-color: var(--primary);
|
|
color: var(--dark);
|
|
border: none;
|
|
border-radius: 0;
|
|
padding: 10px 20px;
|
|
font-size: 14px;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
text-transform: uppercase;
|
|
letter-spacing: 1px;
|
|
margin-top: 15px;
|
|
font-family: 'Roboto Mono', monospace;
|
|
}
|
|
|
|
/* Responsive design */
|
|
@media (max-width: 600px) {
|
|
.container {
|
|
padding: 20px;
|
|
}
|
|
|
|
header h1 {
|
|
font-size: 2.5rem;
|
|
}
|
|
|
|
header, .new-proposal, .proposal-card {
|
|
padding: 25px;
|
|
}
|
|
|
|
.filter-bar {
|
|
flex-direction: column;
|
|
gap: 15px;
|
|
align-items: flex-start;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<header>
|
|
<h1>RADICAL</h1>
|
|
<div class="tagline">Vibe, Vote, Veto</div>
|
|
<p>Australia's direct democracy movement. Share policy ideas, vote on proposals, take back control.</p>
|
|
</header>
|
|
|
|
<section class="new-proposal">
|
|
<textarea id="proposal-input" class="proposal-input" placeholder="Your idea to revolutionize Australia? (280 character limit)" maxlength="280"></textarea>
|
|
<div id="char-counter" class="char-counter">280 characters remaining</div>
|
|
<button id="post-button" class="post-button" disabled>Post Proposal</button>
|
|
<div style="clear: both;"></div>
|
|
</section>
|
|
|
|
<section class="proposals">
|
|
<div class="filter-bar">
|
|
<div class="filter-title">Democracy Goes Brrr</div>
|
|
<select id="sort-select" class="sort-select">
|
|
<option value="newest">Latest Ideas</option>
|
|
<option value="popular">Most Supported</option>
|
|
<option value="controversial">Most Debated</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div id="proposals-container">
|
|
<div class="loading-indicator">
|
|
<div class="loading-spinner"></div>
|
|
<p>Loading democracy...</p>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<footer>
|
|
<p>RADICAL - Direct Democracy Movement 🇦🇺 © 2025</p>
|
|
<div class="footer-links">
|
|
<a href="#about">About Us</a>
|
|
<a href="#join">Join The Movement</a>
|
|
<a href="#events">Events</a>
|
|
<a href="#contact">Contact</a>
|
|
</div>
|
|
</footer>
|
|
</div>
|
|
|
|
<script>
|
|
// Configuration
|
|
const API_BASE_URL = 'https://radical.omar-c29.workers.dev'; // Replace with your actual worker URL
|
|
|
|
// DOM elements
|
|
const proposalInput = document.getElementById('proposal-input');
|
|
const charCounter = document.getElementById('char-counter');
|
|
const postButton = document.getElementById('post-button');
|
|
const proposalsContainer = document.getElementById('proposals-container');
|
|
const sortSelect = document.getElementById('sort-select');
|
|
|
|
// Character limit
|
|
const CHAR_LIMIT = 280;
|
|
|
|
// User information (in a real app, this would come from authentication)
|
|
let currentUser = JSON.parse(localStorage.getItem('radical_user'));
|
|
|
|
// If no user exists, create a new one
|
|
if (!currentUser) {
|
|
currentUser = {
|
|
id: 'citizen_' + Math.random().toString(36).substr(2, 9),
|
|
name: 'Citizen ' + Math.floor(Math.random() * 9000 + 1000)
|
|
};
|
|
|
|
// Save user to local storage
|
|
localStorage.setItem('radical_user', JSON.stringify(currentUser));
|
|
|
|
// Create user in database
|
|
createUser(currentUser);
|
|
}
|
|
|
|
// Create user in database
|
|
async function createUser(user) {
|
|
try {
|
|
const response = await fetch(`${API_BASE_URL}/users`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
id: user.id,
|
|
name: user.name
|
|
})
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error('Failed to create user');
|
|
}
|
|
} catch (error) {
|
|
console.error('Error creating user:', error);
|
|
}
|
|
}
|
|
|
|
// Catchy political slogans for placeholder text
|
|
const placeholders = [
|
|
"Your idea to revolutionize Australia? (280 character limit)",
|
|
"Got a hot take on Australian politics? (280 character limit)",
|
|
"Parliament failed the vibe check. Your solution? (280 character limit)",
|
|
"What would make Australia actually slap? (280 character limit)",
|
|
"Drop your 🔥 policy idea here (280 character limit)"
|
|
];
|
|
|
|
// Rotate placeholder text every 5 seconds
|
|
let placeholderIndex = 0;
|
|
setInterval(() => {
|
|
placeholderIndex = (placeholderIndex + 1) % placeholders.length;
|
|
proposalInput.placeholder = placeholders[placeholderIndex];
|
|
}, 5000);
|
|
|
|
// Update character counter
|
|
proposalInput.addEventListener('input', () => {
|
|
const remaining = CHAR_LIMIT - proposalInput.value.length;
|
|
charCounter.textContent = `${remaining} characters remaining`;
|
|
|
|
if (remaining < 20) {
|
|
charCounter.classList.add('limit');
|
|
} else {
|
|
charCounter.classList.remove('limit');
|
|
}
|
|
|
|
// Enable/disable post button
|
|
postButton.disabled = proposalInput.value.trim().length === 0;
|
|
});
|
|
|
|
// Post new proposal
|
|
postButton.addEventListener('click', async () => {
|
|
const text = proposalInput.value.trim();
|
|
|
|
if (text) {
|
|
try {
|
|
const trending = Math.random() > 0.8; // Randomly mark some as trending for effect
|
|
|
|
const response = await fetch(`${API_BASE_URL}/proposals`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
authorId: currentUser.id,
|
|
text: text,
|
|
trending: trending
|
|
})
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error('Failed to create proposal');
|
|
}
|
|
|
|
// Clear input
|
|
proposalInput.value = '';
|
|
charCounter.textContent = `${CHAR_LIMIT} characters remaining`;
|
|
postButton.disabled = true;
|
|
|
|
// Show success animation
|
|
animatePostSuccess();
|
|
|
|
// Refresh proposals
|
|
fetchProposals();
|
|
} catch (error) {
|
|
console.error('Error creating proposal:', error);
|
|
showErrorMessage('Failed to post your proposal. Parliament might be onto us!');
|
|
}
|
|
}
|
|
});
|
|
|
|
// Animation for successful post
|
|
function animatePostSuccess() {
|
|
const successEl = document.createElement('div');
|
|
successEl.textContent = '🔥 Take that, Parliament!';
|
|
successEl.style.position = 'fixed';
|
|
successEl.style.bottom = '20px';
|
|
successEl.style.left = '50%';
|
|
successEl.style.transform = 'translateX(-50%)';
|
|
successEl.style.backgroundColor = 'var(--primary)';
|
|
successEl.style.color = 'var(--dark)';
|
|
successEl.style.padding = '12px 24px';
|
|
successEl.style.borderRadius = '0';
|
|
successEl.style.zIndex = '1000';
|
|
successEl.style.boxShadow = '0 0 20px rgba(255, 0, 153, 0.5)';
|
|
successEl.style.transition = 'all 0.4s cubic-bezier(0.16, 1, 0.3, 1)';
|
|
successEl.style.opacity = '0';
|
|
successEl.style.fontSize = '14px';
|
|
successEl.style.fontWeight = '700';
|
|
successEl.style.fontFamily = "'Roboto Mono', monospace";
|
|
|
|
document.body.appendChild(successEl);
|
|
|
|
// Fade in
|
|
setTimeout(() => {
|
|
successEl.style.opacity = '1';
|
|
}, 100);
|
|
|
|
// Fade out
|
|
setTimeout(() => {
|
|
successEl.style.opacity = '0';
|
|
setTimeout(() => {
|
|
document.body.removeChild(successEl);
|
|
}, 500);
|
|
}, 3000);
|
|
}
|
|
|
|
// Show loading indicator
|
|
function showLoadingIndicator() {
|
|
proposalsContainer.innerHTML = `
|
|
<div class="loading-indicator">
|
|
<div class="loading-spinner"></div>
|
|
<p>Loading democracy...</p>
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
// Show error message
|
|
function showErrorMessage(message, isRetryable = true) {
|
|
proposalsContainer.innerHTML = `
|
|
<div class="error-state">
|
|
<p>${message}</p>
|
|
${isRetryable ? '<button class="retry-button" onclick="fetchProposals()">Try Again</button>' : ''}
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
// Sort proposals when sort option changes
|
|
sortSelect.addEventListener('change', fetchProposals);
|
|
|
|
// Fetch proposals from API
|
|
async function fetchProposals() {
|
|
try {
|
|
// Show loading indicator
|
|
showLoadingIndicator();
|
|
|
|
const sortBy = sortSelect.value;
|
|
const response = await fetch(`${API_BASE_URL}/proposals?sortBy=${sortBy}&userId=${currentUser.id}`);
|
|
|
|
if (!response.ok) {
|
|
throw new Error('Failed to fetch proposals');
|
|
}
|
|
|
|
const proposals = await response.json();
|
|
renderProposals(proposals);
|
|
} catch (error) {
|
|
console.error('Error fetching proposals:', error);
|
|
showErrorMessage('Oops! Failed to load proposals. Parliament might be censoring us already!');
|
|
}
|
|
}
|
|
|
|
// Handle voting
|
|
async function handleVote(proposalId, voteType) {
|
|
try {
|
|
const response = await fetch(`${API_BASE_URL}/votes`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
proposalId: proposalId,
|
|
userId: currentUser.id,
|
|
voteType: voteType
|
|
})
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error('Failed to submit vote');
|
|
}
|
|
|
|
// Refresh proposals to show updated votes
|
|
fetchProposals();
|
|
} catch (error) {
|
|
console.error('Error voting:', error);
|
|
showErrorMessage('Hmm, your vote didn\'t count. That\'s a bit suspicious, isn\'t it?');
|
|
}
|
|
}
|
|
|
|
// Format date
|
|
function formatDate(timestamp) {
|
|
const now = new Date();
|
|
const date = new Date(timestamp);
|
|
const diffMs = now - date;
|
|
const diffSec = Math.floor(diffMs / 1000);
|
|
const diffMin = Math.floor(diffSec / 60);
|
|
const diffHour = Math.floor(diffMin / 60);
|
|
const diffDay = Math.floor(diffHour / 24);
|
|
|
|
if (diffSec < 60) {
|
|
return 'just now';
|
|
} else if (diffMin < 60) {
|
|
return diffMin + (diffMin === 1 ? ' minute ago' : ' minutes ago');
|
|
} else if (diffHour < 24) {
|
|
return diffHour + (diffHour === 1 ? ' hour ago' : ' hours ago');
|
|
} else if (diffDay < 30) {
|
|
return diffDay + (diffDay === 1 ? ' day ago' : ' days ago');
|
|
} else {
|
|
return date.toLocaleDateString();
|
|
}
|
|
}
|
|
|
|
// Render proposals
|
|
function renderProposals(proposals) {
|
|
// Clear container
|
|
proposalsContainer.innerHTML = '';
|
|
|
|
// Show empty state if no proposals
|
|
if (!proposals || proposals.length === 0) {
|
|
proposalsContainer.innerHTML = `
|
|
<div class="empty-state">
|
|
<p>No proposals yet. Be the first to drop your hot take!</p>
|
|
</div>
|
|
`;
|
|
return;
|
|
}
|
|
|
|
// Render each proposal
|
|
proposals.forEach(proposal => {
|
|
const netVotes = proposal.upvotes - proposal.downvotes;
|
|
const voteClass = netVotes > 0 ? 'positive' : netVotes < 0 ? 'negative' : '';
|
|
|
|
const proposalCard = document.createElement('div');
|
|
proposalCard.className = 'proposal-card';
|
|
|
|
// Badge for trending or power proposals
|
|
const badgeHtml = proposal.trending ?
|
|
`<div class="power-badge trending-badge">🔥 Based</div>` :
|
|
(netVotes > 5 ? `<div class="power-badge">💯 Vibing</div>` : '');
|
|
|
|
proposalCard.innerHTML = `
|
|
${badgeHtml}
|
|
<div class="proposal-author">${proposal.author_name}</div>
|
|
<div class="proposal-text">${proposal.text}</div>
|
|
<div class="proposal-stats">
|
|
<div class="vote-buttons">
|
|
<button class="vote-button ${proposal.userVote === 'upvote' ? 'upvoted' : ''}" data-proposal-id="${proposal.id}" data-vote-type="upvote">
|
|
<span class="vote-icon">↑</span>
|
|
<span class="vote-count">${proposal.upvotes}</span>
|
|
</button>
|
|
<button class="vote-button ${proposal.userVote === 'downvote' ? 'downvoted' : ''}" data-proposal-id="${proposal.id}" data-vote-type="downvote">
|
|
<span class="vote-icon">↓</span>
|
|
<span class="vote-count">${proposal.downvotes}</span>
|
|
</button>
|
|
<span class="net-votes ${voteClass}">${netVotes > 0 ? '+' : ''}${netVotes}</span>
|
|
</div>
|
|
<div class="proposal-time">${formatDate(proposal.timestamp)}</div>
|
|
</div>
|
|
`;
|
|
|
|
proposalsContainer.appendChild(proposalCard);
|
|
|
|
// Add event listeners for vote buttons
|
|
const upvoteButton = proposalCard.querySelector('[data-vote-type="upvote"]');
|
|
const downvoteButton = proposalCard.querySelector('[data-vote-type="downvote"]');
|
|
|
|
upvoteButton.addEventListener('click', () => {
|
|
handleVote(proposal.id, 'upvote');
|
|
});
|
|
|
|
downvoteButton.addEventListener('click', () => {
|
|
handleVote(proposal.id, 'downvote');
|
|
});
|
|
});
|
|
}
|
|
|
|
// Initial load of proposals
|
|
fetchProposals();
|
|
</script>
|
|
</body>
|
|
</html> |