|
| 1 | + |
| 2 | +import {html} from "lit" |
| 3 | +import {view} from "@e280/sly" |
| 4 | + |
| 5 | +import {Router} from "../router.js" |
| 6 | +import styleCss from "./style.css.js" |
| 7 | +import {Context} from "../context.js" |
| 8 | +import themeCss from "../theme.css.js" |
| 9 | +import menu2Svg from "../icons/tabler/menu-2.svg.js" |
| 10 | +import {DashboardView} from "../pages/dashboard/view.js" |
| 11 | + |
| 12 | +export class OliveApp extends (view.component(use => { |
| 13 | + use.css(themeCss, styleCss) |
| 14 | + |
| 15 | + const context = use.once(() => new Context()) |
| 16 | + const router = use.once(() => new Router( |
| 17 | + [/^$/, () => DashboardView.props(context).children(html`<slot></slot>`).render()], |
| 18 | + [/^#\/a\/$/, () => html`account`], |
| 19 | + [/^#\/o\/$/, () => html`orglist`], |
| 20 | + [/^#\/o\/(\w+)$/, orgId => html`org ${orgId}`], |
| 21 | + [/^#\/c\/$/, () => html`chatlist`], |
| 22 | + [/^#\/c\/(\w+)$/, chatId => html`chat ${chatId}`], |
| 23 | + [/.*/, () => html`404 not found`], |
| 24 | + )) |
| 25 | + |
| 26 | + const {hash} = router |
| 27 | + const $navOpen = use.signal(false) |
| 28 | + |
| 29 | + const toggleNav = () => $navOpen(!$navOpen()) |
| 30 | + const closeNav = () => $navOpen(false) |
| 31 | + |
| 32 | + const renderLink = (label: string, url: string, isActive: boolean) => html` |
| 33 | + <a |
| 34 | + href="${url}" |
| 35 | + ?data-active="${isActive}" |
| 36 | + @click="${closeNav}"> |
| 37 | + ${label} |
| 38 | + </a> |
| 39 | + ` |
| 40 | + |
| 41 | + return html` |
| 42 | + <nav ?data-open="${$navOpen()}"> |
| 43 | + <button theme=icon @click="${toggleNav}">${menu2Svg}</button> |
| 44 | + <div class=navplate ?inert="${!$navOpen()}"> |
| 45 | + <header> |
| 46 | + <img alt="" src="/assets/olive.png"/> |
| 47 | + <div> |
| 48 | + <h1>Olive Support <small>v${context.version}</small></h1> |
| 49 | + <p>Simple secure customer support.</p> |
| 50 | + </div> |
| 51 | + </header> |
| 52 | + <div class=links> |
| 53 | + ${renderLink("Dashboard", "#/", hash === "")} |
| 54 | + ${renderLink("Account", "#/a/", hash.startsWith("#/a/"))} |
| 55 | + ${renderLink("Orgs", "#/o/", hash.startsWith("#/a/"))} |
| 56 | + ${renderLink("Chats", "#/c/", hash.startsWith("#/c/"))} |
| 57 | + </div> |
| 58 | + </div> |
| 59 | + </nav> |
| 60 | +
|
| 61 | + <main>${router.$content()}</main> |
| 62 | +
|
| 63 | + <div class=blanket |
| 64 | + ?inert="${!$navOpen()}" |
| 65 | + ?data-active="${$navOpen()}" |
| 66 | + @click="${closeNav}"> |
| 67 | + </div> |
| 68 | + ` |
| 69 | +})) {} |
| 70 | + |
0 commit comments