111 lines
4.3 KiB
React
111 lines
4.3 KiB
React
import { useContext, useState } from "react";
|
|
import { NavLink, Outlet, useNavigate } from "react-router-dom";
|
|
import { SessionContext } from "../session.js";
|
|
|
|
const WORK = [
|
|
{ to: "/", end: true, label: "Übersicht", icon: "home" },
|
|
{ to: "/matters", label: "Vorgänge", icon: "layers" },
|
|
{ to: "/cases", label: "Akten", icon: "folder" },
|
|
{ to: "/work", label: "Aufgaben", icon: "check" },
|
|
];
|
|
|
|
const ADMIN = [
|
|
{ to: "/settings", label: "Verwaltung", icon: "rooms" },
|
|
];
|
|
|
|
export function Shell() {
|
|
const { session, logout } = useContext(SessionContext);
|
|
const navigate = useNavigate();
|
|
const [query, setQuery] = useState("");
|
|
const items = [...WORK, ...ADMIN];
|
|
|
|
function onSearch(event) {
|
|
event.preventDefault();
|
|
const term = query.trim();
|
|
if (term.length < 2) return;
|
|
navigate(`/search?q=${encodeURIComponent(term)}`);
|
|
}
|
|
|
|
return (
|
|
<div className="app-shell">
|
|
<aside className="desktop-sidebar" aria-label="Hauptnavigation">
|
|
<div className="desktop-sidebar__brand">
|
|
<div className="desktop-sidebar__logo" aria-hidden="true" />
|
|
<div className="desktop-sidebar__title">Tsumugu</div>
|
|
</div>
|
|
<nav className="desktop-sidebar__nav">
|
|
{items.map((item) => (
|
|
<NavLink key={item.to} to={item.to} end={item.end} className={({ isActive }) => `desktop-sidebar__link${isActive ? " active" : ""}`}>
|
|
<NavIcon name={item.icon} />
|
|
<span>{item.label}</span>
|
|
</NavLink>
|
|
))}
|
|
</nav>
|
|
<div className="desktop-sidebar__footer">
|
|
<div className="desktop-sidebar__user-text">
|
|
<span className="desktop-sidebar__user-name">{session.account.display_name}</span>
|
|
</div>
|
|
<button type="button" className="desktop-sidebar__logout" onClick={logout} title="Abmelden">
|
|
<NavIcon name="logout" />
|
|
</button>
|
|
</div>
|
|
</aside>
|
|
|
|
<div className="app-shell__column">
|
|
<header className="app-header">
|
|
<div className="app-header__bar mobile-only">
|
|
<NavLink to="/" className="app-logo">Tsumugu</NavLink>
|
|
<button type="button" className="quiet" onClick={logout}>Abmelden</button>
|
|
</div>
|
|
<form className="search" onSubmit={onSearch}>
|
|
<input
|
|
value={query}
|
|
onChange={(event) => setQuery(event.target.value)}
|
|
placeholder="Suchen"
|
|
aria-label="Suchen"
|
|
/>
|
|
<button type="submit">Suchen</button>
|
|
</form>
|
|
</header>
|
|
<div className="app-main">
|
|
<Outlet />
|
|
</div>
|
|
<nav className="bottom-nav" aria-label="Hauptnavigation">
|
|
{[...WORK, ADMIN[0]].map((item) => (
|
|
<NavLink key={item.to} to={item.to} end={item.end} className={({ isActive }) => `nav-item${isActive ? " active" : ""}`}>
|
|
<NavIcon name={item.icon} />
|
|
<span>{item.label}</span>
|
|
</NavLink>
|
|
))}
|
|
</nav>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function NavIcon({ name }) {
|
|
const common = { width: 20, height: 20, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true };
|
|
if (name === "home") {
|
|
return <svg {...common}><path d="M4 10.5 12 4l8 6.5V20a1 1 0 0 1-1 1h-5v-6H10v6H5a1 1 0 0 1-1-1z" /></svg>;
|
|
}
|
|
if (name === "folder") {
|
|
return <svg {...common}><path d="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z" /></svg>;
|
|
}
|
|
if (name === "layers") {
|
|
return <svg {...common}><path d="m12 3 9 5-9 5-9-5z" /><path d="m3 12 9 5 9-5" /><path d="m3 17 9 5 9-5" /></svg>;
|
|
}
|
|
if (name === "sources") {
|
|
return <svg {...common}><path d="M4 7h16" /><path d="M4 12h10" /><path d="M4 17h16" /><path d="M18 10v4" /></svg>;
|
|
}
|
|
if (name === "users") {
|
|
return <svg {...common}><circle cx="12" cy="8" r="3" /><path d="M5 19c1.2-2.4 3.4-3.5 7-3.5s5.8 1.1 7 3.5" /></svg>;
|
|
}
|
|
if (name === "check") {
|
|
return <svg {...common}><path d="M8 12h8" /><path d="M8 7h8" /><path d="M8 17h5" /><path d="M4 7.5 5.2 9 8 6" /></svg>;
|
|
}
|
|
if (name === "logout") {
|
|
return <svg {...common}><path d="M9 6H5a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h4" /><path d="M14 16l4-4-4-4" /><path d="M18 12H9" /></svg>;
|
|
}
|
|
return <svg {...common}><path d="M4 8h16M4 12h16M4 16h10" /></svg>;
|
|
}
|