Skip to content

Commit 18fcc74

Browse files
committed
Reformat the Effect UI examples with stack-chains
1 parent 5159d16 commit 18fcc74

75 files changed

Lines changed: 4746 additions & 3728 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎examples/ui/auth/src/App.ts‎

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,17 @@ export const AppNoDeps = Html.component({
130130
$.set(AppModel.LoggedIn({ route: LoggedInRoute.Dashboard(), session }))
131131
.run(
132132
SaveSession.make({ session }),
133-
AppNavigation.Dashboard.replace().pipe(Command.asNoop)
133+
AppNavigation.Dashboard
134+
.replace()
135+
.pipe(Command.asNoop)
134136
),
135137

136138
SignedOut: ($) =>
137139
$.set(AppModel.LoggedOut({ route: LoggedOutRoute.Home() })).run(
138140
ClearSession.make(),
139-
AppNavigation.Home.replace().pipe(Command.asNoop)
141+
AppNavigation.Home
142+
.replace()
143+
.pipe(Command.asNoop)
140144
),
141145

142146
FailedSaveSession: ($, { error }) => $.run(LogError.make({ entries: ["Failed to save session:", error] })),
@@ -161,22 +165,24 @@ export const AppNoDeps = Html.component({
161165
],
162166

163167
view: (h, model) =>
164-
h.div.class("min-h-screen bg-gray-100").children(
165-
AppModel.match(model, {
166-
LoggedOut: ({ route }) =>
167-
LoggedOut(h, {
168-
props: { route },
169-
onEmit: {
170-
SignedIn: ({ session }) => AppMessage.SignedIn({ session })
171-
}
172-
}),
173-
LoggedIn: ({ route, session }) =>
174-
LoggedIn(h, {
175-
props: { route, session },
176-
onEmit: { SignedOut: () => AppMessage.SignedOut() }
177-
})
178-
})
179-
)
168+
h.div
169+
.class("min-h-screen bg-gray-100")
170+
.children(
171+
AppModel.match(model, {
172+
LoggedOut: ({ route }) =>
173+
LoggedOut(h, {
174+
props: { route },
175+
onEmit: {
176+
SignedIn: ({ session }) => AppMessage.SignedIn({ session })
177+
}
178+
}),
179+
LoggedIn: ({ route, session }) =>
180+
LoggedIn(h, {
181+
props: { route, session },
182+
onEmit: { SignedOut: () => AppMessage.SignedOut() }
183+
})
184+
})
185+
)
180186
})
181187

182188
export const App = AppNoDeps.pipe(

‎examples/ui/auth/src/LoggedIn.ts‎

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ const NavLink = LoggedInDef.fragment(
2323
(h, tag: "Dashboard" | "Settings") => {
2424
const active = tag === h.props.route._tag
2525
return h.li.children(
26-
h.a.attr("href", LoggedInRoute[tag].href())
26+
h.a
27+
.attr("href", LoggedInRoute[tag].href())
2728
.attr("aria-current", active ? "page" : undefined)
28-
.class(
29-
"hover:bg-blue-600 font-medium px-3 py-1 rounded transition",
30-
active && "bg-blue-700/50"
31-
)
29+
.class("hover:bg-blue-600 font-medium px-3 py-1 rounded transition", active && "bg-blue-700/50")
3230
.children(tag)
3331
)
3432
}
@@ -41,33 +39,41 @@ export const LoggedIn = LoggedInDef.make({
4139

4240
view: (h) => {
4341
const { route, session } = h.props
44-
return h.div.class("min-h-screen").children(
45-
h.nav.class("bg-blue-500 text-white p-4").children(
46-
h.div.class("max-w-4xl mx-auto flex justify-between items-center")
42+
return h.div
43+
.class("min-h-screen")
44+
.children(
45+
h.nav
46+
.class("bg-blue-500 text-white p-4")
4747
.children(
48-
h.ul.class("flex gap-6 list-none").children(
49-
NavLink(h, "Dashboard"),
50-
NavLink(h, "Settings")
51-
),
52-
h.div.class("text-sm").children(`Signed in as ${session.email}`)
53-
)
54-
),
55-
h.main.class("py-8").children(
56-
LoggedInRoute.match(route, {
57-
Dashboard: () => DashboardPage(h, session),
58-
Settings: () =>
59-
SettingsPage(h, {
60-
session,
61-
onSignOut: LoggedInMessage.ClickedSignOut()
62-
}),
63-
NotFound: (route) =>
64-
NotFound(h, {
65-
path: route.params["*"],
66-
backHref: LoggedInRoute.Dashboard.href(),
67-
backText: "Go to Dashboard"
48+
h.div
49+
.class("max-w-4xl mx-auto flex justify-between items-center")
50+
.children(
51+
h.ul
52+
.class("flex gap-6 list-none")
53+
.children(NavLink(h, "Dashboard"), NavLink(h, "Settings")),
54+
h.div
55+
.class("text-sm")
56+
.children(`Signed in as ${session.email}`)
57+
)
58+
),
59+
h.main
60+
.class("py-8")
61+
.children(
62+
LoggedInRoute.match(route, {
63+
Dashboard: () => DashboardPage(h, session),
64+
Settings: () =>
65+
SettingsPage(h, {
66+
session,
67+
onSignOut: LoggedInMessage.ClickedSignOut()
68+
}),
69+
NotFound: (route) =>
70+
NotFound(h, {
71+
path: route.params["*"],
72+
backHref: LoggedInRoute.Dashboard.href(),
73+
backText: "Go to Dashboard"
74+
})
6875
})
69-
})
76+
)
7077
)
71-
)
7278
}
7379
})

‎examples/ui/auth/src/LoggedOut.ts‎

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,23 @@ export const LoggedOut = Html.component({
2727
update: ($, { session }) => $.emit(LoggedOutEvents.SignedIn({ session })),
2828

2929
view: (h) =>
30-
h.div.class("py-8").children(
31-
LoggedOutRoute.match(h.props.route, {
32-
Home: () => HomePage(h),
33-
Login: () =>
34-
LoginPage(h, {
35-
onEmit: {
36-
SignedIn: ({ session }) => LoggedOutMessage.SignedInLogin({ session })
37-
}
38-
}),
39-
NotFound: (route) =>
40-
NotFound(h, {
41-
path: route.params["*"],
42-
backHref: LoggedOutRoute.Home.href(),
43-
backText: "Go Home"
44-
})
45-
})
46-
)
30+
h.div
31+
.class("py-8")
32+
.children(
33+
LoggedOutRoute.match(h.props.route, {
34+
Home: () => HomePage(h),
35+
Login: () =>
36+
LoginPage(h, {
37+
onEmit: {
38+
SignedIn: ({ session }) => LoggedOutMessage.SignedInLogin({ session })
39+
}
40+
}),
41+
NotFound: (route) =>
42+
NotFound(h, {
43+
path: route.params["*"],
44+
backHref: LoggedOutRoute.Home.href(),
45+
backText: "Go Home"
46+
})
47+
})
48+
)
4749
})

‎examples/ui/auth/src/pages/HomePage.ts‎

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,52 @@ import type { Html } from "effect/ui/html"
22
import { LoggedOutRoute } from "../routes.ts"
33

44
const FeatureCard = <M>(h: Html.H<M>, title: string, description: string) =>
5-
h.div.class("bg-white rounded-lg shadow-md p-6").children(
6-
h.h2.class("text-xl font-semibold text-gray-800 mb-3").children(title),
7-
h.p.class("text-gray-600").children(description)
8-
)
5+
h.div
6+
.class("bg-white rounded-lg shadow-md p-6")
7+
.children(
8+
h.h2
9+
.class("text-xl font-semibold text-gray-800 mb-3")
10+
.children(title),
11+
h.p
12+
.class("text-gray-600")
13+
.children(description)
14+
)
915

1016
export const HomePage = <M>(h: Html.H<M>) =>
11-
h.div.class("max-w-4xl mx-auto px-4").children(
12-
h.div.class("text-center py-16").children(
13-
h.h1.class("text-5xl font-bold text-gray-800 mb-6").children(
14-
"Welcome to Auth Example"
15-
),
16-
h.p.class("text-xl text-gray-600 mb-8").children(
17-
"A demonstration of authentication with a Model union and route guards in Effect UI."
18-
),
19-
h.a.attr("href", LoggedOutRoute.Login.href())
20-
.class(
21-
"inline-block px-8 py-3 bg-blue-500 text-white font-medium rounded-lg hover:bg-blue-600 transition"
17+
h.div
18+
.class("max-w-4xl mx-auto px-4")
19+
.children(
20+
h.div
21+
.class("text-center py-16")
22+
.children(
23+
h.h1
24+
.class("text-5xl font-bold text-gray-800 mb-6")
25+
.children("Welcome to Auth Example"),
26+
h.p
27+
.class("text-xl text-gray-600 mb-8")
28+
.children("A demonstration of authentication with a Model union and route guards in Effect UI."),
29+
h.a
30+
.attr("href", LoggedOutRoute.Login.href())
31+
.class("inline-block px-8 py-3 bg-blue-500 text-white font-medium rounded-lg hover:bg-blue-600 transition")
32+
.children("Sign In")
33+
),
34+
h.div
35+
.class("grid grid-cols-1 md:grid-cols-3 gap-8 mt-16")
36+
.children(
37+
FeatureCard(
38+
h,
39+
"Model as Union",
40+
"App state is fundamentally LoggedOut | LoggedIn, not a flat struct with optional session."
41+
),
42+
FeatureCard(
43+
h,
44+
"Route Guards",
45+
"Protected routes redirect to login. Auth routes redirect to dashboard when logged in."
46+
),
47+
FeatureCard(
48+
h,
49+
"Session Persistence",
50+
"Session survives page refresh via localStorage, read into the root's props before it mounts."
51+
)
2252
)
23-
.children("Sign In")
24-
),
25-
h.div.class("grid grid-cols-1 md:grid-cols-3 gap-8 mt-16").children(
26-
FeatureCard(
27-
h,
28-
"Model as Union",
29-
"App state is fundamentally LoggedOut | LoggedIn, not a flat struct with optional session."
30-
),
31-
FeatureCard(
32-
h,
33-
"Route Guards",
34-
"Protected routes redirect to login. Auth routes redirect to dashboard when logged in."
35-
),
36-
FeatureCard(
37-
h,
38-
"Session Persistence",
39-
"Session survives page refresh via localStorage, read into the root's props before it mounts."
40-
)
4153
)
42-
)

‎examples/ui/auth/src/pages/NotFound.ts‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ export const NotFound = <M>(h: Html.H<M>, options: {
55
readonly backHref: string
66
readonly backText: string
77
}) =>
8-
h.div.class("max-w-4xl mx-auto px-4 text-center").children(
9-
h.h1.class("text-4xl font-bold text-red-600 mb-6").children(
10-
"404 - Page Not Found"
11-
),
12-
h.p.class("text-lg text-gray-600 mb-4").children(
13-
`The path "${options.path}" was not found.`
14-
),
15-
h.a.attr("href", options.backHref).class("text-blue-500 hover:underline")
16-
.children(options.backText)
17-
)
8+
h.div
9+
.class("max-w-4xl mx-auto px-4 text-center")
10+
.children(
11+
h.h1
12+
.class("text-4xl font-bold text-red-600 mb-6")
13+
.children("404 - Page Not Found"),
14+
h.p
15+
.class("text-lg text-gray-600 mb-4")
16+
.children(`The path "${options.path}" was not found.`),
17+
h.a
18+
.attr("href", options.backHref)
19+
.class("text-blue-500 hover:underline")
20+
.children(options.backText)
21+
)

‎examples/ui/auth/src/pages/dashboard/DashboardPage.ts‎

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,32 @@ import type { Session } from "#domain/Session"
22
import type { Html } from "effect/ui/html"
33

44
const StatCard = <M>(h: Html.H<M>, title: string, value: string) =>
5-
h.div.class("bg-white rounded-lg shadow-md p-6").children(
6-
h.h2.class("text-sm font-medium text-gray-500 uppercase mb-1").children(
7-
title
8-
),
9-
h.p.class("text-3xl font-bold text-gray-800").children(value)
10-
)
5+
h.div
6+
.class("bg-white rounded-lg shadow-md p-6")
7+
.children(
8+
h.h2
9+
.class("text-sm font-medium text-gray-500 uppercase mb-1")
10+
.children(title),
11+
h.p
12+
.class("text-3xl font-bold text-gray-800")
13+
.children(value)
14+
)
1115

1216
export const DashboardPage = <M>(h: Html.H<M>, session: Session) =>
13-
h.div.class("max-w-4xl mx-auto px-4").children(
14-
h.h1.class("text-4xl font-bold text-gray-800 mb-6").children(
15-
`Welcome back, ${session.name}!`
16-
),
17-
h.p.class("text-lg text-gray-600 mb-8").children("Here is your dashboard."),
18-
h.div.class("grid grid-cols-1 md:grid-cols-3 gap-6").children(
19-
StatCard(h, "Total Sessions", "42"),
20-
StatCard(h, "Active Projects", "7"),
21-
StatCard(h, "Tasks Completed", "128")
17+
h.div
18+
.class("max-w-4xl mx-auto px-4")
19+
.children(
20+
h.h1
21+
.class("text-4xl font-bold text-gray-800 mb-6")
22+
.children(`Welcome back, ${session.name}!`),
23+
h.p
24+
.class("text-lg text-gray-600 mb-8")
25+
.children("Here is your dashboard."),
26+
h.div
27+
.class("grid grid-cols-1 md:grid-cols-3 gap-6")
28+
.children(
29+
StatCard(h, "Total Sessions", "42"),
30+
StatCard(h, "Active Projects", "7"),
31+
StatCard(h, "Tasks Completed", "128")
32+
)
2233
)
23-
)

0 commit comments

Comments
 (0)