Skip to content

Commit

Permalink
get heights
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHicks committed Feb 17, 2020
1 parent c233bcc commit 1655e5d
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/Main.elm
Expand Up @@ -25,6 +25,7 @@ type Msg
| MouseUp
| MouseMove Float
| AttachmentsMoved (List ( Int, Float ))
| GotCommentHeights (List ( Int, Float ))


init : () -> ( Model, Cmd Msg )
Expand Down Expand Up @@ -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)
]
)


Expand Down Expand Up @@ -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 =
Expand All @@ -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"
Expand Down

0 comments on commit 1655e5d

Please sign in to comment.