parent
2983c00c74
commit
f3139f56bf
27
src/Main.elm
27
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
|
||||
|
||||
|
|
|
@ -69,6 +69,7 @@ init :
|
|||
-> Maybe String
|
||||
-> Maybe Int
|
||||
-> Maybe Int
|
||||
-> Maybe Model
|
||||
-> ( Model, Cmd Msg )
|
||||
init =
|
||||
Search.init
|
||||
|
|
|
@ -106,6 +106,7 @@ init :
|
|||
-> Maybe String
|
||||
-> Maybe Int
|
||||
-> Maybe Int
|
||||
-> Maybe Model
|
||||
-> ( Model, Cmd Msg )
|
||||
init =
|
||||
Search.init
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue