Skip to content

Commit 97e04a1

Browse files
committed
setup routing
1 parent 0d4a292 commit 97e04a1

File tree

5 files changed

+84
-49
lines changed

5 files changed

+84
-49
lines changed

gleam.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ target = "javascript"
1717
gleam_stdlib = ">= 0.44.0 and < 2.0.0"
1818
lustre = ">= 5.3.5 and < 6.0.0"
1919
gleam_javascript = ">= 1.0.0 and < 2.0.0"
20+
modem = ">= 2.1.1 and < 3.0.0"
2021

2122
[dev-dependencies]
2223
gleeunit = ">= 1.0.0 and < 2.0.0"
@@ -33,4 +34,4 @@ host = "0.0.0.0"
3334
port = 8080
3435

3536
[tools.lustre.html]
36-
title = "🚧 wiskiy"
37+
title = "🚧 wiskiy"

index.html

Lines changed: 0 additions & 12 deletions
This file was deleted.

manifest.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ packages = [
3333
{ name = "lustre_dev_tools", version = "2.0.2", build_tools = ["gleam"], requirements = ["argv", "booklet", "filepath", "gleam_community_ansi", "gleam_crypto", "gleam_erlang", "gleam_http", "gleam_httpc", "gleam_json", "gleam_otp", "gleam_regexp", "gleam_stdlib", "glint", "group_registry", "justin", "lustre", "mist", "polly", "simplifile", "tom", "wisp"], otp_app = "lustre_dev_tools", source = "hex", outer_checksum = "BA4281B369292A0100D2FA66B6886C7A4205537EE0D5D38B3CAC504BA724E91E" },
3434
{ name = "marceau", version = "1.3.0", build_tools = ["gleam"], requirements = [], otp_app = "marceau", source = "hex", outer_checksum = "2D1C27504BEF45005F5DFB18591F8610FB4BFA91744878210BDC464412EC44E9" },
3535
{ name = "mist", version = "5.0.3", build_tools = ["gleam"], requirements = ["exception", "gleam_erlang", "gleam_http", "gleam_otp", "gleam_stdlib", "gleam_yielder", "glisten", "gramps", "hpack_erl", "logging"], otp_app = "mist", source = "hex", outer_checksum = "7C4BE717A81305323C47C8A591E6B9BA4AC7F56354BF70B4D3DF08CC01192668" },
36+
{ name = "modem", version = "2.1.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "lustre"], otp_app = "modem", source = "hex", outer_checksum = "444332FF806610B955D57389B3643245BBEC61A705A61B4FF7E67E3AF148F339" },
3637
{ name = "platform", version = "1.0.0", build_tools = ["gleam"], requirements = [], otp_app = "platform", source = "hex", outer_checksum = "8339420A95AD89AAC0F82F4C3DB8DD401041742D6C3F46132A8739F6AEB75391" },
3738
{ name = "polly", version = "2.1.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib", "simplifile"], otp_app = "polly", source = "hex", outer_checksum = "1BA4D0ACE9BCF52AEA6AD9DE020FD8220CCA399A379E50A1775FC5C1204FCF56" },
3839
{ name = "simplifile", version = "2.3.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "0A868DAC6063D9E983477981839810DC2E553285AB4588B87E3E9C96A7FB4CB4" },
@@ -48,3 +49,4 @@ gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" }
4849
gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
4950
lustre = { version = ">= 5.3.5 and < 6.0.0" }
5051
lustre_dev_tools = { version = ">= 2.0.2 and < 3.0.0" }
52+
modem = { version = ">= 2.1.1 and < 3.0.0" }

src/app.css

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,17 @@
3838
}
3939

4040
@layer base {
41-
html, body {
42-
@apply h-full
41+
html {
42+
@apply min-h-screen;
43+
}
44+
45+
body {
46+
@apply min-h-screen bg-background text-primary;
4347
}
4448
}
4549

4650
@layer components {
4751
#app {
48-
@apply h-full flex flex-col px-4 font-monocraft bg-background text-primary;
52+
@apply min-h-screen flex flex-col px-4 font-monocraft max-w-5xl mx-auto;
4953
}
5054
}

src/app.gleam

Lines changed: 73 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,69 @@
1+
import gleam/result
2+
import gleam/uri
13
import lustre
24
import lustre/attribute
5+
import lustre/effect.{type Effect}
36
import lustre/element.{type Element}
47
import lustre/element/html
8+
import modem
59

610
pub fn main() {
7-
let app = lustre.simple(init, update, view)
11+
let app = lustre.application(init, update, view)
812
let assert Ok(_) = lustre.start(app, "#app", Nil)
913

1014
Nil
1115
}
1216

17+
pub type Route {
18+
Home
19+
}
20+
1321
type Model =
14-
Nil
22+
Route
1523

16-
fn init(_args) -> Model {
17-
Nil
24+
fn init(_args) -> #(Model, Effect(Msg)) {
25+
let route =
26+
modem.initial_uri()
27+
|> result.map(fn(uri) { uri.path_segments(uri.path) })
28+
|> fn(path) {
29+
case path {
30+
_ -> Home
31+
}
32+
}
33+
34+
#(route, modem.init(on_url_change))
1835
}
1936

20-
type Msg
37+
fn on_url_change(uri: uri.Uri) -> Msg {
38+
case uri.path_segments(uri.path) {
39+
_ -> OnRouterChange(Home)
40+
}
41+
}
2142

22-
fn update(model: Model, msg: Msg) -> Model {
23-
Nil
43+
type Msg {
44+
OnRouterChange(Route)
45+
}
46+
47+
fn update(model: Model, msg: Msg) -> #(Model, Effect(Msg)) {
48+
case msg {
49+
OnRouterChange(route) -> #(route, effect.none())
50+
}
2451
}
2552

2653
fn view(model: Model) -> Element(Msg) {
2754
element.fragment([
28-
view_navbar(),
55+
view_header(),
2956
html.main([attribute.class("flex-1 flex items-center justify-center")], [
30-
view_hero(),
57+
case model {
58+
Home -> view_home()
59+
},
3160
]),
61+
view_footer(),
3262
])
3363
}
3464

35-
fn view_navbar() -> Element(Msg) {
36-
html.header([], [
65+
fn view_header() -> Element(Msg) {
66+
html.header([attribute.class("h-7")], [
3767
html.nav([attribute.class("bg-background")], [
3868
html.div([attribute.class("")], [
3969
html.a([attribute.href("/")], [html.text("Home")]),
@@ -42,7 +72,15 @@ fn view_navbar() -> Element(Msg) {
4272
])
4373
}
4474

45-
fn view_hero() -> Element(Msg) {
75+
fn view_footer() -> Element(Msg) {
76+
html.footer([], [
77+
html.p([attribute.class("my-4 text-center text-sm text-stone-500")], [
78+
html.text("Made with Gleam & Lustre"),
79+
]),
80+
])
81+
}
82+
83+
fn view_home() -> Element(Msg) {
4684
html.section([attribute.class("sm:flex sm:gap-6")], [
4785
html.div([], [
4886
html.img([
@@ -66,37 +104,39 @@ fn view_hero() -> Element(Msg) {
66104
html.p(
67105
[
68106
attribute.class(
69-
"mt-4 text-justify leading-6 xs:max-w-md sm:max-w-sm md:max-w-lg md:text-lg xl:text-xl",
107+
"mt-4 text-justify leading-6 xs:max-w-md sm:max-w-sm md:max-w-lg
108+
md:text-lg xl:text-xl",
70109
),
71110
],
72111
[
73112
html.text(
74-
"19 y/o, student & developer from Russia. I'm passionate about networking and backend development, and I'm currently working on my own side projects and having fun working with new technologies. In love with ",
75-
),
76-
html.a(
77-
[
78-
attribute.class("text-detail"),
79-
attribute.href("https://gleam.run"),
80-
attribute.target("_blank"),
81-
],
82-
[html.text("#gleam")],
113+
"19 y/o, student & developer from Russia. I'm passionate about
114+
networking and backend development, and I'm currently working on my
115+
own side projects and having fun working with new technologies. In
116+
love with ",
83117
),
118+
tag("gleam", "https://gleam.run"),
84119
html.text(", "),
85-
html.a(
86-
[
87-
attribute.class("text-detail"),
88-
attribute.href(
89-
"https://rateyourmusic.com/list/Hyp3r10n/_dariacore-hyperflip/1/",
90-
),
91-
attribute.target("_blank"),
92-
],
93-
[
94-
html.text("#hyperflip"),
95-
],
120+
tag(
121+
"hyperflip",
122+
"https://rateyourmusic.com/list/Hyp3r10n/_dariacore-hyperflip/1/",
96123
),
97124
html.text("."),
98125
],
99126
),
100127
]),
101128
])
102129
}
130+
131+
fn tag(name: String, link: String) -> Element(Msg) {
132+
html.a(
133+
[
134+
attribute.class("text-detail"),
135+
attribute.href(link),
136+
attribute.target("_blank"),
137+
],
138+
[
139+
html.text("#" <> name),
140+
],
141+
)
142+
}

0 commit comments

Comments
 (0)