web: behaviour: fix scroll to bottom
`Browser.Dom.getElement` seems to give incorrect information for the
scene of the element (gives the entire browser scene, rather than of the
scrollable element - see https://github.com/elm/browser/issues/86). This
results in ScrollDirection.ToBottom not working properly.
@@ -8,7 +8,7 @@ port module Message.Effects exposing
)
import Base64
-import Browser.Dom exposing (Element, getElement, getViewport, setViewportOf)
+import Browser.Dom exposing (Element, getElement, getViewport, getViewportOf, setViewportOf)
import Browser.Navigation as Navigation
import Concourse
import Concourse.BuildStatus exposing (BuildStatus)
@@ -512,12 +512,35 @@ scrollCoords srcId idOfThingToScroll getX getY =
Task.sequence [ getElement srcId, getElement idOfThingToScroll ]
|> Task.andThen
(\elems ->
+ getViewportOf idOfThingToScroll
+ |> Task.andThen
+ (\parentViewport ->
+ Task.succeed
+ { elems = elems
+ , parentViewport = parentViewport
+ }
+ )
+ )
+ |> Task.andThen
+ (\{ elems, parentViewport } ->
case elems of
[ srcInfo, parentInfo ] ->
+ let
+ info =
+ { srcElem = srcInfo
+
+ -- https://github.com/elm/browser/issues/86
+ , parentElem =
+ { parentInfo
+ | viewport = parentViewport.viewport
+ , scene = parentViewport.scene
+ }
+ }
+ in
setViewportOf
idOfThingToScroll
- (getX { srcElem = srcInfo, parentElem = parentInfo })
- (getY { srcElem = srcInfo, parentElem = parentInfo })
+ (getX info)
+ (getY info)
_ ->
Task.fail <|
