{"action":"created","comment":{"url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/pulls/comments/67133813","id":67133813,"diff_hunk":"@@ -57,8 +70,133 @@ var getReviewElement = function(data, container) {\n   return element;\n };\n \n-window.reviews.forEach(function(review) {\n-  getReviewElement(review, reviewsList);\n-});\n+var getReviews = function(callback) {\n+  var xhr = new XMLHttpRequest();\n+  var reviewsBlock = document.querySelector('.reviews');\n+  reviewsBlock.classList.add('reviews-list-loading');\n+\n+  xhr.onload = function(evt) {\n+    var loadedData = JSON.parse(evt.target.response);\n+    reviewsBlock.classList.remove('reviews-list-loading');\n+    callback(loadedData);\n+  };\n+\n+  xhr.timeout = 10000;\n+\n+  xhr.ontimeout = function() {\n+    reviewsBlock.classList.remove('reviews-list-loading');\n+    reviewsBlock.classList.add('reviews-load-failure');\n+  };\n+\n+  xhr.onerror = function() {\n+    reviewsBlock.classList.remove('reviews-list-loading');\n+    reviewsBlock.classList.add('reviews-load-failure');\n+  };\n+\n+  xhr.open('GET', REVIEWS_LOAD_URL, true);\n+  xhr.send();\n+};\n+\n+var renderReviews = function(data) {\n+  reviewsList.innerHTML = '';\n+\n+  data.forEach(function(review) {\n+    getReviewElement(review, reviewsList);\n+  });\n+};\n \n-reviewsFilter.classList.remove('invisible');\n+var getFilteredReviews = function(filter) {\n+  var reviewsToFilter = reviews.slice(0);\n+  var filtredArr = [];\n+\n+  switch (filter) {\n+\n+    case Filter.ALL:\n+      filtredArr = reviewsToFilter;\n+      break;\n+\n+    case Filter.RECENT:\n+      var nowDate = new Date();\n+      nowDate.setDate(nowDate.getDate() - 5);\n+      filtredArr = reviewsToFilter.filter(function(item) {\n+        var reviewsDate = new Date(item.date);\n+        return (reviewsDate > nowDate);\n+      }).sort(function(a, b) {\n+        var aDate = new Date(a.date);\n+        var bDate = new Date(b.date);\n+        return aDate < bDate;\n+      });\n+      break;\n+\n+    case Filter.GOOD:\n+      filtredArr = reviewsToFilter.filter(function(item) {\n+        return item.rating > 2;\n+      }).sort(function(a, b) {\n+        return b.rating - a.rating;\n+      });\n+      break;\n+\n+    case Filter.BAD:\n+      filtredArr = reviewsToFilter.filter(function(item) {\n+        // return item.rating < 3;\n+        return item.rating > 7;\n+      }).sort(function(a, b) {\n+        return a.rating - b.rating;\n+      });\n+      break;\n+\n+    case Filter.POPULAR:\n+      filtredArr = reviewsToFilter.sort(function(a, b) {\n+        return b.review_usefulness - a.review_usefulness;\n+      });\n+      break;\n+  }\n+\n+  if (filtredArr.length) {\n+    return filtredArr;\n+  } else {\n+    return false;\n+  }\n+};\n+\n+var setFilter = function(filter) {\n+  var filteredReviews = getFilteredReviews(filter);\n+  if (filteredReviews) {","path":"src/reviews.js","position":128,"original_position":128,"commit_id":"3c0bb1d54e56a98769067defceaafc281387f906","original_commit_id":"3c0bb1d54e56a98769067defceaafc281387f906","user":{"login":"isqua","id":529247,"avatar_url":"https://avatars.githubusercontent.com/u/529247?v=3","gravatar_id":"","url":"https://api.github.com/users/isqua","html_url":"https://github.com/isqua","followers_url":"https://api.github.com/users/isqua/followers","following_url":"https://api.github.com/users/isqua/following{/other_user}","gists_url":"https://api.github.com/users/isqua/gists{/gist_id}","starred_url":"https://api.github.com/users/isqua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/isqua/subscriptions","organizations_url":"https://api.github.com/users/isqua/orgs","repos_url":"https://api.github.com/users/isqua/repos","events_url":"https://api.github.com/users/isqua/events{/privacy}","received_events_url":"https://api.github.com/users/isqua/received_events","type":"User","site_admin":false},"body":"А тут проверять `filteredReviews.length`. Например если ты будешь не сам фильтровать отзывы, а запрашивать отфильтрованное у сервера, а он будет ходить в базу данных, то скорее всего сервер не будет париться, чтобы вместо пустого массива тебе отдавать `false`.","created_at":"2016-06-15T10:02:30Z","updated_at":"2016-06-15T10:02:30Z","html_url":"https://github.com/htmlacademy-javascript/42701-code-and-magick/pull/9#discussion_r67133813","pull_request_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/pulls/9","_links":{"self":{"href":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/pulls/comments/67133813"},"html":{"href":"https://github.com/htmlacademy-javascript/42701-code-and-magick/pull/9#discussion_r67133813"},"pull_request":{"href":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/pulls/9"}}},"pull_request":{"url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/pulls/9","id":73877642,"html_url":"https://github.com/htmlacademy-javascript/42701-code-and-magick/pull/9","diff_url":"https://github.com/htmlacademy-javascript/42701-code-and-magick/pull/9.diff","patch_url":"https://github.com/htmlacademy-javascript/42701-code-and-magick/pull/9.patch","issue_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/issues/9","number":9,"state":"open","locked":false,"title":"Робкое знакомство с AJAX","user":{"login":"miospace","id":11254600,"avatar_url":"https://avatars.githubusercontent.com/u/11254600?v=3","gravatar_id":"","url":"https://api.github.com/users/miospace","html_url":"https://github.com/miospace","followers_url":"https://api.github.com/users/miospace/followers","following_url":"https://api.github.com/users/miospace/following{/other_user}","gists_url":"https://api.github.com/users/miospace/gists{/gist_id}","starred_url":"https://api.github.com/users/miospace/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miospace/subscriptions","organizations_url":"https://api.github.com/users/miospace/orgs","repos_url":"https://api.github.com/users/miospace/repos","events_url":"https://api.github.com/users/miospace/events{/privacy}","received_events_url":"https://api.github.com/users/miospace/received_events","type":"User","site_admin":false},"body":"\n\n--\n:boom: https://htmlacademy-javascript.github.io/42701-code-and-magick/9/","created_at":"2016-06-15T09:20:37Z","updated_at":"2016-06-15T10:02:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9a6746d0a62671b9ee2cbb1a4fb315f8ba50a01d","assignee":{"login":"isqua","id":529247,"avatar_url":"https://avatars.githubusercontent.com/u/529247?v=3","gravatar_id":"","url":"https://api.github.com/users/isqua","html_url":"https://github.com/isqua","followers_url":"https://api.github.com/users/isqua/followers","following_url":"https://api.github.com/users/isqua/following{/other_user}","gists_url":"https://api.github.com/users/isqua/gists{/gist_id}","starred_url":"https://api.github.com/users/isqua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/isqua/subscriptions","organizations_url":"https://api.github.com/users/isqua/orgs","repos_url":"https://api.github.com/users/isqua/repos","events_url":"https://api.github.com/users/isqua/events{/privacy}","received_events_url":"https://api.github.com/users/isqua/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/pulls/9/commits","review_comments_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/pulls/9/comments","review_comment_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/pulls/comments{/number}","comments_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/issues/9/comments","statuses_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/statuses/3c0bb1d54e56a98769067defceaafc281387f906","head":{"label":"miospace:module5-task1","ref":"module5-task1","sha":"3c0bb1d54e56a98769067defceaafc281387f906","user":{"login":"miospace","id":11254600,"avatar_url":"https://avatars.githubusercontent.com/u/11254600?v=3","gravatar_id":"","url":"https://api.github.com/users/miospace","html_url":"https://github.com/miospace","followers_url":"https://api.github.com/users/miospace/followers","following_url":"https://api.github.com/users/miospace/following{/other_user}","gists_url":"https://api.github.com/users/miospace/gists{/gist_id}","starred_url":"https://api.github.com/users/miospace/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miospace/subscriptions","organizations_url":"https://api.github.com/users/miospace/orgs","repos_url":"https://api.github.com/users/miospace/repos","events_url":"https://api.github.com/users/miospace/events{/privacy}","received_events_url":"https://api.github.com/users/miospace/received_events","type":"User","site_admin":false},"repo":{"id":59658426,"name":"42701-code-and-magick","full_name":"miospace/42701-code-and-magick","owner":{"login":"miospace","id":11254600,"avatar_url":"https://avatars.githubusercontent.com/u/11254600?v=3","gravatar_id":"","url":"https://api.github.com/users/miospace","html_url":"https://github.com/miospace","followers_url":"https://api.github.com/users/miospace/followers","following_url":"https://api.github.com/users/miospace/following{/other_user}","gists_url":"https://api.github.com/users/miospace/gists{/gist_id}","starred_url":"https://api.github.com/users/miospace/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miospace/subscriptions","organizations_url":"https://api.github.com/users/miospace/orgs","repos_url":"https://api.github.com/users/miospace/repos","events_url":"https://api.github.com/users/miospace/events{/privacy}","received_events_url":"https://api.github.com/users/miospace/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/miospace/42701-code-and-magick","description":"Олег Зубов","fork":true,"url":"https://api.github.com/repos/miospace/42701-code-and-magick","forks_url":"https://api.github.com/repos/miospace/42701-code-and-magick/forks","keys_url":"https://api.github.com/repos/miospace/42701-code-and-magick/keys{/key_id}","collaborators_url":"https://api.github.com/repos/miospace/42701-code-and-magick/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/miospace/42701-code-and-magick/teams","hooks_url":"https://api.github.com/repos/miospace/42701-code-and-magick/hooks","issue_events_url":"https://api.github.com/repos/miospace/42701-code-and-magick/issues/events{/number}","events_url":"https://api.github.com/repos/miospace/42701-code-and-magick/events","assignees_url":"https://api.github.com/repos/miospace/42701-code-and-magick/assignees{/user}","branches_url":"https://api.github.com/repos/miospace/42701-code-and-magick/branches{/branch}","tags_url":"https://api.github.com/repos/miospace/42701-code-and-magick/tags","blobs_url":"https://api.github.com/repos/miospace/42701-code-and-magick/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/miospace/42701-code-and-magick/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/miospace/42701-code-and-magick/git/refs{/sha}","trees_url":"https://api.github.com/repos/miospace/42701-code-and-magick/git/trees{/sha}","statuses_url":"https://api.github.com/repos/miospace/42701-code-and-magick/statuses/{sha}","languages_url":"https://api.github.com/repos/miospace/42701-code-and-magick/languages","stargazers_url":"https://api.github.com/repos/miospace/42701-code-and-magick/stargazers","contributors_url":"https://api.github.com/repos/miospace/42701-code-and-magick/contributors","subscribers_url":"https://api.github.com/repos/miospace/42701-code-and-magick/subscribers","subscription_url":"https://api.github.com/repos/miospace/42701-code-and-magick/subscription","commits_url":"https://api.github.com/repos/miospace/42701-code-and-magick/commits{/sha}","git_commits_url":"https://api.github.com/repos/miospace/42701-code-and-magick/git/commits{/sha}","comments_url":"https://api.github.com/repos/miospace/42701-code-and-magick/comments{/number}","issue_comment_url":"https://api.github.com/repos/miospace/42701-code-and-magick/issues/comments{/number}","contents_url":"https://api.github.com/repos/miospace/42701-code-and-magick/contents/{+path}","compare_url":"https://api.github.com/repos/miospace/42701-code-and-magick/compare/{base}...{head}","merges_url":"https://api.github.com/repos/miospace/42701-code-and-magick/merges","archive_url":"https://api.github.com/repos/miospace/42701-code-and-magick/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/miospace/42701-code-and-magick/downloads","issues_url":"https://api.github.com/repos/miospace/42701-code-and-magick/issues{/number}","pulls_url":"https://api.github.com/repos/miospace/42701-code-and-magick/pulls{/number}","milestones_url":"https://api.github.com/repos/miospace/42701-code-and-magick/milestones{/number}","notifications_url":"https://api.github.com/repos/miospace/42701-code-and-magick/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/miospace/42701-code-and-magick/labels{/name}","releases_url":"https://api.github.com/repos/miospace/42701-code-and-magick/releases{/id}","deployments_url":"https://api.github.com/repos/miospace/42701-code-and-magick/deployments","created_at":"2016-05-25T11:43:21Z","updated_at":"2016-05-25T11:43:22Z","pushed_at":"2016-06-15T09:50:10Z","git_url":"git://github.com/miospace/42701-code-and-magick.git","ssh_url":"git@github.com:miospace/42701-code-and-magick.git","clone_url":"https://github.com/miospace/42701-code-and-magick.git","svn_url":"https://github.com/miospace/42701-code-and-magick","homepage":null,"size":1060,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"htmlacademy-javascript:master","ref":"master","sha":"fb95f69704a2d3f36ece4c24e34e6c382221b702","user":{"login":"htmlacademy-javascript","id":14179712,"avatar_url":"https://avatars.githubusercontent.com/u/14179712?v=3","gravatar_id":"","url":"https://api.github.com/users/htmlacademy-javascript","html_url":"https://github.com/htmlacademy-javascript","followers_url":"https://api.github.com/users/htmlacademy-javascript/followers","following_url":"https://api.github.com/users/htmlacademy-javascript/following{/other_user}","gists_url":"https://api.github.com/users/htmlacademy-javascript/gists{/gist_id}","starred_url":"https://api.github.com/users/htmlacademy-javascript/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/htmlacademy-javascript/subscriptions","organizations_url":"https://api.github.com/users/htmlacademy-javascript/orgs","repos_url":"https://api.github.com/users/htmlacademy-javascript/repos","events_url":"https://api.github.com/users/htmlacademy-javascript/events{/privacy}","received_events_url":"https://api.github.com/users/htmlacademy-javascript/received_events","type":"Organization","site_admin":false},"repo":{"id":59600144,"name":"42701-code-and-magick","full_name":"htmlacademy-javascript/42701-code-and-magick","owner":{"login":"htmlacademy-javascript","id":14179712,"avatar_url":"https://avatars.githubusercontent.com/u/14179712?v=3","gravatar_id":"","url":"https://api.github.com/users/htmlacademy-javascript","html_url":"https://github.com/htmlacademy-javascript","followers_url":"https://api.github.com/users/htmlacademy-javascript/followers","following_url":"https://api.github.com/users/htmlacademy-javascript/following{/other_user}","gists_url":"https://api.github.com/users/htmlacademy-javascript/gists{/gist_id}","starred_url":"https://api.github.com/users/htmlacademy-javascript/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/htmlacademy-javascript/subscriptions","organizations_url":"https://api.github.com/users/htmlacademy-javascript/orgs","repos_url":"https://api.github.com/users/htmlacademy-javascript/repos","events_url":"https://api.github.com/users/htmlacademy-javascript/events{/privacy}","received_events_url":"https://api.github.com/users/htmlacademy-javascript/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/htmlacademy-javascript/42701-code-and-magick","description":"Олег Зубов","fork":false,"url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick","forks_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/forks","keys_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/keys{/key_id}","collaborators_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/teams","hooks_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/hooks","issue_events_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/issues/events{/number}","events_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/events","assignees_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/assignees{/user}","branches_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/branches{/branch}","tags_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/tags","blobs_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/git/refs{/sha}","trees_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/git/trees{/sha}","statuses_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/statuses/{sha}","languages_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/languages","stargazers_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/stargazers","contributors_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/contributors","subscribers_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/subscribers","subscription_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/subscription","commits_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/commits{/sha}","git_commits_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/git/commits{/sha}","comments_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/comments{/number}","issue_comment_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/issues/comments{/number}","contents_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/contents/{+path}","compare_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/compare/{base}...{head}","merges_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/merges","archive_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/downloads","issues_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/issues{/number}","pulls_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/pulls{/number}","milestones_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/milestones{/number}","notifications_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/labels{/name}","releases_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/releases{/id}","deployments_url":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/deployments","created_at":"2016-05-24T18:56:17Z","updated_at":"2016-05-25T11:51:13Z","pushed_at":"2016-06-15T09:50:10Z","git_url":"git://github.com/htmlacademy-javascript/42701-code-and-magick.git","ssh_url":"git@github.com:htmlacademy-javascript/42701-code-and-magick.git","clone_url":"https://github.com/htmlacademy-javascript/42701-code-and-magick.git","svn_url":"https://github.com/htmlacademy-javascript/42701-code-and-magick","homepage":"https://github.com/miospace/42701-code-and-magick","size":1093,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":true,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/pulls/9"},"html":{"href":"https://github.com/htmlacademy-javascript/42701-code-and-magick/pull/9"},"issue":{"href":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/issues/9"},"comments":{"href":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/issues/9/comments"},"review_comments":{"href":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/pulls/9/comments"},"review_comment":{"href":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/pulls/9/commits"},"statuses":{"href":"https://api.github.com/repos/htmlacademy-javascript/42701-code-and-magick/statuses/3c0bb1d54e56a98769067defceaafc281387f906"}}}}
{"actor":{"display_login":"isqua"}}