diff --git a/src/Main.elm b/src/Main.elm index 91ea597..7a09854 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -148,7 +148,10 @@ submitQuery old ( new, cmd ) = ( new, cmd ) -changeRouteTo : Model -> Url.Url -> ( Model, Cmd Msg ) +changeRouteTo : + Model + -> Url.Url + -> ( Model, Cmd Msg ) changeRouteTo model url = let newModel = @@ -178,12 +181,30 @@ changeRouteTo model url = ( newModel, Browser.Navigation.pushUrl newModel.navKey "/packages" ) Just (Route.Packages channel query show from size) -> - Page.Packages.init channel query show from size + let + modelPage = + case newModel.page of + Packages x -> + Just x + + _ -> + Nothing + in + Page.Packages.init channel query show from size modelPage |> updateWith Packages PackagesMsg newModel |> submitQuery newModel Just (Route.Options channel query show from size) -> - Page.Options.init channel query show from size + let + modelPage = + case newModel.page of + Options x -> + Just x + + _ -> + Nothing + in + Page.Options.init channel query show from size modelPage |> updateWith Options OptionsMsg newModel |> submitQuery newModel diff --git a/src/Page/Options.elm b/src/Page/Options.elm index fc58fea..02005b0 100644 --- a/src/Page/Options.elm +++ b/src/Page/Options.elm @@ -69,6 +69,7 @@ init : -> Maybe String -> Maybe Int -> Maybe Int + -> Maybe Model -> ( Model, Cmd Msg ) init = Search.init diff --git a/src/Page/Packages.elm b/src/Page/Packages.elm index de0edc9..fbdc5fd 100644 --- a/src/Page/Packages.elm +++ b/src/Page/Packages.elm @@ -106,6 +106,7 @@ init : -> Maybe String -> Maybe Int -> Maybe Int + -> Maybe Model -> ( Model, Cmd Msg ) init = Search.init diff --git a/src/Search.elm b/src/Search.elm index dcf1138..4b0b784 100644 --- a/src/Search.elm +++ b/src/Search.elm @@ -99,14 +99,34 @@ init : -> Maybe String -> Maybe Int -> Maybe Int + -> Maybe (Model a) -> ( Model a, Cmd msg ) -init channel query show from size = - ( { channel = Maybe.withDefault "unstable" channel +init channel query show from size model = + let + defaultChannel = + model + |> Maybe.map (\x -> x.channel) + |> Maybe.withDefault "unstable" + + defaultFrom = + model + |> Maybe.map (\x -> x.from) + |> Maybe.withDefault 0 + + defaultSize = + model + |> Maybe.map (\x -> x.size) + |> Maybe.withDefault 15 + in + ( { channel = Maybe.withDefault defaultChannel channel , query = query - , result = RemoteData.NotAsked + , result = + model + |> Maybe.map (\x -> x.result) + |> Maybe.withDefault RemoteData.NotAsked , show = show - , from = Maybe.withDefault 0 from - , size = Maybe.withDefault 15 size + , from = Maybe.withDefault defaultFrom from + , size = Maybe.withDefault defaultSize size } , Cmd.none )