likwid/frontend/src/layouts/Layout.astro

347 lines
10 KiB
Text
Raw Normal View History

---
interface Props {
title: string;
}
import { DEFAULT_THEME, themes as themeRegistry } from '../lib/themes';
import { API_BASE as apiBase } from '../lib/api';
import VotingIcons from '../components/icons/VotingIcons.astro';
2026-01-29 15:31:32 +00:00
import DesignSystemStyles from '../components/ui/DesignSystemStyles.astro';
2026-01-29 10:38:43 +00:00
function isEnabled(v: string | undefined): boolean {
if (!v) return false;
const n = v.trim().toLowerCase();
return n === '1' || n === 'true' || n === 'yes' || n === 'on';
}
const { title } = Astro.props;
2026-01-29 10:38:43 +00:00
const publicDemoSite = isEnabled((globalThis as any).process?.env?.PUBLIC_DEMO_SITE);
const themes = Object.fromEntries(
Object.entries(themeRegistry).map(([id, t]) => [id, { isDark: t.isDark, colors: t.colors }]),
);
const defaultTheme = DEFAULT_THEME;
---
<!doctype html>
<html lang="en" data-theme="neutral" data-theme-mode="dark">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Likwid - modular governance and decision-making for organizations" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<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=Inter:wght@400;500;600;700&display=swap" rel="stylesheet" />
<title>{title} | Likwid</title>
<script is:inline define:vars={{ themes, defaultTheme }}>
(function() {
const saved = localStorage.getItem('likwid-theme') || defaultTheme;
const theme = themes[saved] || themes[defaultTheme];
const root = document.documentElement;
const c = theme.colors;
root.style.setProperty('--color-bg', c.bg);
root.style.setProperty('--color-bg-alt', c.bgAlt);
root.style.setProperty('--color-surface', c.surface);
root.style.setProperty('--color-surface-hover', c.surfaceHover);
root.style.setProperty('--color-border', c.border);
root.style.setProperty('--color-border-hover', c.borderHover);
root.style.setProperty('--color-text', c.text);
root.style.setProperty('--color-text-muted', c.textMuted);
root.style.setProperty('--color-text-inverse', c.textInverse);
root.style.setProperty('--color-primary', c.primary);
root.style.setProperty('--color-primary-hover', c.primaryHover);
root.style.setProperty('--color-primary-muted', c.primaryMuted);
root.style.setProperty('--color-secondary', c.secondary);
root.style.setProperty('--color-secondary-hover', c.secondaryHover);
root.style.setProperty('--color-info', c.info);
root.style.setProperty('--color-info-hover', c.infoHover);
root.style.setProperty('--color-info-muted', c.infoMuted);
root.style.setProperty('--color-neutral', c.neutral);
root.style.setProperty('--color-neutral-hover', c.neutralHover);
root.style.setProperty('--color-neutral-muted', c.neutralMuted);
root.style.setProperty('--color-success', c.success);
root.style.setProperty('--color-success-muted', c.successMuted);
root.style.setProperty('--color-success-hover', c.successHover);
root.style.setProperty('--color-warning', c.warning);
root.style.setProperty('--color-warning-muted', c.warningMuted);
root.style.setProperty('--color-error', c.error);
root.style.setProperty('--color-error-muted', c.errorMuted);
root.style.setProperty('--color-error-hover', c.errorHover);
root.style.setProperty('--color-link', c.link);
root.style.setProperty('--color-link-visited', c.linkVisited);
root.style.setProperty('--color-overlay', c.overlay);
root.style.setProperty('--color-field-bg', c.fieldBg);
root.style.setProperty('--color-on-primary', c.onPrimary);
root.setAttribute('data-theme', saved);
root.setAttribute('data-theme-mode', theme.isDark ? 'dark' : 'light');
})();
</script>
</head>
<body>
<VotingIcons />
<div class="app">
<header class="header">
<nav class="nav">
<a href="/" class="logo">Likwid</a>
<div class="nav-links">
<a href="/communities">Organizations</a>
<a href="/proposals">Proposals</a>
<a href="/about">About</a>
</div>
<div class="nav-auth" id="nav-auth">
<a href="/login">Login</a>
{!publicDemoSite ? <a href="/register" class="ui-btn ui-btn-primary">Register</a> : null}
</div>
</nav>
</header>
<main class="main">
<slot />
</main>
<footer class="footer">
<p>&copy; 2026 Likwid - Modular governance platform</p>
</footer>
</div>
<script define:vars={{ apiBase }}>
// Dynamic auth state in navigation
const token = localStorage.getItem('token');
const user = localStorage.getItem('user');
const navAuth = document.getElementById('nav-auth');
if (token && user && navAuth) {
const userData = JSON.parse(user);
navAuth.innerHTML = `
<a href="/dashboard">Dashboard</a>
<a href="/notifications" class="nav-notifications" id="nav-notifications">
<span class="notif-icon">🔔</span>
<span class="notif-badge" id="notif-badge" style="display:none;">0</span>
</a>
<a href="/settings">Settings</a>
<a href="/admin/settings" id="admin-link" style="display:none;">Admin</a>
<span class="user-name">${userData.display_name || userData.username}</span>
`;
loadNotificationCount();
checkAdminStatus();
}
async function checkAdminStatus() {
try {
const res = await fetch(`${apiBase}/api/settings/instance`, {
headers: { 'Authorization': `Bearer ${token}` }
});
if (res.ok) {
const adminLink = document.getElementById('admin-link');
if (adminLink) adminLink.style.display = 'inline';
}
} catch (e) {}
}
setActiveNav();
async function loadNotificationCount() {
try {
const res = await fetch(`${apiBase}/api/notifications/unread-count`, {
headers: { 'Authorization': `Bearer ${token}` },
});
if (res.ok) {
const data = await res.json();
const badge = document.getElementById('notif-badge');
if (badge && data.count > 0) {
badge.textContent = data.count > 9 ? '9+' : data.count;
badge.style.display = 'inline-block';
badge.classList.add('is-visible');
}
}
} catch (e) {}
}
function setActiveNav() {
var links = document.querySelectorAll('.nav-links a, #nav-auth a');
var path = window.location.pathname.replace(/\/$/, '') || '/';
for (var i = 0; i < links.length; i++) {
var a = links[i];
var hrefPath = a.pathname.replace(/\/$/, '') || '/';
if (hrefPath === '/' || hrefPath === '') {
continue;
}
var isActive = path === hrefPath || path.indexOf(hrefPath + '/') === 0;
if (isActive) {
a.setAttribute('aria-current', 'page');
}
}
}
</script>
</body>
</html>
2026-01-29 15:31:32 +00:00
<DesignSystemStyles />
<style>
.app {
min-height: 100vh;
display: flex;
flex-direction: column;
}
.header {
background: rgba(24, 24, 27, 0.8);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
border-bottom: 1px solid var(--color-border);
padding: 1rem 2rem;
position: sticky;
top: 0;
z-index: 100;
}
2026-02-02 17:17:48 +00:00
@media (max-width: 640px) {
.header {
padding: 0.875rem 1rem;
}
}
.nav {
max-width: 1200px;
margin: 0 auto;
display: flex;
justify-content: space-between;
align-items: center;
}
2026-02-02 17:17:48 +00:00
@media (max-width: 640px) {
.nav {
flex-wrap: wrap;
justify-content: center;
gap: 0.75rem;
}
}
.logo {
font-size: 1.375rem;
font-weight: 700;
color: var(--color-text);
letter-spacing: -0.02em;
}
.logo:hover {
color: var(--color-primary);
}
.nav-links {
display: flex;
gap: 2rem;
}
2026-02-02 17:17:48 +00:00
@media (max-width: 640px) {
.nav-links {
width: 100%;
justify-content: center;
gap: 0.5rem;
flex-wrap: wrap;
}
}
.nav-links a {
color: var(--color-text-muted);
padding: 0.5rem 0.875rem;
border-radius: var(--radius-sm);
font-size: 0.9375rem;
font-weight: 500;
transition: background-color var(--motion-fast) var(--easing-standard), color var(--motion-fast) var(--easing-standard);
}
.nav-links a:hover {
color: var(--color-text);
background: rgba(255, 255, 255, 0.06);
}
.nav-links a[aria-current="page"],
.nav-auth a[aria-current="page"] {
color: var(--color-text);
background: var(--color-field-bg);
}
.nav-auth {
display: flex;
gap: 1rem;
align-items: center;
}
2026-02-02 17:17:48 +00:00
@media (max-width: 640px) {
.nav-auth {
width: 100%;
justify-content: center;
flex-wrap: wrap;
gap: 0.5rem;
}
}
.nav-auth a {
color: var(--color-text-muted);
}
.nav-auth a:hover {
color: var(--color-text);
}
.user-name {
color: var(--color-text);
font-weight: 500;
}
.main {
flex: 1;
max-width: 1200px;
margin: 0 auto;
padding: clamp(1.5rem, 2.2vw, 2.25rem);
width: 100%;
}
.footer {
background: var(--color-bg-alt);
border-top: 1px solid var(--color-border);
padding: 1.5rem 2rem;
text-align: center;
color: var(--color-text-muted);
font-size: 0.8125rem;
}
.nav-notifications {
position: relative;
display: flex;
align-items: center;
}
.notif-icon {
font-size: 1.25rem;
}
.notif-badge {
position: absolute;
top: -6px;
right: -8px;
background: var(--color-error);
color: var(--color-on-primary);
font-size: 0.625rem;
font-weight: 700;
padding: 0.125rem 0.375rem;
border-radius: 999px;
min-width: 16px;
text-align: center;
opacity: 0;
transform: scale(0.9);
transition: opacity var(--motion-fast) var(--easing-standard), transform var(--motion-fast) var(--easing-standard);
}
.notif-badge.is-visible {
opacity: 1;
transform: scale(1);
}
</style>