auth-yes/ui/components/AuthenticatedLayout.tsx
google-labs-jules[bot] c8cf9c7df7 refactor(ui): extract layout and sessions subcomponents
Extract Navbar, MobileNav, and UserMenu from AuthenticatedLayout.tsx.
Extract SessionTable, SessionDeck, and SessionsScript from SessionsPage.tsx.
Preserves existing pure Hono SSR JSX and logic.

Co-authored-by: mrteye <1945243+mrteye@users.noreply.github.com>
2026-08-26 06:38:22 +00:00

287 lines
9.0 KiB
TypeScript

import { COMMON_CSS } from "./CommonStyles.ts";
import { Navbar } from "./layout/Navbar.tsx";
import { MobileNav } from "./layout/MobileNav.tsx";
import { UserMenu } from "./layout/UserMenu.tsx";
export const AuthenticatedLayout = ({
children,
title,
currentPath,
isAdmin = false,
}: {
children: any;
title: string;
currentPath: string;
isAdmin?: boolean;
}) => {
const navItems = [
{
label: "Launchpad",
href: "/dashboard",
icon:
`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 0 0-2.91-.09z"></path><path d="m12 15-3-3a22 22 0 0 1 2-3.95A12.88 12.88 0 0 1 22 2c0 2.72-.78 7.5-6 11a22.35 22.35 0 0 1-4 2z"></path><path d="M9 12H4s.55-3.03 2-4c1.62-1.08 5 0 5 0"></path><path d="M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5"></path></svg>`,
},
{
label: "Sessions",
href: "/dashboard/sessions",
icon:
`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="14" x="2" y="3" rx="2"></rect><line x1="8" x2="16" y1="21" y2="21"></line><line x1="12" x2="12" y1="17" y2="21"></line></svg>`,
},
{
label: "Passkeys",
href: "/dashboard/passkeys",
icon:
`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="7.5" cy="15.5" r="5.5"></circle><path d="m21 2-9.6 9.6"></path><path d="m15.5 7.5 3 3L22 7l-3-3"></path></svg>`,
},
...(isAdmin
? [{
label: "Admin",
href: "/admin/users",
icon:
`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"></path></svg>`,
}]
: []),
];
return (
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
<meta name="theme-color" content="#0066cc" />
<title>{title} - Auth-Yes</title>
<style>
{`
${COMMON_CSS}
/* Layout Shell */
.app-shell {
display: flex;
flex-direction: column;
min-height: 100vh;
}
/* Top App Bar */
.top-bar {
position: sticky;
top: 0;
z-index: 40;
background-color: var(--surface-card);
border-bottom: 1px solid var(--border-subtle);
padding: 0.75rem 1.25rem;
display: flex;
justify-content: space-between;
align-items: center;
box-shadow: var(--shadow-sm);
}
.brand {
display: inline-flex;
align-items: center;
gap: 0.65rem;
text-decoration: none;
color: var(--text-primary);
font-weight: 700;
font-size: 1.15rem;
height: 36px;
}
.brand-badge {
display: inline-flex;
align-items: center;
justify-content: center;
width: 32px;
height: 32px;
background: var(--primary);
color: #ffffff;
border-radius: var(--radius-sm);
font-weight: 800;
}
/* Desktop Navigation */
.desktop-nav {
display: none;
align-items: center;
gap: 0.5rem;
margin-left: 2rem;
}
.desktop-nav a {
display: inline-flex;
align-items: center;
gap: 0.4rem;
padding: 0.4rem 0.85rem;
border-radius: var(--radius-md);
text-decoration: none;
color: var(--text-secondary);
font-weight: 500;
font-size: 0.9rem;
height: 36px;
box-sizing: border-box;
transition: all 0.15s ease;
}
.desktop-nav a:hover {
background-color: var(--surface-muted);
color: var(--text-primary);
}
.desktop-nav a.active {
background-color: var(--primary-light);
color: var(--primary);
font-weight: 600;
}
.header-actions {
display: flex;
align-items: center;
gap: 0.75rem;
}
.logout-link {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.35rem;
padding: 0.4rem 0.85rem;
border-radius: var(--radius-md);
text-decoration: none;
color: var(--danger);
font-weight: 600;
font-size: 0.85rem;
border: 1px solid var(--danger-border);
background: var(--danger-bg);
height: 36px;
box-sizing: border-box;
transition: all 0.15s ease;
}
.logout-link:hover {
background: var(--danger);
color: #ffffff;
}
/* Main Content Container */
.main-content {
flex: 1;
width: 100%;
max-width: 1100px;
margin: 0 auto;
padding: 1.5rem 1rem calc(5.5rem + env(safe-area-inset-bottom)) 1rem;
box-sizing: border-box;
}
/* Mobile Bottom Navigation Bar */
.mobile-bottom-nav {
position: fixed;
bottom: 0;
left: 0;
right: 0;
z-index: 50;
background-color: var(--surface-card);
border-top: 1px solid var(--border-subtle);
display: flex;
justify-content: space-around;
padding: 0.5rem 0 calc(0.5rem + env(safe-area-inset-bottom)) 0;
box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.04);
}
.mobile-bottom-nav a {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 0.2rem;
color: var(--text-muted);
text-decoration: none;
font-size: 0.75rem;
font-weight: 600;
padding: 0.35rem 0.75rem;
border-radius: var(--radius-md);
transition: all 0.15s ease;
min-width: 64px;
}
.mobile-bottom-nav a.active {
color: var(--primary);
}
.mobile-bottom-nav a.active svg {
stroke: var(--primary);
}
/* Desktop Responsive Rules */
@media (min-width: 768px) {
.desktop-nav {
display: flex;
}
.mobile-bottom-nav {
display: none;
}
.main-content {
padding: 2.5rem 2rem;
}
.top-bar {
padding: 0.75rem 2rem;
}
}
/* Tables Responsive Scroller */
.table-container {
width: 100%;
overflow-x: auto;
-webkit-overflow-scrolling: touch;
border-radius: var(--radius-md);
border: 1px solid var(--border-subtle);
}
table {
width: 100%;
border-collapse: collapse;
text-align: left;
}
th, td {
padding: 0.85rem 1rem;
border-bottom: 1px solid var(--border-subtle);
font-size: 0.9rem;
}
th {
background-color: var(--surface-muted);
color: var(--text-secondary);
font-weight: 600;
}
tr:last-child td {
border-bottom: none;
}
`}
</style>
<script src="https://unpkg.com/@simplewebauthn/browser/dist/bundle/index.umd.min.js">
</script>
<script src="/public/auth-client.js?v=5"></script>
</head>
<body>
<div class="app-shell">
{/* Top Header */}
<Navbar navItems={navItems} currentPath={currentPath}>
<UserMenu isAdmin={isAdmin} />
</Navbar>
{/* Main Body */}
<main class="main-content">
{children}
</main>
{/* Mobile Bottom Navigation Bar */}
<MobileNav navItems={navItems} currentPath={currentPath} />
</div>
</body>
</html>
);
};