mirror of
https://codeberg.org/likwid/likwid.git
synced 2026-02-10 05:23:09 +00:00
- Backend: Rust/Axum with PostgreSQL, plugin architecture - Frontend: Astro with polished UI - Voting methods: Approval, Ranked Choice, Schulze, STAR, Quadratic - Features: Liquid delegation, transparent moderation, structured deliberation - Documentation: User and admin guides in /docs - Deployment: Docker/Podman compose files for production and demo - Demo: Seeded data with 3 communities, 13 users, 7 proposals License: AGPLv3
349 lines
8.3 KiB
Text
349 lines
8.3 KiB
Text
---
|
|
import Layout from '../layouts/Layout.astro';
|
|
import { API_BASE as apiBase } from '../lib/api';
|
|
---
|
|
|
|
<Layout title="Dashboard">
|
|
<section class="dashboard">
|
|
<div id="dashboard-content">
|
|
<p class="loading">Loading...</p>
|
|
</div>
|
|
</section>
|
|
</Layout>
|
|
|
|
<script define:vars={{ apiBase }}>
|
|
const token = localStorage.getItem('token');
|
|
const userStr = localStorage.getItem('user');
|
|
|
|
if (!token || !userStr) {
|
|
window.location.href = '/login';
|
|
}
|
|
|
|
const user = JSON.parse(userStr || '{}');
|
|
|
|
async function loadDashboard() {
|
|
const container = document.getElementById('dashboard-content');
|
|
if (!container) return;
|
|
|
|
container.innerHTML = `
|
|
<div class="welcome">
|
|
<h1>Welcome, ${user.display_name || user.username}!</h1>
|
|
<p class="user-email">${user.email}</p>
|
|
</div>
|
|
|
|
<div class="dashboard-grid">
|
|
<div class="card">
|
|
<h2>My Communities</h2>
|
|
<div id="my-communities" class="card-content">
|
|
<p class="loading-small">Loading...</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<h2>My Proposals</h2>
|
|
<div id="my-proposals" class="card-content">
|
|
<p class="loading-small">Loading...</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<h2>Recent Activity</h2>
|
|
<div id="recent-activity" class="card-content">
|
|
<p class="loading-small">Loading...</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<h2>Quick Actions</h2>
|
|
<div class="quick-actions">
|
|
<a href="/communities/new" class="action-btn">Create Community</a>
|
|
<a href="/communities" class="action-btn secondary">Browse Communities</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="account-section">
|
|
<h2>Account</h2>
|
|
<button id="logout-btn" class="logout-btn">Logout</button>
|
|
</div>
|
|
`;
|
|
|
|
document.getElementById('logout-btn')?.addEventListener('click', () => {
|
|
localStorage.removeItem('token');
|
|
localStorage.removeItem('user');
|
|
window.location.href = '/';
|
|
});
|
|
|
|
loadMyCommunities();
|
|
loadMyProposals();
|
|
loadRecentActivity();
|
|
}
|
|
|
|
async function loadRecentActivity() {
|
|
const container = document.getElementById('recent-activity');
|
|
if (!container) return;
|
|
|
|
try {
|
|
const res = await fetch(`${apiBase}/api/activity/recent`);
|
|
const activities = await res.json();
|
|
|
|
if (activities.length === 0) {
|
|
container.innerHTML = '<p class="empty-small">No recent activity</p>';
|
|
return;
|
|
}
|
|
|
|
container.innerHTML = activities.slice(0, 5).map((a) => `
|
|
<a href="${a.link}" class="activity-item">
|
|
<span class="activity-type type-${a.activity_type}">${a.activity_type}</span>
|
|
<span class="activity-title">${a.title}</span>
|
|
</a>
|
|
`).join('');
|
|
} catch (e) {
|
|
container.innerHTML = '<p class="error-small">Failed to load</p>';
|
|
}
|
|
}
|
|
|
|
async function loadMyProposals() {
|
|
const container = document.getElementById('my-proposals');
|
|
if (!container) return;
|
|
|
|
try {
|
|
const res = await fetch(`${apiBase}/api/proposals/my`, {
|
|
headers: { 'Authorization': `Bearer ${token}` },
|
|
});
|
|
const proposals = await res.json();
|
|
|
|
if (proposals.length === 0) {
|
|
container.innerHTML = '<p class="empty-small">You haven\'t created any proposals yet</p>';
|
|
return;
|
|
}
|
|
|
|
container.innerHTML = proposals.slice(0, 5).map((p) => `
|
|
<a href="/proposals/${p.id}" class="list-item">
|
|
<span class="item-title">${p.title}</span>
|
|
<span class="item-status status-${p.status}">${p.status}</span>
|
|
</a>
|
|
`).join('');
|
|
} catch (e) {
|
|
container.innerHTML = '<p class="error-small">Failed to load</p>';
|
|
}
|
|
}
|
|
|
|
async function loadMyCommunities() {
|
|
const container = document.getElementById('my-communities');
|
|
if (!container) return;
|
|
|
|
try {
|
|
const res = await fetch(`${apiBase}/api/users/me/communities`, {
|
|
headers: { 'Authorization': `Bearer ${token}` },
|
|
});
|
|
const communities = await res.json();
|
|
|
|
if (communities.length === 0) {
|
|
container.innerHTML = `
|
|
<p class="empty-small">You haven't joined any communities yet</p>
|
|
<a href="/communities" class="browse-link">Browse Communities</a>
|
|
`;
|
|
return;
|
|
}
|
|
|
|
container.innerHTML = communities.slice(0, 5).map((c) => `
|
|
<a href="/communities/${c.slug}" class="list-item">${c.name}</a>
|
|
`).join('');
|
|
} catch (e) {
|
|
container.innerHTML = '<p class="error-small">Failed to load</p>';
|
|
}
|
|
}
|
|
|
|
loadDashboard();
|
|
</script>
|
|
|
|
<style>
|
|
.dashboard {
|
|
padding: 2rem 0;
|
|
}
|
|
|
|
.welcome {
|
|
margin-bottom: 2rem;
|
|
}
|
|
|
|
.welcome h1 {
|
|
font-size: 2rem;
|
|
margin-bottom: 0.25rem;
|
|
}
|
|
|
|
.user-email {
|
|
color: var(--color-text-muted);
|
|
}
|
|
|
|
.dashboard-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(2, 1fr);
|
|
gap: 1.5rem;
|
|
margin-bottom: 2rem;
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
.dashboard-grid {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
}
|
|
|
|
.card {
|
|
background: var(--color-surface);
|
|
border: 1px solid var(--color-border);
|
|
border-radius: 12px;
|
|
padding: 1.5rem;
|
|
}
|
|
|
|
.card h2 {
|
|
font-size: 1rem;
|
|
margin-bottom: 1rem;
|
|
padding-bottom: 0.75rem;
|
|
border-bottom: 1px solid var(--color-border);
|
|
}
|
|
|
|
.card-content {
|
|
min-height: 100px;
|
|
}
|
|
|
|
.list-item {
|
|
display: block;
|
|
padding: 0.5rem 0;
|
|
color: var(--color-text);
|
|
border-bottom: 1px solid var(--color-border);
|
|
}
|
|
|
|
.list-item:last-child {
|
|
border-bottom: none;
|
|
}
|
|
|
|
.list-item:hover {
|
|
color: var(--color-primary);
|
|
}
|
|
|
|
.quick-actions {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.75rem;
|
|
}
|
|
|
|
.action-btn {
|
|
display: block;
|
|
text-align: center;
|
|
padding: 0.75rem;
|
|
border-radius: 6px;
|
|
font-weight: 600;
|
|
background: var(--color-primary);
|
|
color: var(--color-on-primary);
|
|
}
|
|
|
|
.action-btn:hover {
|
|
background: var(--color-primary-hover);
|
|
color: var(--color-on-primary);
|
|
}
|
|
|
|
.action-btn.secondary {
|
|
background: transparent;
|
|
border: 1px solid var(--color-border);
|
|
color: var(--color-text);
|
|
}
|
|
|
|
.action-btn.secondary:hover {
|
|
border-color: var(--color-primary);
|
|
color: var(--color-primary);
|
|
}
|
|
|
|
.account-section {
|
|
background: var(--color-surface);
|
|
border: 1px solid var(--color-border);
|
|
border-radius: 12px;
|
|
padding: 1.5rem;
|
|
}
|
|
|
|
.account-section h2 {
|
|
font-size: 1rem;
|
|
margin-bottom: 1rem;
|
|
}
|
|
|
|
.logout-btn {
|
|
background: var(--color-error);
|
|
color: var(--color-on-primary);
|
|
border: none;
|
|
padding: 0.5rem 1rem;
|
|
border-radius: 6px;
|
|
cursor: pointer;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.logout-btn:hover {
|
|
background: var(--color-error-hover);
|
|
}
|
|
|
|
.loading {
|
|
text-align: center;
|
|
padding: 3rem;
|
|
color: var(--color-text-muted);
|
|
}
|
|
|
|
.loading-small, .empty-small, .error-small {
|
|
color: var(--color-text-muted);
|
|
font-size: 0.875rem;
|
|
}
|
|
|
|
.browse-link {
|
|
display: block;
|
|
margin-top: 0.5rem;
|
|
font-size: 0.875rem;
|
|
}
|
|
|
|
.activity-item {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.75rem;
|
|
padding: 0.5rem 0;
|
|
border-bottom: 1px solid var(--color-border);
|
|
text-decoration: none;
|
|
color: var(--color-text);
|
|
}
|
|
|
|
.activity-item:last-child {
|
|
border-bottom: none;
|
|
}
|
|
|
|
.activity-item:hover .activity-title {
|
|
color: var(--color-primary);
|
|
}
|
|
|
|
.activity-type {
|
|
font-size: 0.625rem;
|
|
padding: 0.125rem 0.5rem;
|
|
border-radius: 4px;
|
|
text-transform: uppercase;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.type-proposal { background: var(--color-success); color: var(--color-on-primary); }
|
|
.type-community { background: var(--color-secondary); color: var(--color-on-primary); }
|
|
|
|
.activity-title {
|
|
font-size: 0.875rem;
|
|
}
|
|
|
|
.item-title {
|
|
flex: 1;
|
|
}
|
|
|
|
.item-status {
|
|
font-size: 0.625rem;
|
|
padding: 0.125rem 0.5rem;
|
|
border-radius: 4px;
|
|
text-transform: uppercase;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.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); }
|
|
</style>
|