From fcd9ccb76ca6fbb233daaa356f6a543968b8fd62 Mon Sep 17 00:00:00 2001 From: David May <49894298+wass3rw3rk@users.noreply.github.com> Date: Mon, 22 Apr 2024 10:12:09 -0500 Subject: [PATCH] enhance: parity with elm-land (#791) --- src/elm/Auth.elm | 8 ++--- src/elm/Auth/Action.elm | 44 ++++++++++++++++++-------- src/elm/Main.elm | 68 ++++++++++++++++++++++------------------- 3 files changed, 71 insertions(+), 49 deletions(-) diff --git a/src/elm/Auth.elm b/src/elm/Auth.elm index e39eac71b..d1de3cf93 100644 --- a/src/elm/Auth.elm +++ b/src/elm/Auth.elm @@ -3,7 +3,7 @@ SPDX-License-Identifier: Apache-2.0 --} -module Auth exposing (User, onPageLoad, viewLoadingPage) +module Auth exposing (User, onPageLoad, viewCustomPage) import Auth.Action import Auth.Session exposing (Session(..)) @@ -39,8 +39,8 @@ onPageLoad shared route = } -{-| Renders whenever `Auth.Action.showLoadingPage` is returned from `onPageLoad`. +{-| Renders whenever `Auth.Action.loadCustomPage` is returned from `onPageLoad`. -} -viewLoadingPage : Shared.Model -> Route () -> View Never -viewLoadingPage shared route = +viewCustomPage : Shared.Model -> Route () -> View Never +viewCustomPage shared route = View.fromString "Loading..." diff --git a/src/elm/Auth/Action.elm b/src/elm/Auth/Action.elm index 6669bc979..6f0d5d55b 100644 --- a/src/elm/Auth/Action.elm +++ b/src/elm/Auth/Action.elm @@ -5,7 +5,7 @@ SPDX-License-Identifier: Apache-2.0 module Auth.Action exposing ( Action(..) - , loadPageWithUser, showLoadingPage + , loadPageWithUser, loadCustomPage , replaceRoute, pushRoute, loadExternalUrl , view, subscriptions, command ) @@ -13,7 +13,7 @@ module Auth.Action exposing {-| @docs Action -@docs loadPageWithUser, showLoadingPage +@docs loadPageWithUser, loadCustomPage @docs replaceRoute, pushRoute, loadExternalUrl @docs view, subscriptions, command @@ -25,9 +25,12 @@ import Route.Path import View exposing (View) +{-| Describes the action to take for authenticated pages, based +on the current `Route` and `Shared.Model` +-} type Action user = LoadPageWithUser user - | ShowLoadingPage (View Never) + | LoadCustomPage | ReplaceRoute { path : Route.Path.Path , query : Dict String String @@ -41,16 +44,27 @@ type Action user | LoadExternalUrl String +{-| Successfully pass the user along to the authenticated page. +-} loadPageWithUser : user -> Action user loadPageWithUser = LoadPageWithUser -showLoadingPage : View Never -> Action user -showLoadingPage = - ShowLoadingPage +{-| Rather than navigating to a different route, keep the URL, but render +what was defined in `Auth.loadCustomPage`. + +**Note:** `Auth.loadCustomPage` has access to the `Shared.Model`, so you +can render different pages in different authentication scenarios. + +-} +loadCustomPage : Action user +loadCustomPage = + LoadCustomPage +{-| Replace the URL with the provided route. +-} replaceRoute : { path : Route.Path.Path , query : Dict String String @@ -61,6 +75,8 @@ replaceRoute = ReplaceRoute +{-| Push a new URL with the provided route. +-} pushRoute : { path : Route.Path.Path , query : Dict String String @@ -71,6 +87,8 @@ pushRoute = PushRoute +{-| Navigate to a URL for an external website. +-} loadExternalUrl : String -> Action user loadExternalUrl = LoadExternalUrl @@ -80,14 +98,14 @@ loadExternalUrl = -- USED INTERNALLY BY ELM LAND -view : (user -> View msg) -> Action user -> View msg -view toView authAction = +view : View msg -> (user -> View msg) -> Action user -> View msg +view viewCustomPage viewPageWithUser authAction = case authAction of LoadPageWithUser user -> - toView user + viewPageWithUser user - ShowLoadingPage loadingView -> - View.map never loadingView + LoadCustomPage -> + viewCustomPage ReplaceRoute _ -> View.none @@ -105,7 +123,7 @@ subscriptions toSub authAction = LoadPageWithUser user -> toSub user - ShowLoadingPage _ -> + LoadCustomPage -> Sub.none ReplaceRoute _ -> @@ -124,7 +142,7 @@ command toCmd authAction = LoadPageWithUser user -> toCmd user - ShowLoadingPage _ -> + LoadCustomPage -> Cmd.none ReplaceRoute _ -> diff --git a/src/elm/Main.elm b/src/elm/Main.elm index 7ae84ff56..e9543ebc7 100644 --- a/src/elm/Main.elm +++ b/src/elm/Main.elm @@ -1172,7 +1172,7 @@ runWhenAuthenticatedWithLayout model toRecord = Auth.Action.LoadPageWithUser user -> toRecord user - Auth.Action.ShowLoadingPage loadingView -> + Auth.Action.LoadCustomPage -> { page = ( Main.Pages.Model.Loading_ , Cmd.none @@ -1239,9 +1239,13 @@ update msg model = ) UrlRequested (Browser.External url) -> - ( model - , Browser.Navigation.load url - ) + if String.isEmpty (String.trim url) then + ( model, Cmd.none ) + + else + ( model + , Browser.Navigation.load url + ) UrlChanged url -> if Route.Path.fromUrl url == Route.Path.fromUrl model.url then @@ -1951,7 +1955,7 @@ hasActionTypeChanged oldAction newAction = ( Auth.Action.LoadPageWithUser _, Auth.Action.LoadPageWithUser _ ) -> False - ( Auth.Action.ShowLoadingPage _, Auth.Action.ShowLoadingPage _ ) -> + ( Auth.Action.LoadCustomPage, Auth.Action.LoadCustomPage ) -> False ( Auth.Action.ReplaceRoute _, Auth.Action.ReplaceRoute _ ) -> @@ -2414,7 +2418,7 @@ viewPage : Model -> View Msg viewPage model = case model.page of Main.Pages.Model.Home_ pageModel -> - Auth.Action.view + Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url))) (\user -> Page.view (Pages.Home_.page user model.shared (Route.fromUrl () model.url)) pageModel |> View.map Main.Pages.Msg.Home_ @@ -2438,7 +2442,7 @@ viewPage model = |> View.map Page Main.Pages.Model.Account_Settings pageModel -> - Auth.Action.view + Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url))) (\user -> Page.view (Pages.Account.Settings.page user model.shared (Route.fromUrl () model.url)) pageModel |> View.map Main.Pages.Msg.Account_Settings @@ -2447,7 +2451,7 @@ viewPage model = (Auth.onPageLoad model.shared (Route.fromUrl () model.url)) Main.Pages.Model.Account_SourceRepos pageModel -> - Auth.Action.view + Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url))) (\user -> Page.view (Pages.Account.SourceRepos.page user model.shared (Route.fromUrl () model.url)) pageModel |> View.map Main.Pages.Msg.Account_SourceRepos @@ -2456,7 +2460,7 @@ viewPage model = (Auth.onPageLoad model.shared (Route.fromUrl () model.url)) Main.Pages.Model.Dash_Secrets_Engine__Org_Org_ params pageModel -> - Auth.Action.view + Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url))) (\user -> Page.view (Pages.Dash.Secrets.Engine_.Org.Org_.page user model.shared (Route.fromUrl params model.url)) pageModel |> View.map Main.Pages.Msg.Dash_Secrets_Engine__Org_Org_ @@ -2465,7 +2469,7 @@ viewPage model = (Auth.onPageLoad model.shared (Route.fromUrl () model.url)) Main.Pages.Model.Dash_Secrets_Engine__Org_Org__Add params pageModel -> - Auth.Action.view + Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url))) (\user -> Page.view (Pages.Dash.Secrets.Engine_.Org.Org_.Add.page user model.shared (Route.fromUrl params model.url)) pageModel |> View.map Main.Pages.Msg.Dash_Secrets_Engine__Org_Org__Add @@ -2474,7 +2478,7 @@ viewPage model = (Auth.onPageLoad model.shared (Route.fromUrl () model.url)) Main.Pages.Model.Dash_Secrets_Engine__Org_Org__Name_ params pageModel -> - Auth.Action.view + Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url))) (\user -> Page.view (Pages.Dash.Secrets.Engine_.Org.Org_.Name_.page user model.shared (Route.fromUrl params model.url)) pageModel |> View.map Main.Pages.Msg.Dash_Secrets_Engine__Org_Org__Name_ @@ -2483,7 +2487,7 @@ viewPage model = (Auth.onPageLoad model.shared (Route.fromUrl () model.url)) Main.Pages.Model.Dash_Secrets_Engine__Repo_Org__Repo_ params pageModel -> - Auth.Action.view + Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url))) (\user -> Page.view (Pages.Dash.Secrets.Engine_.Repo.Org_.Repo_.page user model.shared (Route.fromUrl params model.url)) pageModel |> View.map Main.Pages.Msg.Dash_Secrets_Engine__Repo_Org__Repo_ @@ -2492,7 +2496,7 @@ viewPage model = (Auth.onPageLoad model.shared (Route.fromUrl () model.url)) Main.Pages.Model.Dash_Secrets_Engine__Repo_Org__Repo__Add params pageModel -> - Auth.Action.view + Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url))) (\user -> Page.view (Pages.Dash.Secrets.Engine_.Repo.Org_.Repo_.Add.page user model.shared (Route.fromUrl params model.url)) pageModel |> View.map Main.Pages.Msg.Dash_Secrets_Engine__Repo_Org__Repo__Add @@ -2501,7 +2505,7 @@ viewPage model = (Auth.onPageLoad model.shared (Route.fromUrl () model.url)) Main.Pages.Model.Dash_Secrets_Engine__Repo_Org__Repo__Name_ params pageModel -> - Auth.Action.view + Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url))) (\user -> Page.view (Pages.Dash.Secrets.Engine_.Repo.Org_.Repo_.Name_.page user model.shared (Route.fromUrl params model.url)) pageModel |> View.map Main.Pages.Msg.Dash_Secrets_Engine__Repo_Org__Repo__Name_ @@ -2510,7 +2514,7 @@ viewPage model = (Auth.onPageLoad model.shared (Route.fromUrl () model.url)) Main.Pages.Model.Dash_Secrets_Engine__Shared_Org__Team_ params pageModel -> - Auth.Action.view + Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url))) (\user -> Page.view (Pages.Dash.Secrets.Engine_.Shared.Org_.Team_.page user model.shared (Route.fromUrl params model.url)) pageModel |> View.map Main.Pages.Msg.Dash_Secrets_Engine__Shared_Org__Team_ @@ -2519,7 +2523,7 @@ viewPage model = (Auth.onPageLoad model.shared (Route.fromUrl () model.url)) Main.Pages.Model.Dash_Secrets_Engine__Shared_Org__Team__Add params pageModel -> - Auth.Action.view + Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url))) (\user -> Page.view (Pages.Dash.Secrets.Engine_.Shared.Org_.Team_.Add.page user model.shared (Route.fromUrl params model.url)) pageModel |> View.map Main.Pages.Msg.Dash_Secrets_Engine__Shared_Org__Team__Add @@ -2528,7 +2532,7 @@ viewPage model = (Auth.onPageLoad model.shared (Route.fromUrl () model.url)) Main.Pages.Model.Dash_Secrets_Engine__Shared_Org__Team__Name_ params pageModel -> - Auth.Action.view + Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url))) (\user -> Page.view (Pages.Dash.Secrets.Engine_.Shared.Org_.Team_.Name_.page user model.shared (Route.fromUrl params model.url)) pageModel |> View.map Main.Pages.Msg.Dash_Secrets_Engine__Shared_Org__Team__Name_ @@ -2537,7 +2541,7 @@ viewPage model = (Auth.onPageLoad model.shared (Route.fromUrl () model.url)) Main.Pages.Model.Org_ params pageModel -> - Auth.Action.view + Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url))) (\user -> Page.view (Pages.Org_.page user model.shared (Route.fromUrl params model.url)) pageModel |> View.map Main.Pages.Msg.Org_ @@ -2546,7 +2550,7 @@ viewPage model = (Auth.onPageLoad model.shared (Route.fromUrl () model.url)) Main.Pages.Model.Org__Builds params pageModel -> - Auth.Action.view + Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url))) (\user -> Page.view (Pages.Org_.Builds.page user model.shared (Route.fromUrl params model.url)) pageModel |> View.map Main.Pages.Msg.Org__Builds @@ -2555,7 +2559,7 @@ viewPage model = (Auth.onPageLoad model.shared (Route.fromUrl () model.url)) Main.Pages.Model.Org__Repo_ params pageModel -> - Auth.Action.view + Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url))) (\user -> Page.view (Pages.Org_.Repo_.page user model.shared (Route.fromUrl params model.url)) pageModel |> View.map Main.Pages.Msg.Org__Repo_ @@ -2564,7 +2568,7 @@ viewPage model = (Auth.onPageLoad model.shared (Route.fromUrl () model.url)) Main.Pages.Model.Org__Repo__Deployments params pageModel -> - Auth.Action.view + Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url))) (\user -> Page.view (Pages.Org_.Repo_.Deployments.page user model.shared (Route.fromUrl params model.url)) pageModel |> View.map Main.Pages.Msg.Org__Repo__Deployments @@ -2573,7 +2577,7 @@ viewPage model = (Auth.onPageLoad model.shared (Route.fromUrl () model.url)) Main.Pages.Model.Org__Repo__Deployments_Add params pageModel -> - Auth.Action.view + Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url))) (\user -> Page.view (Pages.Org_.Repo_.Deployments.Add.page user model.shared (Route.fromUrl params model.url)) pageModel |> View.map Main.Pages.Msg.Org__Repo__Deployments_Add @@ -2582,7 +2586,7 @@ viewPage model = (Auth.onPageLoad model.shared (Route.fromUrl () model.url)) Main.Pages.Model.Org__Repo__Hooks params pageModel -> - Auth.Action.view + Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url))) (\user -> Page.view (Pages.Org_.Repo_.Hooks.page user model.shared (Route.fromUrl params model.url)) pageModel |> View.map Main.Pages.Msg.Org__Repo__Hooks @@ -2596,7 +2600,7 @@ viewPage model = |> View.map Page Main.Pages.Model.Org__Repo__Schedules params pageModel -> - Auth.Action.view + Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url))) (\user -> Page.view (Pages.Org_.Repo_.Schedules.page user model.shared (Route.fromUrl params model.url)) pageModel |> View.map Main.Pages.Msg.Org__Repo__Schedules @@ -2605,7 +2609,7 @@ viewPage model = (Auth.onPageLoad model.shared (Route.fromUrl () model.url)) Main.Pages.Model.Org__Repo__Schedules_Add params pageModel -> - Auth.Action.view + Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url))) (\user -> Page.view (Pages.Org_.Repo_.Schedules.Add.page user model.shared (Route.fromUrl params model.url)) pageModel |> View.map Main.Pages.Msg.Org__Repo__Schedules_Add @@ -2614,7 +2618,7 @@ viewPage model = (Auth.onPageLoad model.shared (Route.fromUrl () model.url)) Main.Pages.Model.Org__Repo__Schedules_Name_ params pageModel -> - Auth.Action.view + Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url))) (\user -> Page.view (Pages.Org_.Repo_.Schedules.Name_.page user model.shared (Route.fromUrl params model.url)) pageModel |> View.map Main.Pages.Msg.Org__Repo__Schedules_Name_ @@ -2623,7 +2627,7 @@ viewPage model = (Auth.onPageLoad model.shared (Route.fromUrl () model.url)) Main.Pages.Model.Org__Repo__Settings params pageModel -> - Auth.Action.view + Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url))) (\user -> Page.view (Pages.Org_.Repo_.Settings.page user model.shared (Route.fromUrl params model.url)) pageModel |> View.map Main.Pages.Msg.Org__Repo__Settings @@ -2637,7 +2641,7 @@ viewPage model = |> View.map Page Main.Pages.Model.Org__Repo__Build_ params pageModel -> - Auth.Action.view + Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url))) (\user -> Page.view (Pages.Org_.Repo_.Build_.page user model.shared (Route.fromUrl params model.url)) pageModel |> View.map Main.Pages.Msg.Org__Repo__Build_ @@ -2646,7 +2650,7 @@ viewPage model = (Auth.onPageLoad model.shared (Route.fromUrl () model.url)) Main.Pages.Model.Org__Repo__Build__Graph params pageModel -> - Auth.Action.view + Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url))) (\user -> Page.view (Pages.Org_.Repo_.Build_.Graph.page user model.shared (Route.fromUrl params model.url)) pageModel |> View.map Main.Pages.Msg.Org__Repo__Build__Graph @@ -2655,7 +2659,7 @@ viewPage model = (Auth.onPageLoad model.shared (Route.fromUrl () model.url)) Main.Pages.Model.Org__Repo__Build__Pipeline params pageModel -> - Auth.Action.view + Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url))) (\user -> Page.view (Pages.Org_.Repo_.Build_.Pipeline.page user model.shared (Route.fromUrl params model.url)) pageModel |> View.map Main.Pages.Msg.Org__Repo__Build__Pipeline @@ -2664,7 +2668,7 @@ viewPage model = (Auth.onPageLoad model.shared (Route.fromUrl () model.url)) Main.Pages.Model.Org__Repo__Build__Services params pageModel -> - Auth.Action.view + Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url))) (\user -> Page.view (Pages.Org_.Repo_.Build_.Services.page user model.shared (Route.fromUrl params model.url)) pageModel |> View.map Main.Pages.Msg.Org__Repo__Build__Services @@ -2681,7 +2685,7 @@ viewPage model = View.none Main.Pages.Model.Loading_ -> - Auth.viewLoadingPage model.shared (Route.fromUrl () model.url) + Auth.viewCustomPage model.shared (Route.fromUrl () model.url) |> View.map never