mirror of
https://codeberg.org/likwid/likwid.git
synced 2026-02-09 21:13:09 +00:00
ui: refresh dashboard layout
This commit is contained in:
parent
bdf6fa6c2f
commit
5f52ddb94f
1 changed files with 286 additions and 140 deletions
|
|
@ -4,9 +4,15 @@ import { API_BASE as apiBase } from '../lib/api';
|
|||
---
|
||||
|
||||
<Layout title="Dashboard">
|
||||
<section class="dashboard">
|
||||
<div id="dashboard-content">
|
||||
<p class="loading">Loading...</p>
|
||||
<section class="ui-page">
|
||||
<div class="ui-container">
|
||||
<div id="dashboard-content">
|
||||
<div class="list-skeleton">
|
||||
<div class="skeleton-card"></div>
|
||||
<div class="skeleton-card"></div>
|
||||
<div class="skeleton-card"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</Layout>
|
||||
|
|
@ -21,50 +27,129 @@ import { API_BASE as apiBase } from '../lib/api';
|
|||
|
||||
const user = JSON.parse(userStr || '{}');
|
||||
|
||||
function escapeHtml(value) {
|
||||
return String(value || '').replace(/[&<>"']/g, function(ch) {
|
||||
switch (ch) {
|
||||
case '&': return '&';
|
||||
case '<': return '<';
|
||||
case '>': return '>';
|
||||
case '"': return '"';
|
||||
case "'": return ''';
|
||||
default: return ch;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function normalizeStatus(status) {
|
||||
const s = String(status || '').toLowerCase();
|
||||
if (s === 'draft' || s === 'discussion' || s === 'voting' || s === 'closed') return s;
|
||||
return 'draft';
|
||||
}
|
||||
|
||||
function setText(id, value) {
|
||||
const el = document.getElementById(id);
|
||||
if (el) el.textContent = String(value);
|
||||
}
|
||||
|
||||
function setBadge(id, value) {
|
||||
const el = document.getElementById(id);
|
||||
if (!el) return;
|
||||
const str = String(value);
|
||||
el.textContent = str;
|
||||
el.setAttribute('aria-label', str);
|
||||
}
|
||||
|
||||
async function loadDashboard() {
|
||||
const container = document.getElementById('dashboard-content');
|
||||
if (!container) return;
|
||||
|
||||
const safeName = escapeHtml(user.display_name || user.username || '');
|
||||
const safeEmail = escapeHtml(user.email || '');
|
||||
|
||||
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 class="hero ui-card ui-card-glass">
|
||||
<div class="hero-top">
|
||||
<div>
|
||||
<h1 class="hero-title">Welcome, ${safeName}!</h1>
|
||||
<p class="hero-subtitle">${safeEmail}</p>
|
||||
</div>
|
||||
<div class="hero-actions">
|
||||
<a href="/communities" class="ui-btn ui-btn-secondary">Browse</a>
|
||||
<a href="/communities/new" class="ui-btn ui-btn-primary">Create Community</a>
|
||||
</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 class="hero-kpis">
|
||||
<div class="hero-kpis-label">At a glance</div>
|
||||
<div class="ui-kpis">
|
||||
<div class="ui-kpi">
|
||||
<div class="ui-kpi-value" id="kpi-my-communities">—</div>
|
||||
<div class="ui-kpi-label">My communities</div>
|
||||
</div>
|
||||
<div class="ui-kpi">
|
||||
<div class="ui-kpi-value" id="kpi-my-proposals">—</div>
|
||||
<div class="ui-kpi-label">My proposals</div>
|
||||
</div>
|
||||
<div class="ui-kpi">
|
||||
<div class="ui-kpi-value" id="kpi-recent">—</div>
|
||||
<div class="ui-kpi-label">Recent activity</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="account-section">
|
||||
<h2>Account</h2>
|
||||
<button id="logout-btn" class="logout-btn">Logout</button>
|
||||
<div class="panels">
|
||||
<details class="panel ui-card" open>
|
||||
<summary class="panel-summary">
|
||||
<span class="panel-title">My Communities</span>
|
||||
<span class="panel-meta">
|
||||
<span class="ui-badge" id="badge-my-communities">—</span>
|
||||
</span>
|
||||
</summary>
|
||||
<div class="panel-body">
|
||||
<div id="my-communities" class="panel-content">
|
||||
<p class="loading-small">Loading...</p>
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<details class="panel ui-card" open>
|
||||
<summary class="panel-summary">
|
||||
<span class="panel-title">My Proposals</span>
|
||||
<span class="panel-meta">
|
||||
<span class="ui-badge" id="badge-my-proposals">—</span>
|
||||
</span>
|
||||
</summary>
|
||||
<div class="panel-body">
|
||||
<div id="my-proposals" class="panel-content">
|
||||
<p class="loading-small">Loading...</p>
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<details class="panel ui-card">
|
||||
<summary class="panel-summary">
|
||||
<span class="panel-title">Recent Activity</span>
|
||||
<span class="panel-meta">
|
||||
<span class="ui-badge" id="badge-recent">—</span>
|
||||
</span>
|
||||
</summary>
|
||||
<div class="panel-body">
|
||||
<div id="recent-activity" class="panel-content">
|
||||
<p class="loading-small">Loading...</p>
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<div class="account ui-card">
|
||||
<div class="account-row">
|
||||
<div>
|
||||
<div class="account-title">Account</div>
|
||||
<div class="account-subtitle">Log out of this device</div>
|
||||
</div>
|
||||
<button id="logout-btn" class="ui-btn ui-btn-danger" type="button">Logout</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
|
|
@ -87,17 +172,28 @@ import { API_BASE as apiBase } from '../lib/api';
|
|||
const res = await fetch(`${apiBase}/api/activity/recent`);
|
||||
const activities = await res.json();
|
||||
|
||||
setText('kpi-recent', activities.length);
|
||||
setBadge('badge-recent', activities.length);
|
||||
|
||||
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('');
|
||||
container.innerHTML = activities.slice(0, 7).map((a) => {
|
||||
const rawType = String(a.activity_type || 'activity');
|
||||
const typeClass = rawType.toLowerCase().replace(/[^a-z0-9_-]/g, '');
|
||||
const type = escapeHtml(rawType);
|
||||
const safeTitle = escapeHtml(a.title);
|
||||
let safeLink = String(a.link || '#');
|
||||
if (!safeLink.startsWith('/')) safeLink = '#';
|
||||
return `
|
||||
<a href="${safeLink}" class="activity-item">
|
||||
<span class="activity-type type-${typeClass}">${type}</span>
|
||||
<span class="activity-title">${safeTitle}</span>
|
||||
</a>
|
||||
`;
|
||||
}).join('');
|
||||
} catch (e) {
|
||||
container.innerHTML = '<p class="error-small">Failed to load</p>';
|
||||
}
|
||||
|
|
@ -113,17 +209,24 @@ import { API_BASE as apiBase } from '../lib/api';
|
|||
});
|
||||
const proposals = await res.json();
|
||||
|
||||
setText('kpi-my-proposals', proposals.length);
|
||||
setBadge('badge-my-proposals', proposals.length);
|
||||
|
||||
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('');
|
||||
container.innerHTML = proposals.slice(0, 7).map((p) => {
|
||||
const safeTitle = escapeHtml(p.title);
|
||||
const status = normalizeStatus(p.status);
|
||||
return `
|
||||
<a href="/proposals/${encodeURIComponent(String(p.id))}" class="list-item">
|
||||
<span class="item-title">${safeTitle}</span>
|
||||
<span class="item-status status-${status}">${escapeHtml(status)}</span>
|
||||
</a>
|
||||
`;
|
||||
}).join('');
|
||||
} catch (e) {
|
||||
container.innerHTML = '<p class="error-small">Failed to load</p>';
|
||||
}
|
||||
|
|
@ -139,17 +242,22 @@ import { API_BASE as apiBase } from '../lib/api';
|
|||
});
|
||||
const communities = await res.json();
|
||||
|
||||
setText('kpi-my-communities', communities.length);
|
||||
setBadge('badge-my-communities', communities.length);
|
||||
|
||||
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>
|
||||
<a href="/communities" class="browse-link ui-btn ui-btn-secondary">Browse Communities</a>
|
||||
`;
|
||||
return;
|
||||
}
|
||||
|
||||
container.innerHTML = communities.slice(0, 5).map((c) => `
|
||||
<a href="/communities/${c.slug}" class="list-item">${c.name}</a>
|
||||
`).join('');
|
||||
container.innerHTML = communities.slice(0, 7).map((c) => {
|
||||
const safeName = escapeHtml(c.name);
|
||||
const safeSlug = encodeURIComponent(String(c.slug || ''));
|
||||
return `<a href="/communities/${safeSlug}" class="list-item">${safeName}</a>`;
|
||||
}).join('');
|
||||
} catch (e) {
|
||||
container.innerHTML = '<p class="error-small">Failed to load</p>';
|
||||
}
|
||||
|
|
@ -159,59 +267,113 @@ import { API_BASE as apiBase } from '../lib/api';
|
|||
</script>
|
||||
|
||||
<style>
|
||||
.dashboard {
|
||||
padding: 2rem 0;
|
||||
.hero {
|
||||
padding: 1.25rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.welcome {
|
||||
margin-bottom: 2rem;
|
||||
.hero-top {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.welcome h1 {
|
||||
font-size: 2rem;
|
||||
margin-bottom: 0.25rem;
|
||||
.hero-title {
|
||||
margin: 0;
|
||||
font-size: 2.125rem;
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
|
||||
.user-email {
|
||||
.hero-subtitle {
|
||||
margin: 0.25rem 0 0;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.dashboard-grid {
|
||||
.hero-actions {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.hero-kpis {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.hero-kpis-label {
|
||||
color: var(--color-text-muted);
|
||||
font-size: 0.8125rem;
|
||||
margin-bottom: 0.5rem;
|
||||
letter-spacing: 0.02em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.panels {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
gap: 1.5rem;
|
||||
margin-bottom: 2rem;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.dashboard-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
.panel {
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: var(--color-surface);
|
||||
.panel-summary {
|
||||
list-style: none;
|
||||
cursor: pointer;
|
||||
padding: 1rem 1.1rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.panel-summary::-webkit-details-marker {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.panel-title {
|
||||
font-weight: 700;
|
||||
letter-spacing: -0.01em;
|
||||
}
|
||||
|
||||
.panel-body {
|
||||
border-top: 1px solid var(--color-border);
|
||||
padding: 0.9rem 1.1rem 1.1rem;
|
||||
}
|
||||
|
||||
.panel-content {
|
||||
min-height: 72px;
|
||||
}
|
||||
|
||||
.ui-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 24px;
|
||||
min-width: 24px;
|
||||
padding: 0 10px;
|
||||
border-radius: 999px;
|
||||
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;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
color: var(--color-text);
|
||||
font-size: 0.75rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.list-item {
|
||||
display: block;
|
||||
padding: 0.5rem 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.75rem;
|
||||
padding: 0.6rem 0;
|
||||
color: var(--color-text);
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
text-decoration: none;
|
||||
transition: color 140ms ease;
|
||||
}
|
||||
|
||||
.list-item:last-child {
|
||||
|
|
@ -222,68 +384,27 @@ import { API_BASE as apiBase } from '../lib/api';
|
|||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.quick-actions {
|
||||
.account {
|
||||
padding: 1rem 1.1rem;
|
||||
}
|
||||
|
||||
.account-row {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.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);
|
||||
.account-title {
|
||||
font-weight: 700;
|
||||
letter-spacing: -0.01em;
|
||||
}
|
||||
|
||||
.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;
|
||||
.account-subtitle {
|
||||
color: var(--color-text-muted);
|
||||
font-size: 0.875rem;
|
||||
margin-top: 0.15rem;
|
||||
}
|
||||
|
||||
.loading-small, .empty-small, .error-small {
|
||||
|
|
@ -305,6 +426,7 @@ import { API_BASE as apiBase } from '../lib/api';
|
|||
border-bottom: 1px solid var(--color-border);
|
||||
text-decoration: none;
|
||||
color: var(--color-text);
|
||||
transition: color 140ms ease;
|
||||
}
|
||||
|
||||
.activity-item:last-child {
|
||||
|
|
@ -346,4 +468,28 @@ import { API_BASE as apiBase } from '../lib/api';
|
|||
.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); }
|
||||
|
||||
.list-skeleton {
|
||||
display: grid;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.skeleton-card {
|
||||
height: 120px;
|
||||
border-radius: 14px;
|
||||
border: 1px solid var(--color-border);
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
rgba(255, 255, 255, 0.03) 0%,
|
||||
rgba(255, 255, 255, 0.06) 50%,
|
||||
rgba(255, 255, 255, 0.03) 100%
|
||||
);
|
||||
background-size: 200% 100%;
|
||||
animation: shimmer 1.2s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes shimmer {
|
||||
0% { background-position: 0% 0%; }
|
||||
100% { background-position: 200% 0%; }
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
Loading…
Reference in a new issue