1+ import gleam/result
2+ import gleam/uri
13import lustre
24import lustre/attribute
5+ import lustre/effect . { type Effect }
36import lustre/element . { type Element }
47import lustre/element/html
8+ import modem
59
610pub 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+
1321type 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
2653fn 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