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

@ -1,6 +1,7 @@
module Page.ItemDetail.Data exposing (Model, Msg(..), emptyModel)
import Api.Model.ItemDetail exposing (ItemDetail)
import Browser.Dom as Dom
import Comp.ItemDetail
import Comp.ItemDetail.Update
import Http
@ -21,3 +22,4 @@ type Msg
= Init String
| ItemDetailMsg Comp.ItemDetail.Update.Msg
| ItemResp (Result Http.Error ItemDetail)
| ScrollResult (Result Dom.Error ())

View File

@ -6,7 +6,8 @@ import Comp.ItemDetail
import Comp.ItemDetail.Update
import Data.Flags exposing (Flags)
import Page.ItemDetail.Data exposing (Model, Msg(..))
import Ports
import Scroll
import Task
update : Nav.Key -> Flags -> Maybe String -> Msg -> Model -> ( Model, Cmd Msg, Sub Msg )
@ -16,12 +17,15 @@ update key flags next msg model =
let
( lm, lc, ls ) =
Comp.ItemDetail.update key flags next Comp.ItemDetail.Update.Init model.detail
task =
Scroll.scroll "main-content" 0 0 0 0
in
( { model | detail = lm }
, Cmd.batch
[ Api.itemDetail flags id ItemResp
, Cmd.map ItemDetailMsg lc
, Ports.scrollToTop ()
, Task.attempt ScrollResult task
]
, Sub.map ItemDetailMsg ls
)
@ -45,3 +49,6 @@ update key flags next msg model =
ItemResp (Err _) ->
( model, Cmd.none, Sub.none )
ScrollResult _ ->
( model, Cmd.none, Sub.none )