{"action":"created","comment":{"url":"https://api.github.com/repos/gfontenot/swole-web/pulls/comments/170461297","pull_request_review_id":99150753,"id":170461297,"diff_hunk":"@@ -0,0 +1,112 @@\n+module Swole.Components.MovementInput exposing\n+    ( Msg\n+    , Model\n+    , view\n+    , update\n+    )\n+\n+import Html exposing (Html, program, div, input, text, button)\n+import Html.Attributes exposing (placeholder, type_, value, id)\n+import Html.Events exposing (onClick, onInput)\n+import Task\n+import Dom exposing (focus)\n+import List.Extra as List\n+\n+import Helpers.List as List\n+import Helpers.Events exposing (onDeleteWhen)\n+import Swole.Types.Movement exposing (Movement)\n+\n+type alias Movements = List (Int, Movement)\n+type alias Model = Movements\n+\n+type Msg\n+    = NoOp\n+    | MovementChanged (Int, Movement)\n+    | AddMovement\n+    | DeleteMovement Int\n+\n+view : Movements -> Html Msg\n+view movements =\n+    div []\n+        (movementFields movements)\n+\n+update : Msg -> Movements -> (Movements, Cmd Msg)\n+update msg movements =\n+    case msg of\n+        NoOp ->\n+            (movements, Cmd.none)\n+\n+        MovementChanged (idx, m) ->\n+            let\n+                (newIdx, newMovements) = splitMovements (idx, m)\n+                (before, after) = movementsAround idx movements\n+                allMovements = before ++ newMovements ++ after\n+            in\n+                (List.enumerated allMovements, updateFocus newIdx)\n+\n+        AddMovement ->\n+            let\n+                rawMovements = List.map Tuple.second movements\n+                idx = List.length rawMovements\n+            in\n+                (List.enumerated <| rawMovements ++ [\"\"], updateFocus idx)\n+\n+        DeleteMovement idx ->\n+            let\n+                newMovements\n+                    = movements\n+                    |> List.map Tuple.second\n+                    |> List.removeAt idx\n+\n+                newIdx = max 0 (idx - 1)\n+            in\n+               (List.enumerated newMovements, updateFocus newIdx)\n+\n+movementsAround : Int -> Movements -> (List Movement, List Movement)\n+movementsAround idx movements\n+    = movements\n+    |> List.map Tuple.second\n+    |> List.splitAt idx\n+    |> Tuple.mapSecond (List.drop 1)\n+\n+updateFocus : Int -> Cmd Msg\n+updateFocus idx =\n+    let\n+        checkFocus : Result Dom.Error () -> Msg\n+        checkFocus result = case result of\n+            Ok _ -> NoOp\n+            Err _ -> NoOp\n+    in\n+        Task.attempt checkFocus (Dom.focus <| \"movement-\" ++ toString idx)\n+\n+movementFields : Movements -> List (Html Msg)\n+movementFields movements = case movements of\n+    [] -> [movementField (0, \"\")]\n+    ms ->\n+        let fields = List.intersperse plusLabel (List.map movementField ms)\n+        in\n+           fields ++ [plusButton]\n+\n+plusLabel : Html Msg","path":"elm/Swole/Components/MovementInput.elm","position":90,"original_position":90,"commit_id":"95777c832dd8399dc61dd9059d66558e5129b246","original_commit_id":"95777c832dd8399dc61dd9059d66558e5129b246","user":{"login":"joshuaclayton","id":1574,"avatar_url":"https://avatars0.githubusercontent.com/u/1574?v=4","gravatar_id":"","url":"https://api.github.com/users/joshuaclayton","html_url":"https://github.com/joshuaclayton","followers_url":"https://api.github.com/users/joshuaclayton/followers","following_url":"https://api.github.com/users/joshuaclayton/following{/other_user}","gists_url":"https://api.github.com/users/joshuaclayton/gists{/gist_id}","starred_url":"https://api.github.com/users/joshuaclayton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joshuaclayton/subscriptions","organizations_url":"https://api.github.com/users/joshuaclayton/orgs","repos_url":"https://api.github.com/users/joshuaclayton/repos","events_url":"https://api.github.com/users/joshuaclayton/events{/privacy}","received_events_url":"https://api.github.com/users/joshuaclayton/received_events","type":"User","site_admin":false},"body":"For markup that doesn't actually trigger a `Msg`, I'll use the more polymorphic `Msg a` to convey that. Thoughts?","created_at":"2018-02-25T18:11:42Z","updated_at":"2018-02-25T18:31:58Z","html_url":"https://github.com/gfontenot/swole-web/pull/14#discussion_r170461297","pull_request_url":"https://api.github.com/repos/gfontenot/swole-web/pulls/14","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/gfontenot/swole-web/pulls/comments/170461297"},"html":{"href":"https://github.com/gfontenot/swole-web/pull/14#discussion_r170461297"},"pull_request":{"href":"https://api.github.com/repos/gfontenot/swole-web/pulls/14"}}},"pull_request":{"url":"https://api.github.com/repos/gfontenot/swole-web/pulls/14","id":171238540,"html_url":"https://github.com/gfontenot/swole-web/pull/14","diff_url":"https://github.com/gfontenot/swole-web/pull/14.diff","patch_url":"https://github.com/gfontenot/swole-web/pull/14.patch","issue_url":"https://api.github.com/repos/gfontenot/swole-web/issues/14","number":14,"state":"open","locked":false,"title":"Introduce new MovementInput component","user":{"login":"gfontenot","id":124499,"avatar_url":"https://avatars3.githubusercontent.com/u/124499?v=4","gravatar_id":"","url":"https://api.github.com/users/gfontenot","html_url":"https://github.com/gfontenot","followers_url":"https://api.github.com/users/gfontenot/followers","following_url":"https://api.github.com/users/gfontenot/following{/other_user}","gists_url":"https://api.github.com/users/gfontenot/gists{/gist_id}","starred_url":"https://api.github.com/users/gfontenot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gfontenot/subscriptions","organizations_url":"https://api.github.com/users/gfontenot/orgs","repos_url":"https://api.github.com/users/gfontenot/repos","events_url":"https://api.github.com/users/gfontenot/events{/privacy}","received_events_url":"https://api.github.com/users/gfontenot/received_events","type":"User","site_admin":false},"body":"This component replaces the old single-text-field approach for user input in\r\nfavor of dynamically adding/removing fields as the user types. This behavior\r\nis _much_ nicer, and means we'll be able to do more things like\r\nauto-completion easier than we otherwise would have.\r\n\r\n![movementinput](https://user-images.githubusercontent.com/124499/36643950-403d4468-1a18-11e8-8186-57bea323ed40.gif)\r\n","created_at":"2018-02-25T16:35:50Z","updated_at":"2018-02-25T18:31:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cf7c9f257842ed8c8c94c0c3b9795c5519cc3778","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/gfontenot/swole-web/pulls/14/commits","review_comments_url":"https://api.github.com/repos/gfontenot/swole-web/pulls/14/comments","review_comment_url":"https://api.github.com/repos/gfontenot/swole-web/pulls/comments{/number}","comments_url":"https://api.github.com/repos/gfontenot/swole-web/issues/14/comments","statuses_url":"https://api.github.com/repos/gfontenot/swole-web/statuses/95777c832dd8399dc61dd9059d66558e5129b246","head":{"label":"gfontenot:gfontenot/movement-interaction","ref":"gfontenot/movement-interaction","sha":"95777c832dd8399dc61dd9059d66558e5129b246","user":{"login":"gfontenot","id":124499,"avatar_url":"https://avatars3.githubusercontent.com/u/124499?v=4","gravatar_id":"","url":"https://api.github.com/users/gfontenot","html_url":"https://github.com/gfontenot","followers_url":"https://api.github.com/users/gfontenot/followers","following_url":"https://api.github.com/users/gfontenot/following{/other_user}","gists_url":"https://api.github.com/users/gfontenot/gists{/gist_id}","starred_url":"https://api.github.com/users/gfontenot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gfontenot/subscriptions","organizations_url":"https://api.github.com/users/gfontenot/orgs","repos_url":"https://api.github.com/users/gfontenot/repos","events_url":"https://api.github.com/users/gfontenot/events{/privacy}","received_events_url":"https://api.github.com/users/gfontenot/received_events","type":"User","site_admin":false},"repo":{"id":83735921,"name":"swole-web","full_name":"gfontenot/swole-web","owner":{"login":"gfontenot","id":124499,"avatar_url":"https://avatars3.githubusercontent.com/u/124499?v=4","gravatar_id":"","url":"https://api.github.com/users/gfontenot","html_url":"https://github.com/gfontenot","followers_url":"https://api.github.com/users/gfontenot/followers","following_url":"https://api.github.com/users/gfontenot/following{/other_user}","gists_url":"https://api.github.com/users/gfontenot/gists{/gist_id}","starred_url":"https://api.github.com/users/gfontenot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gfontenot/subscriptions","organizations_url":"https://api.github.com/users/gfontenot/orgs","repos_url":"https://api.github.com/users/gfontenot/repos","events_url":"https://api.github.com/users/gfontenot/events{/privacy}","received_events_url":"https://api.github.com/users/gfontenot/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gfontenot/swole-web","description":null,"fork":false,"url":"https://api.github.com/repos/gfontenot/swole-web","forks_url":"https://api.github.com/repos/gfontenot/swole-web/forks","keys_url":"https://api.github.com/repos/gfontenot/swole-web/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gfontenot/swole-web/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gfontenot/swole-web/teams","hooks_url":"https://api.github.com/repos/gfontenot/swole-web/hooks","issue_events_url":"https://api.github.com/repos/gfontenot/swole-web/issues/events{/number}","events_url":"https://api.github.com/repos/gfontenot/swole-web/events","assignees_url":"https://api.github.com/repos/gfontenot/swole-web/assignees{/user}","branches_url":"https://api.github.com/repos/gfontenot/swole-web/branches{/branch}","tags_url":"https://api.github.com/repos/gfontenot/swole-web/tags","blobs_url":"https://api.github.com/repos/gfontenot/swole-web/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gfontenot/swole-web/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gfontenot/swole-web/git/refs{/sha}","trees_url":"https://api.github.com/repos/gfontenot/swole-web/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gfontenot/swole-web/statuses/{sha}","languages_url":"https://api.github.com/repos/gfontenot/swole-web/languages","stargazers_url":"https://api.github.com/repos/gfontenot/swole-web/stargazers","contributors_url":"https://api.github.com/repos/gfontenot/swole-web/contributors","subscribers_url":"https://api.github.com/repos/gfontenot/swole-web/subscribers","subscription_url":"https://api.github.com/repos/gfontenot/swole-web/subscription","commits_url":"https://api.github.com/repos/gfontenot/swole-web/commits{/sha}","git_commits_url":"https://api.github.com/repos/gfontenot/swole-web/git/commits{/sha}","comments_url":"https://api.github.com/repos/gfontenot/swole-web/comments{/number}","issue_comment_url":"https://api.github.com/repos/gfontenot/swole-web/issues/comments{/number}","contents_url":"https://api.github.com/repos/gfontenot/swole-web/contents/{+path}","compare_url":"https://api.github.com/repos/gfontenot/swole-web/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gfontenot/swole-web/merges","archive_url":"https://api.github.com/repos/gfontenot/swole-web/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gfontenot/swole-web/downloads","issues_url":"https://api.github.com/repos/gfontenot/swole-web/issues{/number}","pulls_url":"https://api.github.com/repos/gfontenot/swole-web/pulls{/number}","milestones_url":"https://api.github.com/repos/gfontenot/swole-web/milestones{/number}","notifications_url":"https://api.github.com/repos/gfontenot/swole-web/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gfontenot/swole-web/labels{/name}","releases_url":"https://api.github.com/repos/gfontenot/swole-web/releases{/id}","deployments_url":"https://api.github.com/repos/gfontenot/swole-web/deployments","created_at":"2017-03-02T23:37:10Z","updated_at":"2018-02-14T02:27:30Z","pushed_at":"2018-02-25T17:52:45Z","git_url":"git://github.com/gfontenot/swole-web.git","ssh_url":"git@github.com:gfontenot/swole-web.git","clone_url":"https://github.com/gfontenot/swole-web.git","svn_url":"https://github.com/gfontenot/swole-web","homepage":null,"size":87,"stargazers_count":2,"watchers_count":2,"language":"Haskell","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":2,"default_branch":"master"}},"base":{"label":"gfontenot:master","ref":"master","sha":"23e0efe8def55d81c3f6184d5bfabf4d589c4d49","user":{"login":"gfontenot","id":124499,"avatar_url":"https://avatars3.githubusercontent.com/u/124499?v=4","gravatar_id":"","url":"https://api.github.com/users/gfontenot","html_url":"https://github.com/gfontenot","followers_url":"https://api.github.com/users/gfontenot/followers","following_url":"https://api.github.com/users/gfontenot/following{/other_user}","gists_url":"https://api.github.com/users/gfontenot/gists{/gist_id}","starred_url":"https://api.github.com/users/gfontenot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gfontenot/subscriptions","organizations_url":"https://api.github.com/users/gfontenot/orgs","repos_url":"https://api.github.com/users/gfontenot/repos","events_url":"https://api.github.com/users/gfontenot/events{/privacy}","received_events_url":"https://api.github.com/users/gfontenot/received_events","type":"User","site_admin":false},"repo":{"id":83735921,"name":"swole-web","full_name":"gfontenot/swole-web","owner":{"login":"gfontenot","id":124499,"avatar_url":"https://avatars3.githubusercontent.com/u/124499?v=4","gravatar_id":"","url":"https://api.github.com/users/gfontenot","html_url":"https://github.com/gfontenot","followers_url":"https://api.github.com/users/gfontenot/followers","following_url":"https://api.github.com/users/gfontenot/following{/other_user}","gists_url":"https://api.github.com/users/gfontenot/gists{/gist_id}","starred_url":"https://api.github.com/users/gfontenot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gfontenot/subscriptions","organizations_url":"https://api.github.com/users/gfontenot/orgs","repos_url":"https://api.github.com/users/gfontenot/repos","events_url":"https://api.github.com/users/gfontenot/events{/privacy}","received_events_url":"https://api.github.com/users/gfontenot/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gfontenot/swole-web","description":null,"fork":false,"url":"https://api.github.com/repos/gfontenot/swole-web","forks_url":"https://api.github.com/repos/gfontenot/swole-web/forks","keys_url":"https://api.github.com/repos/gfontenot/swole-web/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gfontenot/swole-web/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gfontenot/swole-web/teams","hooks_url":"https://api.github.com/repos/gfontenot/swole-web/hooks","issue_events_url":"https://api.github.com/repos/gfontenot/swole-web/issues/events{/number}","events_url":"https://api.github.com/repos/gfontenot/swole-web/events","assignees_url":"https://api.github.com/repos/gfontenot/swole-web/assignees{/user}","branches_url":"https://api.github.com/repos/gfontenot/swole-web/branches{/branch}","tags_url":"https://api.github.com/repos/gfontenot/swole-web/tags","blobs_url":"https://api.github.com/repos/gfontenot/swole-web/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gfontenot/swole-web/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gfontenot/swole-web/git/refs{/sha}","trees_url":"https://api.github.com/repos/gfontenot/swole-web/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gfontenot/swole-web/statuses/{sha}","languages_url":"https://api.github.com/repos/gfontenot/swole-web/languages","stargazers_url":"https://api.github.com/repos/gfontenot/swole-web/stargazers","contributors_url":"https://api.github.com/repos/gfontenot/swole-web/contributors","subscribers_url":"https://api.github.com/repos/gfontenot/swole-web/subscribers","subscription_url":"https://api.github.com/repos/gfontenot/swole-web/subscription","commits_url":"https://api.github.com/repos/gfontenot/swole-web/commits{/sha}","git_commits_url":"https://api.github.com/repos/gfontenot/swole-web/git/commits{/sha}","comments_url":"https://api.github.com/repos/gfontenot/swole-web/comments{/number}","issue_comment_url":"https://api.github.com/repos/gfontenot/swole-web/issues/comments{/number}","contents_url":"https://api.github.com/repos/gfontenot/swole-web/contents/{+path}","compare_url":"https://api.github.com/repos/gfontenot/swole-web/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gfontenot/swole-web/merges","archive_url":"https://api.github.com/repos/gfontenot/swole-web/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gfontenot/swole-web/downloads","issues_url":"https://api.github.com/repos/gfontenot/swole-web/issues{/number}","pulls_url":"https://api.github.com/repos/gfontenot/swole-web/pulls{/number}","milestones_url":"https://api.github.com/repos/gfontenot/swole-web/milestones{/number}","notifications_url":"https://api.github.com/repos/gfontenot/swole-web/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gfontenot/swole-web/labels{/name}","releases_url":"https://api.github.com/repos/gfontenot/swole-web/releases{/id}","deployments_url":"https://api.github.com/repos/gfontenot/swole-web/deployments","created_at":"2017-03-02T23:37:10Z","updated_at":"2018-02-14T02:27:30Z","pushed_at":"2018-02-25T17:52:45Z","git_url":"git://github.com/gfontenot/swole-web.git","ssh_url":"git@github.com:gfontenot/swole-web.git","clone_url":"https://github.com/gfontenot/swole-web.git","svn_url":"https://github.com/gfontenot/swole-web","homepage":null,"size":87,"stargazers_count":2,"watchers_count":2,"language":"Haskell","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/gfontenot/swole-web/pulls/14"},"html":{"href":"https://github.com/gfontenot/swole-web/pull/14"},"issue":{"href":"https://api.github.com/repos/gfontenot/swole-web/issues/14"},"comments":{"href":"https://api.github.com/repos/gfontenot/swole-web/issues/14/comments"},"review_comments":{"href":"https://api.github.com/repos/gfontenot/swole-web/pulls/14/comments"},"review_comment":{"href":"https://api.github.com/repos/gfontenot/swole-web/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/gfontenot/swole-web/pulls/14/commits"},"statuses":{"href":"https://api.github.com/repos/gfontenot/swole-web/statuses/95777c832dd8399dc61dd9059d66558e5129b246"}},"author_association":"OWNER"}}
{"actor":{"display_login":"joshuaclayton"}}