Replace js code with proper elm using elm-scroll package

This commit is contained in:
Eike Kettner
2020-09-14 23:35:21 +02:00
parent 3852c69da1
commit ad110b2a05
8 changed files with 31 additions and 47 deletions

View File

@@ -13,6 +13,7 @@ module Page.Home.Data exposing
import Api
import Api.Model.ItemLightList exposing (ItemLightList)
import Api.Model.ItemSearch
import Browser.Dom as Dom
import Comp.FixedDropdown
import Comp.ItemCardList
import Comp.SearchMenu
@@ -95,6 +96,7 @@ type Msg
| SearchTypeMsg (Comp.FixedDropdown.Msg SearchType)
| KeyUpMsg (Maybe KeyCode)
| SetContentOnly String
| ScrollResult (Result Dom.Error ())
type SearchType

View File

@@ -8,7 +8,8 @@ import Data.Flags exposing (Flags)
import Data.UiSettings exposing (UiSettings)
import Page exposing (Page(..))
import Page.Home.Data exposing (..)
import Ports
import Scroll
import Task
import Throttle
import Time
import Util.Html exposing (KeyCode(..))
@@ -221,6 +222,9 @@ update mId key flags settings msg model =
KeyUpMsg _ ->
withSub ( model, Cmd.none )
ScrollResult res ->
withSub ( model, Cmd.none )
--- Helpers
@@ -228,9 +232,13 @@ update mId key flags settings msg model =
scrollToCard : Maybe String -> Model -> ( Model, Cmd Msg, Sub Msg )
scrollToCard mId model =
let
scroll id =
Scroll.scroll id 0.5 0.5 0.5 0.5
in
case mId of
Just id ->
( model, Ports.scrollToElem ( id, 0 ), Sub.none )
( model, Task.attempt ScrollResult (scroll id), Sub.none )
Nothing ->
( model, Cmd.none, Sub.none )