11
22import { html } from "lit"
3- import { view } from "@e280/sly"
3+ import { spa , view } from "@e280/sly"
44
55import styleCss from "./style.css.js"
66import { Context } from "../context.js"
@@ -13,34 +13,23 @@ export class OliveApp extends (view.component(use => {
1313 use . css ( themeCss , styleCss )
1414
1515 const context = use . once ( ( ) => new Context ( ) )
16- // const router = use.once(() => new Hashrouter({
17- // dashboard: new Route(
18- // [],
19- // async() => DashboardView.props(context).children(html`<slot></slot>`).render(),
20- // ),
21- // account: new Route(
22- // ["account"],
23- // async() => html`account`,
24- // ),
25- // orgs: new Route(
26- // ["orgs"],
27- // async() => html`orgs`,
28- // ),
29- // org: new Route(
30- // ["orgs", {}],
31- // async(orgId: string) => html`org ${orgId}`,
32- // ),
33- // chats: new Route(
34- // ["chats"],
35- // async() => html`chats`,
36- // ),
37- // chat: new Route(
38- // ["chat", {}],
39- // async(chatId: string) => html`chat ${chatId}`,
40- // ),
41- // }))
4216
43- // const {hash} = router
17+ const router = use . once ( ( ) => new spa . Router ( {
18+ routes : {
19+ dashboard : spa . route ( "#/" , async ( ) =>
20+ DashboardView
21+ . props ( context )
22+ . children ( html `< slot > </ slot > ` )
23+ . render ( )
24+ ) ,
25+ account : spa . route ( "#/account" , async ( ) => html `account` ) ,
26+ orgs : spa . route ( "#/orgs" , async ( ) => html `orgs` ) ,
27+ org : spa . route ( "#/org/{orgId}" , async ( { orgId} ) => html `org ${ orgId } ` ) ,
28+ chats : spa . route ( "#/chats" , async ( ) => html `chats` ) ,
29+ chat : spa . route ( "#/chat/{chatId}" , async ( { chatId} ) => html `chat ${ chatId } ` ) ,
30+ } ,
31+ } ) )
32+
4433 const $navOpen = use . signal ( false )
4534 const taglines = use . once ( ( ) => new Taglines ( ) )
4635
@@ -54,21 +43,19 @@ export class OliveApp extends (view.component(use => {
5443
5544 const closeNav = ( ) => toggleNav ( false )
5645
57- const renderLink = ( label : string , url : string , isActive : boolean ) => html `
46+ const renderLink = < N extends spa . Navigable > (
47+ label : string ,
48+ nav : N ,
49+ ...params : Parameters < N [ "hash" ] >
50+ ) => html `
5851 < a
59- href ="${ url } "
60- ?data-active ="${ isActive } "
52+ href ="${ nav . hash ( ... params ) } "
53+ ?data-active ="${ nav . active } "
6154 @click ="${ closeNav } ">
6255 ${ label }
6356 </ a >
6457 `
6558
66- // <div class=links>
67- // ${renderLink("🫒 Dashboard", "#/", hash === "")}
68- // ${renderLink("👤 Account", "#/account", hash.startsWith("#/account"))}
69- // ${renderLink("🏛 Orgs", "#/orgs", hash.startsWith("#/orgs"))}
70- // ${renderLink("💬 Chats", "#/chats", hash.startsWith("#/chats"))}
71- // </div>
7259 return html `
7360 < nav ?data-open ="${ $navOpen ( ) } ">
7461 < button theme =icon @click ="${ ( ) => toggleNav ( ) } "> ${ menu2Svg } </ button >
@@ -83,10 +70,16 @@ export class OliveApp extends (view.component(use => {
8370 < p > ${ taglines . $tagline ( ) } </ p >
8471 </ div >
8572 </ header >
73+ < div class =links >
74+ ${ renderLink ( "🫒 Dashboard" , router . nav . dashboard ) }
75+ ${ renderLink ( "👤 Account" , router . nav . account ) }
76+ ${ renderLink ( "🏛 Orgs" , router . nav . orgs ) }
77+ ${ renderLink ( "💬 Chats" , router . nav . chats ) }
78+ </ div >
8679 </ div >
8780 </ nav >
8881
89- < main > ${ "404 not found" } </ main >
82+ < main > ${ router . render ( ) } </ main >
9083
9184 < div class =blanket
9285 ?inert ="${ ! $navOpen ( ) } "
0 commit comments