{"action":"created","comment":{"url":"https://api.github.com/repos/kucenko/practics/pulls/comments/214137393","pull_request_review_id":151127645,"id":214137393,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxNDEzNzM5Mw==","diff_hunk":"@@ -4,43 +4,101 @@ import './App.css';\n \n import {connectWs, addWsListener, removeWsListener} from \"./utils/ws\";\n \n-const {emit} = connectWs('ws://192.168.110.49:3000');\n+const { emit, connectionOpened } = connectWs('ws://192.168.110.49:3000');\n+let isConnectionOpened = false;\n \n-addWsListener(\"connected_new_user\", (data) => {\n-  console.log(data);\n+connectionOpened.then(() => {\n+    isConnectionOpened = true;\n })\n \n-addWsListener(\"disconnected_user\", (data) => {\n-  console.log(data);\n-})\n+class App extends Component {\n+    state = {\n+        messageLabel: 'Connecting...',\n+        message: '',\n+        messages: []\n+    }\n \n-addWsListener(\"message\", (data) => {\n-  console.log(data);\n-});\n+    componentDidMount() {\n+        if (isConnectionOpened) {\n+            this.changeMessageLabel('Enter name: ');\n+        } else {\n+            connectionOpened.then(() => {\n+                this.changeMessageLabel('Enter name: ');\n+            });\n+        }\n \n-setTimeout(() => {\n-  emit(`User: ${+new Date}`)\n-}, 1000)\n+        addWsListener(\"connected_new_user\", () => {\n+            this.changeMessageLabel('Enter message: ');\n+            this.changeMessage('');\n+        });\n \n-setTimeout(() => {\n-  emit(`Message: ${+new Date}`)\n-}, 3000)\n+        addWsListener(\"message\", (data) => {\n+            this.changeMessage('');\n+            this.changeMessages(data);\n+        });\n+    }\n \n+    changeMessageLabel(messageLabel) {\n+        this.setState({ messageLabel })\n+    }\n \n-class App extends Component {\n-  render() {\n-    return (\n-      <div className=\"App\">\n-        <header className=\"App-header\">\n-          <img src={logo} className=\"App-logo\" alt=\"logo\" />\n-          <h1 className=\"App-title\">Welcome to React</h1>\n-        </header>\n-        <p className=\"App-intro\">\n-          To get started, edit <code>src/App.js</code> and save to reload.\n-        </p>\n-      </div>\n-    );\n-  }\n+    changeMessages(message) {\n+        this.setState(({ messages }) => ({ messages: [...messages, message] }))\n+    }\n+\n+    changeMessage(message) {\n+        this.setState({ message })\n+    }\n+\n+    onSubmit(event) {\n+        event.preventDefault();\n+        emit(this.state.message);\n+    }\n+\n+    onMessageChange({ target: { value: message } }) {\n+        this.setState({ message })\n+    }\n+\n+    render() {\n+        const setAuthorColor = (color) => ({color})\n+\n+        return (\n+            <div className=\"chat container\">\n+                <div className=\"messages\">\n+                    {this.state.messages.map(messageObj => {\n+                        const dt = new Date(messageObj.time)\n+\n+                        return (\n+                            <div className=\"message row\">\n+                                <span style={setAuthorColor(messageObj.color)}>\n+                                    {messageObj.author}\n+                                </span>\n+                                @ {dt.getHours()} : {dt.getMinutes() < 10 ? ('0' + dt.getMinutes()) : dt.getMinutes()} ---- {messageObj.text}","path":"client/chat/src/App.js","position":102,"original_position":102,"commit_id":"724e796538257f03b05600575b071541763fe3ea","original_commit_id":"724e796538257f03b05600575b071541763fe3ea","user":{"login":"vparkhomenko","id":19910609,"node_id":"MDQ6VXNlcjE5OTEwNjA5","avatar_url":"https://avatars0.githubusercontent.com/u/19910609?v=4","gravatar_id":"","url":"https://api.github.com/users/vparkhomenko","html_url":"https://github.com/vparkhomenko","followers_url":"https://api.github.com/users/vparkhomenko/followers","following_url":"https://api.github.com/users/vparkhomenko/following{/other_user}","gists_url":"https://api.github.com/users/vparkhomenko/gists{/gist_id}","starred_url":"https://api.github.com/users/vparkhomenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vparkhomenko/subscriptions","organizations_url":"https://api.github.com/users/vparkhomenko/orgs","repos_url":"https://api.github.com/users/vparkhomenko/repos","events_url":"https://api.github.com/users/vparkhomenko/events{/privacy}","received_events_url":"https://api.github.com/users/vparkhomenko/received_events","type":"User","site_admin":false},"body":"сделай метод formatDate или formatText\r\nбудет принимать дату и объект сообщения, возвращать отформатированную строку","created_at":"2018-08-30T18:34:41Z","updated_at":"2018-08-30T18:34:42Z","html_url":"https://github.com/kucenko/practics/pull/1#discussion_r214137393","pull_request_url":"https://api.github.com/repos/kucenko/practics/pulls/1","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/kucenko/practics/pulls/comments/214137393"},"html":{"href":"https://github.com/kucenko/practics/pull/1#discussion_r214137393"},"pull_request":{"href":"https://api.github.com/repos/kucenko/practics/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/kucenko/practics/pulls/1","id":212092495,"node_id":"MDExOlB1bGxSZXF1ZXN0MjEyMDkyNDk1","html_url":"https://github.com/kucenko/practics/pull/1","diff_url":"https://github.com/kucenko/practics/pull/1.diff","patch_url":"https://github.com/kucenko/practics/pull/1.patch","issue_url":"https://api.github.com/repos/kucenko/practics/issues/1","number":1,"state":"open","locked":false,"title":"React chat","user":{"login":"Aleksei11","id":24891192,"node_id":"MDQ6VXNlcjI0ODkxMTky","avatar_url":"https://avatars0.githubusercontent.com/u/24891192?v=4","gravatar_id":"","url":"https://api.github.com/users/Aleksei11","html_url":"https://github.com/Aleksei11","followers_url":"https://api.github.com/users/Aleksei11/followers","following_url":"https://api.github.com/users/Aleksei11/following{/other_user}","gists_url":"https://api.github.com/users/Aleksei11/gists{/gist_id}","starred_url":"https://api.github.com/users/Aleksei11/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Aleksei11/subscriptions","organizations_url":"https://api.github.com/users/Aleksei11/orgs","repos_url":"https://api.github.com/users/Aleksei11/repos","events_url":"https://api.github.com/users/Aleksei11/events{/privacy}","received_events_url":"https://api.github.com/users/Aleksei11/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-08-30T14:07:38Z","updated_at":"2018-08-30T18:34:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d1e11c2acc07cc8d97f79e359af33cb19649c522","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/kucenko/practics/pulls/1/commits","review_comments_url":"https://api.github.com/repos/kucenko/practics/pulls/1/comments","review_comment_url":"https://api.github.com/repos/kucenko/practics/pulls/comments{/number}","comments_url":"https://api.github.com/repos/kucenko/practics/issues/1/comments","statuses_url":"https://api.github.com/repos/kucenko/practics/statuses/724e796538257f03b05600575b071541763fe3ea","head":{"label":"Aleksei7:master","ref":"master","sha":"724e796538257f03b05600575b071541763fe3ea","user":{"login":"Aleksei7","id":13983725,"node_id":"MDQ6VXNlcjEzOTgzNzI1","avatar_url":"https://avatars2.githubusercontent.com/u/13983725?v=4","gravatar_id":"","url":"https://api.github.com/users/Aleksei7","html_url":"https://github.com/Aleksei7","followers_url":"https://api.github.com/users/Aleksei7/followers","following_url":"https://api.github.com/users/Aleksei7/following{/other_user}","gists_url":"https://api.github.com/users/Aleksei7/gists{/gist_id}","starred_url":"https://api.github.com/users/Aleksei7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Aleksei7/subscriptions","organizations_url":"https://api.github.com/users/Aleksei7/orgs","repos_url":"https://api.github.com/users/Aleksei7/repos","events_url":"https://api.github.com/users/Aleksei7/events{/privacy}","received_events_url":"https://api.github.com/users/Aleksei7/received_events","type":"User","site_admin":false},"repo":{"id":146734556,"node_id":"MDEwOlJlcG9zaXRvcnkxNDY3MzQ1NTY=","name":"practics","full_name":"Aleksei7/practics","owner":{"login":"Aleksei7","id":13983725,"node_id":"MDQ6VXNlcjEzOTgzNzI1","avatar_url":"https://avatars2.githubusercontent.com/u/13983725?v=4","gravatar_id":"","url":"https://api.github.com/users/Aleksei7","html_url":"https://github.com/Aleksei7","followers_url":"https://api.github.com/users/Aleksei7/followers","following_url":"https://api.github.com/users/Aleksei7/following{/other_user}","gists_url":"https://api.github.com/users/Aleksei7/gists{/gist_id}","starred_url":"https://api.github.com/users/Aleksei7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Aleksei7/subscriptions","organizations_url":"https://api.github.com/users/Aleksei7/orgs","repos_url":"https://api.github.com/users/Aleksei7/repos","events_url":"https://api.github.com/users/Aleksei7/events{/privacy}","received_events_url":"https://api.github.com/users/Aleksei7/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Aleksei7/practics","description":null,"fork":true,"url":"https://api.github.com/repos/Aleksei7/practics","forks_url":"https://api.github.com/repos/Aleksei7/practics/forks","keys_url":"https://api.github.com/repos/Aleksei7/practics/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Aleksei7/practics/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Aleksei7/practics/teams","hooks_url":"https://api.github.com/repos/Aleksei7/practics/hooks","issue_events_url":"https://api.github.com/repos/Aleksei7/practics/issues/events{/number}","events_url":"https://api.github.com/repos/Aleksei7/practics/events","assignees_url":"https://api.github.com/repos/Aleksei7/practics/assignees{/user}","branches_url":"https://api.github.com/repos/Aleksei7/practics/branches{/branch}","tags_url":"https://api.github.com/repos/Aleksei7/practics/tags","blobs_url":"https://api.github.com/repos/Aleksei7/practics/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Aleksei7/practics/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Aleksei7/practics/git/refs{/sha}","trees_url":"https://api.github.com/repos/Aleksei7/practics/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Aleksei7/practics/statuses/{sha}","languages_url":"https://api.github.com/repos/Aleksei7/practics/languages","stargazers_url":"https://api.github.com/repos/Aleksei7/practics/stargazers","contributors_url":"https://api.github.com/repos/Aleksei7/practics/contributors","subscribers_url":"https://api.github.com/repos/Aleksei7/practics/subscribers","subscription_url":"https://api.github.com/repos/Aleksei7/practics/subscription","commits_url":"https://api.github.com/repos/Aleksei7/practics/commits{/sha}","git_commits_url":"https://api.github.com/repos/Aleksei7/practics/git/commits{/sha}","comments_url":"https://api.github.com/repos/Aleksei7/practics/comments{/number}","issue_comment_url":"https://api.github.com/repos/Aleksei7/practics/issues/comments{/number}","contents_url":"https://api.github.com/repos/Aleksei7/practics/contents/{+path}","compare_url":"https://api.github.com/repos/Aleksei7/practics/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Aleksei7/practics/merges","archive_url":"https://api.github.com/repos/Aleksei7/practics/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Aleksei7/practics/downloads","issues_url":"https://api.github.com/repos/Aleksei7/practics/issues{/number}","pulls_url":"https://api.github.com/repos/Aleksei7/practics/pulls{/number}","milestones_url":"https://api.github.com/repos/Aleksei7/practics/milestones{/number}","notifications_url":"https://api.github.com/repos/Aleksei7/practics/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Aleksei7/practics/labels{/name}","releases_url":"https://api.github.com/repos/Aleksei7/practics/releases{/id}","deployments_url":"https://api.github.com/repos/Aleksei7/practics/deployments","created_at":"2018-08-30T10:34:36Z","updated_at":"2018-08-30T14:02:56Z","pushed_at":"2018-08-30T14:02:55Z","git_url":"git://github.com/Aleksei7/practics.git","ssh_url":"git@github.com:Aleksei7/practics.git","clone_url":"https://github.com/Aleksei7/practics.git","svn_url":"https://github.com/Aleksei7/practics","homepage":null,"size":155,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"kucenko:master","ref":"master","sha":"ccb5fee6078924b5ee867e859f77e80cc31497c1","user":{"login":"kucenko","id":15870799,"node_id":"MDQ6VXNlcjE1ODcwNzk5","avatar_url":"https://avatars3.githubusercontent.com/u/15870799?v=4","gravatar_id":"","url":"https://api.github.com/users/kucenko","html_url":"https://github.com/kucenko","followers_url":"https://api.github.com/users/kucenko/followers","following_url":"https://api.github.com/users/kucenko/following{/other_user}","gists_url":"https://api.github.com/users/kucenko/gists{/gist_id}","starred_url":"https://api.github.com/users/kucenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kucenko/subscriptions","organizations_url":"https://api.github.com/users/kucenko/orgs","repos_url":"https://api.github.com/users/kucenko/repos","events_url":"https://api.github.com/users/kucenko/events{/privacy}","received_events_url":"https://api.github.com/users/kucenko/received_events","type":"User","site_admin":false},"repo":{"id":142979776,"node_id":"MDEwOlJlcG9zaXRvcnkxNDI5Nzk3NzY=","name":"practics","full_name":"kucenko/practics","owner":{"login":"kucenko","id":15870799,"node_id":"MDQ6VXNlcjE1ODcwNzk5","avatar_url":"https://avatars3.githubusercontent.com/u/15870799?v=4","gravatar_id":"","url":"https://api.github.com/users/kucenko","html_url":"https://github.com/kucenko","followers_url":"https://api.github.com/users/kucenko/followers","following_url":"https://api.github.com/users/kucenko/following{/other_user}","gists_url":"https://api.github.com/users/kucenko/gists{/gist_id}","starred_url":"https://api.github.com/users/kucenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kucenko/subscriptions","organizations_url":"https://api.github.com/users/kucenko/orgs","repos_url":"https://api.github.com/users/kucenko/repos","events_url":"https://api.github.com/users/kucenko/events{/privacy}","received_events_url":"https://api.github.com/users/kucenko/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kucenko/practics","description":null,"fork":false,"url":"https://api.github.com/repos/kucenko/practics","forks_url":"https://api.github.com/repos/kucenko/practics/forks","keys_url":"https://api.github.com/repos/kucenko/practics/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kucenko/practics/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kucenko/practics/teams","hooks_url":"https://api.github.com/repos/kucenko/practics/hooks","issue_events_url":"https://api.github.com/repos/kucenko/practics/issues/events{/number}","events_url":"https://api.github.com/repos/kucenko/practics/events","assignees_url":"https://api.github.com/repos/kucenko/practics/assignees{/user}","branches_url":"https://api.github.com/repos/kucenko/practics/branches{/branch}","tags_url":"https://api.github.com/repos/kucenko/practics/tags","blobs_url":"https://api.github.com/repos/kucenko/practics/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kucenko/practics/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kucenko/practics/git/refs{/sha}","trees_url":"https://api.github.com/repos/kucenko/practics/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kucenko/practics/statuses/{sha}","languages_url":"https://api.github.com/repos/kucenko/practics/languages","stargazers_url":"https://api.github.com/repos/kucenko/practics/stargazers","contributors_url":"https://api.github.com/repos/kucenko/practics/contributors","subscribers_url":"https://api.github.com/repos/kucenko/practics/subscribers","subscription_url":"https://api.github.com/repos/kucenko/practics/subscription","commits_url":"https://api.github.com/repos/kucenko/practics/commits{/sha}","git_commits_url":"https://api.github.com/repos/kucenko/practics/git/commits{/sha}","comments_url":"https://api.github.com/repos/kucenko/practics/comments{/number}","issue_comment_url":"https://api.github.com/repos/kucenko/practics/issues/comments{/number}","contents_url":"https://api.github.com/repos/kucenko/practics/contents/{+path}","compare_url":"https://api.github.com/repos/kucenko/practics/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kucenko/practics/merges","archive_url":"https://api.github.com/repos/kucenko/practics/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kucenko/practics/downloads","issues_url":"https://api.github.com/repos/kucenko/practics/issues{/number}","pulls_url":"https://api.github.com/repos/kucenko/practics/pulls{/number}","milestones_url":"https://api.github.com/repos/kucenko/practics/milestones{/number}","notifications_url":"https://api.github.com/repos/kucenko/practics/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kucenko/practics/labels{/name}","releases_url":"https://api.github.com/repos/kucenko/practics/releases{/id}","deployments_url":"https://api.github.com/repos/kucenko/practics/deployments","created_at":"2018-07-31T07:39:47Z","updated_at":"2018-08-01T18:37:16Z","pushed_at":"2018-08-30T14:07:38Z","git_url":"git://github.com/kucenko/practics.git","ssh_url":"git@github.com:kucenko/practics.git","clone_url":"https://github.com/kucenko/practics.git","svn_url":"https://github.com/kucenko/practics","homepage":null,"size":153,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/kucenko/practics/pulls/1"},"html":{"href":"https://github.com/kucenko/practics/pull/1"},"issue":{"href":"https://api.github.com/repos/kucenko/practics/issues/1"},"comments":{"href":"https://api.github.com/repos/kucenko/practics/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/kucenko/practics/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/kucenko/practics/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/kucenko/practics/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/kucenko/practics/statuses/724e796538257f03b05600575b071541763fe3ea"}},"author_association":"NONE"}}
{"actor":{"display_login":"vparkhomenko"}}