this repo has no description
lustre frontent oat-ui gleam
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

:fire: remove "api_url" variable

+13 -43
+8 -32
client/src/client.gleam
··· 4 4 import client/page/navbar 5 5 import client/page/not_found 6 6 import client/page/sidebar 7 - import envoy 8 7 import gleam/bool 9 8 import gleam/http/response 10 9 import gleam/option 11 - import gleam/result 12 - import gleam/uri 13 10 import lustre 14 11 import lustre/effect.{type Effect} 15 12 import lustre/element ··· 26 23 route: route.Route, 27 24 /// Current Page model 28 25 page: page.Page, 29 - /// Server uri used for HTTP requests 30 - /// 31 - /// ┌──client──┐ ┌─────────server──────────┐ 32 - /// │  │─→│ https://localhost:8080/ │ 33 - /// └──────────┘ └─────────────────────────┘ 34 - api: uri.Uri, 35 26 ) 36 27 } 37 28 38 - pub opaque type InitOpts { 39 - InitOpts(api: uri.Uri) 40 - } 41 - 42 29 /// ┌──────┐ 43 30 /// ┌──────│ View │←─────┐ 44 31 /// ↓ └──────┘ │ ··· 47 34 /// └───────┘ └────────┘ 48 35 /// 49 36 pub fn main() -> Nil { 50 - let assert Ok(api) = { 51 - use value <- result.try(envoy.get("API_URL")) 52 - uri.parse(value) 53 - } 54 - as "Missing `API_URL` enviroment variable" 55 - 56 - let opts = InitOpts(api:) 57 37 let app = lustre.application(init:, update:, view:) 58 - let assert Ok(_runtime) = lustre.start(app, "#app", opts) 38 + let assert Ok(_runtime) = lustre.start(app, "#app", Nil) 59 39 60 40 Nil 61 41 } ··· 80 60 // INIT ------------------------------------------------------------------------ 81 61 82 62 /// Build initial application Model 83 - pub fn init(opts: InitOpts) -> #(Model, Effect(Msg)) { 63 + pub fn init(_opts: Nil) -> #(Model, Effect(Msg)) { 84 64 // Get the `Uri` of the page when it first loaded. 85 65 let assert Ok(uri) = modem.initial_uri() 86 66 let route = route.parse(uri) ··· 93 73 UserNavigatedTo(route.parse(uri)) 94 74 } 95 75 96 - let url = 97 - uri.Uri(..opts.api, path: "/whoami") 98 - |> uri.to_string 99 - 100 76 // 󱡯 Send a request to the Server to verify if the current 101 77 // token is still valid. 102 78 // ··· 105 81 let restore_session = 106 82 UserRestoredSession 107 83 |> rsvp.expect_json(session.decoder(), _) 108 - |> rsvp.get(url, _) 84 + |> rsvp.get("/api/whoami", _) 109 85 110 86 // Batch all scheduled effects and build the initial application `Model` 111 87 let effect = effect.batch([restore_session, init_modem]) 112 - #(Model(session:, route:, page:, api: opts.api), effect) 88 + #(Model(session:, route:, page:), effect) 113 89 } 114 90 115 91 fn init_session( ··· 145 121 pub fn view(model: Model) -> element.Element(Msg) { 146 122 case model { 147 123 // HOME PAGE --------------------------------------------------------------- 148 - Model(session:, route: route.Home, page: page.Home, ..) -> 124 + Model(session:, route: route.Home, page: page.Home) -> 149 125 layout(model, home.view(session), HomeMsg) 150 126 151 127 // LOGIN PAGE -------------------------------------------------------------- 152 - Model(session:, route: route.Login, page: page.Login(page), ..) -> 128 + Model(session:, route: route.Login, page: page.Login(page)) -> 153 129 layout(model, login.view(session, page), LoginMsg) 154 130 155 131 _ -> not_found.view() ··· 170 146 Model(session: session.Pending(on_success:, on_error: _), ..), 171 147 UserRestoredSession(Ok(session)) 172 148 -> #( 173 - Model(..model, session:, route: on_success, page: page.init(on_success)), 149 + Model(session:, route: on_success, page: page.init(on_success)), 174 150 modem.push(route.to_path(on_success), option.None, option.None), 175 151 ) 176 152 ··· 231 207 page: login.Model, 232 208 msg: login.Msg, 233 209 ) -> #(Model, Effect(Msg)) { 234 - case login.update(page, msg, model.api) { 210 + case login.update(page, msg) { 235 211 login.Continue(page, effect) -> #( 236 212 Model(..model, page: page.Login(page)), 237 213 effect.map(effect, LoginMsg),
+2 -7
client/src/client/page/login.gleam
··· 1 1 import gleam/json 2 - import gleam/uri 3 2 import lustre/effect 4 3 import lustre/element 5 4 import lustre/element/html ··· 43 42 ServerFailedToAuthenticate(reason: rsvp.Error) 44 43 } 45 44 46 - pub fn update(model: Model, msg: Msg, api: uri.Uri) -> LoginStep { 45 + pub fn update(model: Model, msg: Msg) -> LoginStep { 47 46 case msg { 48 47 // FIELDS ------------------------------------------------------------------ 49 48 UserTypedEmail(email:) -> { ··· 63 62 #("password", json.string(model.password)), 64 63 ]) 65 64 66 - let path = 67 - uri.Uri(..api, path: "/login") 68 - |> uri.to_string 69 - 70 65 let effect = 71 66 ApiReturnedSession 72 67 |> rsvp.expect_json(session.decoder(), _) 73 - |> rsvp.post(path, body, _) 68 + |> rsvp.post("/login", body, _) 74 69 75 70 let model = Model(..model, loading: True) 76 71 Continue(model, effect)
+3 -4
client/test/page/login_test.gleam
··· 1 1 import client/page/login 2 2 import dummy 3 3 import gleam/list 4 - import gleam/uri 5 4 import lustre/effect 6 5 import rsvp 7 6 import shared/session ··· 18 17 19 18 let #(model, _) = { 20 19 use acc, msg <- list.fold(sequence, #(login.empty, effect.none())) 21 - let assert login.Continue(model, _) = login.update(acc.0, msg, uri.empty) 20 + let assert login.Continue(model, _) = login.update(acc.0, msg) 22 21 23 22 #(model, effect.none()) 24 23 } ··· 34 33 let model = 35 34 Ok(session.Authenticated(want)) 36 35 |> login.ApiReturnedSession 37 - |> login.update(login.empty, _, uri.empty) 36 + |> login.update(login.empty, _) 38 37 39 38 let assert login.ServerAuthenticatedUser(resp) = model 40 39 let assert session.Authenticated(got) = resp ··· 46 45 let model = 47 46 Error(rsvp.NetworkError) 48 47 |> login.ApiReturnedSession 49 - |> login.update(login.empty, _, uri.empty) 48 + |> login.update(login.empty, _) 50 49 51 50 let assert login.ServerFailedToAuthenticate(_) = model 52 51 }