Merge pull request #381 from eikek/fix-search-scroll

Fix search scroll
This commit is contained in:
mergify[bot] 2020-10-22 22:45:54 +00:00 committed by GitHub
commit c2d8f2b438
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 36 deletions

View File

@ -178,16 +178,7 @@ viewLogin model =
viewHome : Model -> Html Msg viewHome : Model -> Html Msg
viewHome model = viewHome model =
let Html.map HomeMsg (Page.Home.View.view model.flags model.uiSettings model.homeModel)
mid =
case model.page of
HomePage ->
Util.Maybe.fromString model.itemDetailModel.detail.item.id
_ ->
Nothing
in
Html.map HomeMsg (Page.Home.View.view mid model.flags model.uiSettings model.homeModel)
menuEntry : Model -> Page -> List (Html Msg) -> Html Msg menuEntry : Model -> Page -> List (Html Msg) -> Html Msg

View File

@ -89,7 +89,7 @@ type Msg
| SearchMenuMsg Comp.SearchMenu.Msg | SearchMenuMsg Comp.SearchMenu.Msg
| ResetSearch | ResetSearch
| ItemCardListMsg Comp.ItemCardList.Msg | ItemCardListMsg Comp.ItemCardList.Msg
| ItemSearchResp (Result Http.Error ItemLightList) | ItemSearchResp Bool (Result Http.Error ItemLightList)
| ItemSearchAddResp (Result Http.Error ItemLightList) | ItemSearchAddResp (Result Http.Error ItemLightList)
| DoSearch | DoSearch
| ToggleSearchMenu | ToggleSearchMenu
@ -136,21 +136,21 @@ itemNav id model =
} }
doSearchCmd : Flags -> UiSettings -> Int -> Model -> Cmd Msg doSearchCmd : Flags -> UiSettings -> Int -> Bool -> Model -> Cmd Msg
doSearchCmd flags settings offset model = doSearchCmd flags settings offset scroll model =
case model.searchType of case model.searchType of
BasicSearch -> BasicSearch ->
doSearchDefaultCmd flags settings offset model doSearchDefaultCmd flags settings offset scroll model
ContentSearch -> ContentSearch ->
doSearchDefaultCmd flags settings offset model doSearchDefaultCmd flags settings offset scroll model
ContentOnlySearch -> ContentOnlySearch ->
doSearchIndexCmd flags settings offset model doSearchIndexCmd flags settings offset scroll model
doSearchDefaultCmd : Flags -> UiSettings -> Int -> Model -> Cmd Msg doSearchDefaultCmd : Flags -> UiSettings -> Int -> Bool -> Model -> Cmd Msg
doSearchDefaultCmd flags settings offset model = doSearchDefaultCmd flags settings offset scroll model =
let let
smask = smask =
Comp.SearchMenu.getItemSearch model.searchMenuModel Comp.SearchMenu.getItemSearch model.searchMenuModel
@ -162,14 +162,14 @@ doSearchDefaultCmd flags settings offset model =
} }
in in
if offset == 0 then if offset == 0 then
Api.itemSearch flags mask ItemSearchResp Api.itemSearch flags mask (ItemSearchResp scroll)
else else
Api.itemSearch flags mask ItemSearchAddResp Api.itemSearch flags mask ItemSearchAddResp
doSearchIndexCmd : Flags -> UiSettings -> Int -> Model -> Cmd Msg doSearchIndexCmd : Flags -> UiSettings -> Int -> Bool -> Model -> Cmd Msg
doSearchIndexCmd flags settings offset model = doSearchIndexCmd flags settings offset scroll model =
case model.contentOnlySearch of case model.contentOnlySearch of
Just q -> Just q ->
let let
@ -180,7 +180,7 @@ doSearchIndexCmd flags settings offset model =
} }
in in
if offset == 0 then if offset == 0 then
Api.itemIndexSearch flags mask ItemSearchResp Api.itemIndexSearch flags mask (ItemSearchResp scroll)
else else
Api.itemIndexSearch flags mask ItemSearchAddResp Api.itemIndexSearch flags mask ItemSearchAddResp
@ -195,7 +195,7 @@ doSearchIndexCmd flags settings offset model =
mask = mask =
{ emptyMask | limit = settings.itemSearchPageSize } { emptyMask | limit = settings.itemSearchPageSize }
in in
Api.itemSearch flags mask ItemSearchResp Api.itemSearch flags mask (ItemSearchResp scroll)
resultsBelowLimit : UiSettings -> Model -> Bool resultsBelowLimit : UiSettings -> Model -> Bool

View File

@ -26,7 +26,7 @@ update mId key flags settings msg model =
Init -> Init ->
Util.Update.andThen2 Util.Update.andThen2
[ update mId key flags settings (SearchMenuMsg Comp.SearchMenu.Init) [ update mId key flags settings (SearchMenuMsg Comp.SearchMenu.Init)
, doSearch flags settings , doSearch flags settings True
] ]
model model
@ -61,7 +61,7 @@ update mId key flags settings msg model =
( m2, c2, s2 ) = ( m2, c2, s2 ) =
if nextState.stateChange && not model.searchInProgress then if nextState.stateChange && not model.searchInProgress then
doSearch flags settings newModel doSearch flags settings False newModel
else else
withSub ( newModel, Cmd.none ) withSub ( newModel, Cmd.none )
@ -91,7 +91,7 @@ update mId key flags settings msg model =
, Cmd.batch [ Cmd.map ItemCardListMsg result.cmd ] , Cmd.batch [ Cmd.map ItemCardListMsg result.cmd ]
) )
ItemSearchResp (Ok list) -> ItemSearchResp scroll (Ok list) ->
let let
noff = noff =
settings.itemSearchPageSize settings.itemSearchPageSize
@ -105,7 +105,11 @@ update mId key flags settings msg model =
in in
Util.Update.andThen2 Util.Update.andThen2
[ update mId key flags settings (ItemCardListMsg (Comp.ItemCardList.SetResults list)) [ update mId key flags settings (ItemCardListMsg (Comp.ItemCardList.SetResults list))
, scrollToCard mId , if scroll then
scrollToCard mId
else
\next -> ( next, Cmd.none, Sub.none )
] ]
m m
@ -124,7 +128,6 @@ update mId key flags settings msg model =
in in
Util.Update.andThen2 Util.Update.andThen2
[ update mId key flags settings (ItemCardListMsg (Comp.ItemCardList.AddResults list)) [ update mId key flags settings (ItemCardListMsg (Comp.ItemCardList.AddResults list))
, scrollToCard mId
] ]
m m
@ -136,7 +139,7 @@ update mId key flags settings msg model =
, Cmd.none , Cmd.none
) )
ItemSearchResp (Err _) -> ItemSearchResp _ (Err _) ->
withSub withSub
( { model ( { model
| searchInProgress = False | searchInProgress = False
@ -153,7 +156,7 @@ update mId key flags settings msg model =
withSub ( model, Cmd.none ) withSub ( model, Cmd.none )
else else
doSearch flags settings nm doSearch flags settings False nm
ToggleSearchMenu -> ToggleSearchMenu ->
withSub withSub
@ -272,8 +275,8 @@ scrollToCard mId model =
( model, Cmd.none, Sub.none ) ( model, Cmd.none, Sub.none )
doSearch : Flags -> UiSettings -> Model -> ( Model, Cmd Msg, Sub Msg ) doSearch : Flags -> UiSettings -> Bool -> Model -> ( Model, Cmd Msg, Sub Msg )
doSearch flags settings model = doSearch flags settings scroll model =
let let
stype = stype =
if if
@ -289,7 +292,7 @@ doSearch flags settings model =
{ model | searchType = stype } { model | searchType = stype }
searchCmd = searchCmd =
doSearchCmd flags settings 0 model_ doSearchCmd flags settings 0 scroll model_
( newThrottle, cmd ) = ( newThrottle, cmd ) =
Throttle.try searchCmd model.throttle Throttle.try searchCmd model.throttle
@ -308,7 +311,7 @@ doSearchMore : Flags -> UiSettings -> Model -> ( Model, Cmd Msg )
doSearchMore flags settings model = doSearchMore flags settings model =
let let
cmd = cmd =
doSearchCmd flags settings model.searchOffset model doSearchCmd flags settings model.searchOffset False model
in in
( { model | moreInProgress = True } ( { model | moreInProgress = True }
, cmd , cmd

View File

@ -14,8 +14,8 @@ import Page.Home.Data exposing (..)
import Util.Html import Util.Html
view : Maybe String -> Flags -> UiSettings -> Model -> Html Msg view : Flags -> UiSettings -> Model -> Html Msg
view current flags settings model = view flags settings model =
div [ class "home-page ui padded grid" ] div [ class "home-page ui padded grid" ]
[ div [ div
[ classList [ classList