Fixes wonky selection of item in search result (#90)

fixes #62
This commit is contained in:
Rok Garbas 2020-06-11 18:29:51 +02:00 committed by GitHub
parent 2983c00c74
commit f3139f56bf
Failed to generate hash of commit
4 changed files with 51 additions and 8 deletions

View file

@ -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

View file

@ -69,6 +69,7 @@ init :
-> Maybe String
-> Maybe Int
-> Maybe Int
-> Maybe Model
-> ( Model, Cmd Msg )
init =
Search.init

View file

@ -106,6 +106,7 @@ init :
-> Maybe String
-> Maybe Int
-> Maybe Int
-> Maybe Model
-> ( Model, Cmd Msg )
init =
Search.init

View file

@ -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
)