2026-01-27 16:21:58 +00:00
|
|
|
---
|
2026-01-29 10:38:43 +00:00
|
|
|
export const prerender = false;
|
2026-01-27 16:21:58 +00:00
|
|
|
import Layout from '../layouts/Layout.astro';
|
|
|
|
|
import { API_BASE as apiBase } from '../lib/api';
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
<Layout title="All Proposals">
|
|
|
|
|
<section class="proposals-page">
|
|
|
|
|
<div class="header-row">
|
|
|
|
|
<div>
|
|
|
|
|
<h1>All Proposals</h1>
|
|
|
|
|
<p class="subtitle">Browse proposals across all communities</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="filters">
|
|
|
|
|
<input type="text" id="search-input" placeholder="Search proposals..." />
|
|
|
|
|
<select id="status-filter">
|
|
|
|
|
<option value="">All Statuses</option>
|
|
|
|
|
<option value="draft">Draft</option>
|
|
|
|
|
<option value="discussion">Discussion</option>
|
|
|
|
|
<option value="voting">Voting</option>
|
|
|
|
|
<option value="closed">Closed</option>
|
|
|
|
|
</select>
|
|
|
|
|
<select id="sort-filter">
|
|
|
|
|
<option value="newest">Newest First</option>
|
|
|
|
|
<option value="oldest">Oldest First</option>
|
|
|
|
|
<option value="most-votes">Most Votes</option>
|
|
|
|
|
<option value="most-comments">Most Comments</option>
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div id="proposals-list" class="list">
|
|
|
|
|
<p class="loading">Loading proposals...</p>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
</Layout>
|
|
|
|
|
|
|
|
|
|
<script define:vars={{ apiBase }}>
|
|
|
|
|
let allProposals = [];
|
|
|
|
|
|
|
|
|
|
async function loadProposals() {
|
|
|
|
|
const container = document.getElementById('proposals-list');
|
|
|
|
|
if (!container) return;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetch(`${apiBase}/api/proposals`);
|
|
|
|
|
allProposals = await res.json();
|
|
|
|
|
renderProposals(allProposals);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
container.innerHTML = '<div class="error"><p>Failed to load proposals.</p></div>';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderProposals(proposals) {
|
|
|
|
|
const container = document.getElementById('proposals-list');
|
|
|
|
|
if (!container) return;
|
|
|
|
|
|
|
|
|
|
if (proposals.length === 0) {
|
|
|
|
|
container.innerHTML = '<div class="empty"><p>No proposals found.</p></div>';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
container.innerHTML = proposals.map(p => `
|
|
|
|
|
<a href="/proposals/${p.id}" class="proposal-card">
|
|
|
|
|
<div class="proposal-header">
|
|
|
|
|
<h3>${p.title}</h3>
|
2026-01-29 16:45:49 +00:00
|
|
|
<span class="ui-pill status-${p.status}">${p.status}</span>
|
2026-01-27 16:21:58 +00:00
|
|
|
</div>
|
|
|
|
|
<p class="community">in <span>${p.community_name}</span></p>
|
|
|
|
|
<p class="description">${p.description.substring(0, 120)}${p.description.length > 120 ? '...' : ''}</p>
|
|
|
|
|
<div class="proposal-stats">
|
|
|
|
|
<span class="stat">🗳️ ${p.vote_count} votes</span>
|
|
|
|
|
<span class="stat">💬 ${p.comment_count} comments</span>
|
|
|
|
|
</div>
|
|
|
|
|
</a>
|
|
|
|
|
`).join('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function filterProposals() {
|
|
|
|
|
const searchInput = document.getElementById('search-input');
|
|
|
|
|
const statusFilter = document.getElementById('status-filter');
|
|
|
|
|
const sortFilter = document.getElementById('sort-filter');
|
|
|
|
|
|
|
|
|
|
const query = searchInput?.value.toLowerCase().trim() || '';
|
|
|
|
|
const status = statusFilter?.value || '';
|
|
|
|
|
const sort = sortFilter?.value || 'newest';
|
|
|
|
|
|
|
|
|
|
let filtered = [...allProposals];
|
|
|
|
|
|
|
|
|
|
if (query) {
|
|
|
|
|
filtered = filtered.filter(p =>
|
|
|
|
|
p.title.toLowerCase().includes(query) ||
|
|
|
|
|
p.description.toLowerCase().includes(query) ||
|
|
|
|
|
p.community_name.toLowerCase().includes(query)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (status) {
|
|
|
|
|
filtered = filtered.filter(p => p.status === status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sort
|
|
|
|
|
switch (sort) {
|
|
|
|
|
case 'oldest':
|
|
|
|
|
filtered.sort((a, b) => new Date(a.created_at).getTime() - new Date(b.created_at).getTime());
|
|
|
|
|
break;
|
|
|
|
|
case 'most-votes':
|
|
|
|
|
filtered.sort((a, b) => b.vote_count - a.vote_count);
|
|
|
|
|
break;
|
|
|
|
|
case 'most-comments':
|
|
|
|
|
filtered.sort((a, b) => b.comment_count - a.comment_count);
|
|
|
|
|
break;
|
|
|
|
|
default: // newest
|
|
|
|
|
filtered.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderProposals(filtered);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadProposals();
|
|
|
|
|
|
|
|
|
|
document.getElementById('search-input')?.addEventListener('input', filterProposals);
|
|
|
|
|
document.getElementById('status-filter')?.addEventListener('change', filterProposals);
|
|
|
|
|
document.getElementById('sort-filter')?.addEventListener('change', filterProposals);
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
.proposals-page {
|
|
|
|
|
padding: 2rem 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.header-row {
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
align-items: flex-start;
|
|
|
|
|
margin-bottom: 2rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
h1 {
|
|
|
|
|
font-size: 2.5rem;
|
|
|
|
|
margin-bottom: 0.5rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.subtitle {
|
|
|
|
|
color: var(--color-text-muted);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.filters {
|
|
|
|
|
display: flex;
|
|
|
|
|
gap: 1rem;
|
|
|
|
|
margin-bottom: 1.5rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.filters input, .filters select {
|
|
|
|
|
border-radius: var(--radius-md);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.filters input {
|
|
|
|
|
flex: 1;
|
|
|
|
|
max-width: 300px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.filters select {
|
|
|
|
|
min-width: 150px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.list {
|
|
|
|
|
display: grid;
|
|
|
|
|
gap: 1rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.proposal-card {
|
|
|
|
|
display: block;
|
|
|
|
|
background: var(--color-surface);
|
|
|
|
|
border: 1px solid var(--color-border);
|
|
|
|
|
border-radius: var(--radius-lg);
|
|
|
|
|
padding: 1.5rem;
|
|
|
|
|
color: var(--color-text);
|
|
|
|
|
box-shadow: var(--shadow-sm);
|
|
|
|
|
transition: transform var(--motion-fast) var(--easing-standard), box-shadow var(--motion-fast) var(--easing-standard), border-color var(--motion-fast) var(--easing-standard);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.proposal-card:hover {
|
|
|
|
|
border-color: var(--color-border-hover);
|
|
|
|
|
transform: translateY(-1px);
|
|
|
|
|
box-shadow: var(--shadow-md);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.proposal-header {
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
align-items: center;
|
|
|
|
|
margin-bottom: 0.25rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.proposal-card h3 {
|
|
|
|
|
font-size: 1.25rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.status-draft { background: var(--color-neutral-muted); color: var(--color-on-primary); }
|
|
|
|
|
.status-discussion { background: var(--color-info); color: var(--color-on-primary); }
|
|
|
|
|
.status-voting { background: var(--color-success); color: var(--color-on-primary); }
|
|
|
|
|
.status-closed { background: var(--color-neutral); color: var(--color-on-primary); }
|
|
|
|
|
|
|
|
|
|
.community {
|
|
|
|
|
font-size: 0.75rem;
|
|
|
|
|
color: var(--color-text-muted);
|
|
|
|
|
margin-bottom: 0.5rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.community span {
|
|
|
|
|
color: var(--color-primary);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.description {
|
|
|
|
|
color: var(--color-text-muted);
|
|
|
|
|
font-size: 0.875rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.proposal-stats {
|
|
|
|
|
display: flex;
|
|
|
|
|
gap: 1rem;
|
|
|
|
|
margin-top: 0.75rem;
|
|
|
|
|
padding-top: 0.75rem;
|
|
|
|
|
border-top: 1px solid var(--color-border);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.proposal-stats .stat {
|
|
|
|
|
font-size: 0.75rem;
|
|
|
|
|
color: var(--color-text-muted);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.loading, .empty, .error {
|
|
|
|
|
text-align: center;
|
|
|
|
|
padding: 3rem;
|
|
|
|
|
color: var(--color-text-muted);
|
|
|
|
|
}
|
|
|
|
|
</style>
|