import '@vaadin/vaadin-app-layout'; import { AppLayoutElement } from '@vaadin/vaadin-app-layout'; import '@vaadin/vaadin-app-layout/vaadin-drawer-toggle'; import '@vaadin/vaadin-avatar/vaadin-avatar'; import '@vaadin/vaadin-context-menu'; import '@vaadin/vaadin-tabs'; import '@vaadin/vaadin-tabs/vaadin-tab'; import '@vaadin/vaadin-template-renderer'; import { html, render } from 'lit'; import { customElement } from 'lit/decorators.js'; import { logout } from '../auth'; import { router } from '../index'; import { hasAccess, views } from '../routes'; import { appStore } from '../stores/app-store'; import { Layout } from './view'; interface RouteInfo { path: string; title: string; icon: string; } @customElement('main-layout') export class MainLayout extends Layout { render() { return html`

${appStore.currentViewTitle}

${appStore.user ? html` ` : html`Sign in`}

${this.getMenuRoutes().map( (viewRoute) => html` ${viewRoute.title} ` )}
`; } connectedCallback() { super.connectedCallback(); this.classList.add('block', 'h-full'); this.reaction( () => appStore.location, () => { AppLayoutElement.dispatchCloseOverlayDrawerEvent(); } ); } private renderLogoutOptions(root: HTMLElement) { render(html` logout()}>Logout`, root); } private getMenuRoutes(): RouteInfo[] { return views.filter((route) => route.title).filter((route) => hasAccess(route)) as RouteInfo[]; } private getSelectedViewRoute(): number { const path = appStore.location; return this.getMenuRoutes().findIndex((viewRoute) => viewRoute.path == path); } }