<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}Task Manager{% endblock %} - acton-service HTMX Example</title>
{% if ctx.csrf_token.is_some() %}
{{ ctx.csrf_meta()|safe }}
{% endif %}
<script src="https://unpkg.com/htmx.org@2.0.4"></script>
<script src="https://unpkg.com/htmx-ext-sse@2.2.2/sse.js"></script>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: system-ui, -apple-system, sans-serif;
line-height: 1.6;
background: #f5f5f5;
color: #333;
}
.container { max-width: 800px; margin: 0 auto; padding: 1rem; }
nav {
background: #2563eb;
padding: 1rem;
margin-bottom: 1rem;
}
nav .container {
display: flex;
justify-content: space-between;
align-items: center;
}
nav a { color: white; text-decoration: none; margin-right: 1rem; }
nav a:hover { text-decoration: underline; }
nav .brand { font-weight: bold; font-size: 1.2rem; }
nav .user-menu { display: flex; align-items: center; gap: 1rem; }
.flash-container { margin-bottom: 1rem; }
.flash {
padding: 1rem 1.25rem;
border-radius: 6px;
margin-bottom: 0.5rem;
display: flex;
justify-content: space-between;
align-items: center;
font-weight: 500;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.flash-success { background: #22c55e; color: white; }
.flash-error { background: #ef4444; color: white; }
.flash-warning { background: #f59e0b; color: white; }
.flash-info { background: #3b82f6; color: white; }
.flash button { background: none; border: none; cursor: pointer; font-size: 1.2rem; color: inherit; opacity: 0.8; }
.flash button:hover { opacity: 1; }
.card {
background: white;
border-radius: 8px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
padding: 1.5rem;
margin-bottom: 1rem;
}
.card h2 { margin-bottom: 1rem; color: #1f2937; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.25rem; font-weight: 500; }
.form-group input, .form-group textarea {
width: 100%;
padding: 0.5rem;
border: 1px solid #d1d5db;
border-radius: 4px;
font-size: 1rem;
}
.form-group input:focus, .form-group textarea:focus {
outline: none;
border-color: #2563eb;
box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.btn {
padding: 0.5rem 1rem;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 0.875rem;
font-weight: 500;
transition: background 0.2s;
}
.btn-primary { background: #2563eb; color: white; }
.btn-primary:hover { background: #1d4ed8; }
.btn-secondary { background: #6b7280; color: white; }
.btn-secondary:hover { background: #4b5563; }
.btn-danger { background: #dc2626; color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-success { background: #16a34a; color: white; }
.btn-success:hover { background: #15803d; }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.75rem; }
.task-list { list-style: none; }
.task-item {
display: flex;
align-items: center;
padding: 0.75rem;
border-bottom: 1px solid #e5e7eb;
gap: 0.75rem;
}
.task-item:last-child { border-bottom: none; }
.task-item.completed .task-title {
text-decoration: line-through;
color: #9ca3af;
}
.task-title { flex: 1; }
.task-actions { display: flex; gap: 0.5rem; }
.stats {
display: flex;
gap: 1rem;
margin-bottom: 1rem;
flex-wrap: wrap;
}
.stat {
background: white;
padding: 1rem;
border-radius: 8px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
min-width: 120px;
}
.stat-value { font-size: 1.5rem; font-weight: bold; color: #2563eb; }
.stat-label { font-size: 0.875rem; color: #6b7280; }
.htmx-request .htmx-indicator { display: inline-block; }
.htmx-indicator { display: none; }
.sse-status {
font-size: 0.75rem;
padding: 0.25rem 0.5rem;
border-radius: 9999px;
}
.sse-connected { background: #dcfce7; color: #166534; }
.sse-disconnected { background: #fee2e2; color: #991b1b; }
</style>
</head>
<body>
<nav>
<div class="container">
<div>
<a href="/" class="brand">Task Manager</a>
<a href="/">Tasks</a>
</div>
<div class="user-menu" id="user-menu">
{% if ctx.is_authenticated %}
<span>{{ ctx.user_id.as_deref().unwrap_or("User") }}</span>
<form hx-post="/logout" hx-target="body" style="display: inline;">
<button type="submit" class="btn btn-secondary btn-sm">Logout</button>
</form>
{% else %}
<a href="/login">Login</a>
{% endif %}
</div>
</div>
</nav>
<main class="container">
<div class="flash-container" id="flash-container">
{% for flash in ctx.flash_messages %}
<div class="flash {{ flash.kind.css_class() }}">
<span>{{ flash.message }}</span>
<button onclick="this.parentElement.remove()">×</button>
</div>
{% endfor %}
</div>
{% block content %}{% endblock %}
</main>
<script>
document.body.addEventListener('htmx:configRequest', function(evt) {
const csrfMeta = document.querySelector('meta[name="csrf-token"]');
if (csrfMeta) {
evt.detail.headers['X-CSRF-Token'] = csrfMeta.content;
}
});
document.querySelectorAll('.flash').forEach(flash => {
setTimeout(() => flash.remove(), 5000);
});
</script>
</body>
</html>