Skip to content

Commit bbfe246

Browse files
committed
integrate: sly spa router
1 parent e91a1dd commit bbfe246

File tree

4 files changed

+58
-56
lines changed

4 files changed

+58
-56
lines changed

package-lock.json

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
"dependencies": {
3131
"@e280/kv": "^0.1.0",
3232
"@e280/renraku": "^0.5.0",
33-
"@e280/sly": "^0.2.0-16",
34-
"@e280/strata": "^0.2.0-13",
35-
"@e280/stz": "^0.2.5",
33+
"@e280/sly": "^0.2.0-17",
34+
"@e280/strata": "^0.2.0-14",
35+
"@e280/stz": "^0.2.6",
3636
"lit": "^3.3.1"
3737
},
3838
"devDependencies": {

s/ui/app/component.ts

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
import {html} from "lit"
3-
import {view} from "@e280/sly"
3+
import {spa, view} from "@e280/sly"
44

55
import styleCss from "./style.css.js"
66
import {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()}"

s/ui/app/style.css.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ main {
108108
padding-top: 4em;
109109
height: 100%;
110110
overflow-y: auto;
111+
112+
[view="loading"] {
113+
font-size: 5em;
114+
display: flex;
115+
justify-content: center;
116+
align-items: center;
117+
width: 100%;
118+
height: 100%;
119+
}
111120
}
112121
113122
.blanket {

0 commit comments

Comments
 (0)