From 1655e5df269c3bd5945da77fd2840c962afef4a9 Mon Sep 17 00:00:00 2001 From: Brian Hicks Date: Mon, 17 Feb 2020 17:10:22 -0600 Subject: [PATCH] get heights --- src/Main.elm | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/Main.elm b/src/Main.elm index 6e28173..ca55706 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -25,6 +25,7 @@ type Msg | MouseUp | MouseMove Float | AttachmentsMoved (List ( Int, Float )) + | GotCommentHeights (List ( Int, Float )) init : () -> ( Model, Cmd Msg ) @@ -52,7 +53,10 @@ init _ = |> Dict.fromList , dragging = Nothing } - , findNewAttachmentTops (List.map .id attachments) + , Cmd.batch + [ findNewAttachmentTops (List.map .id attachments) + , findCommentHeights (List.map .id comments) + ] ) @@ -84,6 +88,13 @@ update msg model = AttachmentsMoved tops -> ( model, Cmd.none ) + GotCommentHeights heights -> + let + _ = + Debug.log "heights" heights + in + ( model, Cmd.none ) + findNewAttachmentTopsTask : List Int -> Task Never (List ( Int, Float )) findNewAttachmentTopsTask ids = @@ -104,6 +115,25 @@ findNewAttachmentTops ids = Task.perform AttachmentsMoved (findNewAttachmentTopsTask ids) +findCommentHeightsTask : List Int -> Task Never (List ( Int, Float )) +findCommentHeightsTask ids = + -- TODO: this may need Process.sleep 0 to be accurate in all cases + ids + |> List.map + (\id -> + Dom.getElement ("comment-" ++ String.fromInt id) + |> Task.map (\{ element } -> Just ( id, element.height )) + |> Task.onError (\_ -> Task.succeed Nothing) + ) + |> Task.sequence + |> Task.map (List.filterMap identity) + + +findCommentHeights : List Int -> Cmd Msg +findCommentHeights ids = + Task.perform GotCommentHeights (findCommentHeightsTask ids) + + view : Model -> Browser.Document Msg view model = { title = "Comment Constraint Experiment"