{"action":"created","comment":{"url":"https://api.github.com/repos/voveus/weather-app/pulls/comments/167187042","pull_request_review_id":95370294,"id":167187042,"diff_hunk":"@@ -1,43 +1,120 @@\n let params = {\n         units: \"M\",\n-        days: \"1\",\n+        days: \"16\",\n         city: \"\"\n     }\n \n-function getForecast () {\n+function init() {\n     const text = document.getElementById('search');\n-    params.city = text.value;\n+    params.city = text.value.toLowerCase();\n+    const forecastPeriod = document.querySelector(\".forecastPeriod\").value;\n+    const scale = document.querySelector('input[name=\"toggleScale\"]:checked').value;\n+    makeForecast(forecastPeriod, scale);\n+}\n+\n+async function makeForecast(forecastPeriod, scale) {\n+    if (storageAvailable('localStorage')) {\n+        var storageData = extractFromStorage(params.city);\n+        storageData = JSON.parse(storageData);\n+\n+        if ((storageData !== null) && checkDataExpire(storageData)) {\n+            localStorage.clear();\n+            storageData == null;\n+        }\n+        if (storageData === null) {\n+            await getForecast()\n+                .then(jsonData => JSON.stringify(jsonData))\n+                .then(data => populateStorage(params.city, data));\n+            storageData = extractFromStorage(params.city);\n+            storageData = JSON.parse(storageData);\n+        }\n+        \n+        displayForecast(storageData, forecastPeriod, scale);\n+\n+    } else {\n+        getForecast().then(data => displayForecast(data, forecastPeriod, scale));\n+    }\n+}\n+\n+function storageAvailable(type) {\n+    try {\n+        var storage = window[type],\n+            x = '__storage_test__';\n+        storage.setItem(x, x);\n+        storage.removeItem(x);\n+        return true;\n+    }\n+    catch(e) {\n+        return e instanceof DOMException && (\n+            e.code === 22 ||\n+            e.code === 1014 ||\n+            e.name === 'QuotaExceededError' ||\n+            e.name === 'NS_ERROR_DOM_QUOTA_REACHED') &&\n+            storage.length !== 0;\n+    }\n+}\n+\n+function getForecast() {\n     let cityWeather = new WeatherApi();\n-    cityWeather.getDailyForecast(params)\n-        .then(data => displayForecast(data));\n+    return cityWeather.getDailyForecast(params)\n+        .then(data => data);\n+}\n+\n+function populateStorage(key, value) {\n+    localStorage.setItem(key, value);\n }\n \n+function extractFromStorage(key) {\n+    return localStorage.getItem(key);\n+}\n+\n+function checkDataExpire(storageData) {\n+    let storageTimeStamp = storageData.data[0].ts * 1000;\n+    let storageDate = new Date(storageTimeStamp);\n+    let storageHour = storageDate.getHours();\n+    let storageExpires = storageTimeStamp + ((24 - storageHour) * 60 * 60 * 1000);\n+    let currentTimeStamp = Date.now();\n+\n+    if (currentTimeStamp > storageExpires) {\n+        return true;\n+    } else {\n+        return false;\n+    }\n+}\n+\n+\n function removeChilds () {\n     const mainForecast = document.getElementById('mainForecast');\n     while (mainForecast.firstChild) {\n         mainForecast.removeChild(mainForecast.firstChild);\n     }\n }\n \n-function displayForecast (data) {\n+function displayForecast (cityData, forecastPeriod, scale) {\n     removeChilds();\n \n     const mainForecast = document.getElementById('mainForecast');\n \n-    data.data.forEach((day) => {\n+    cityData.data.every((day, index) => {\n+        if (index >= forecastPeriod) {return false}\n+            else {\n         const mainForecastItem = document.createElement('div');\n         mainForecast.appendChild(mainForecastItem);\n         mainForecastItem.className= 'mainForecastItem'\n         \n-        const summary = generateSummary(day);\n+        const summary = generateSummary(day, scale);\n         mainForecastItem.appendChild(summary);\n \n         const details = generateDetails(day);\n         mainForecastItem.appendChild(details);\n+\n+        return true;\n+\n+    }\n     });\n }\n \n-function generateSummary (data) {\n+function generateSummary (data, scale) {","path":"js/app.js","position":126,"original_position":126,"commit_id":"f63947389312ba5ccd91de7608b39ab67277b8d3","original_commit_id":"f63947389312ba5ccd91de7608b39ab67277b8d3","user":{"login":"viktor-yakubiv","id":8440244,"avatar_url":"https://avatars3.githubusercontent.com/u/8440244?v=4","gravatar_id":"","url":"https://api.github.com/users/viktor-yakubiv","html_url":"https://github.com/viktor-yakubiv","followers_url":"https://api.github.com/users/viktor-yakubiv/followers","following_url":"https://api.github.com/users/viktor-yakubiv/following{/other_user}","gists_url":"https://api.github.com/users/viktor-yakubiv/gists{/gist_id}","starred_url":"https://api.github.com/users/viktor-yakubiv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/viktor-yakubiv/subscriptions","organizations_url":"https://api.github.com/users/viktor-yakubiv/orgs","repos_url":"https://api.github.com/users/viktor-yakubiv/repos","events_url":"https://api.github.com/users/viktor-yakubiv/events{/privacy}","received_events_url":"https://api.github.com/users/viktor-yakubiv/received_events","type":"User","site_admin":false},"body":"Awesome!","created_at":"2018-02-09T10:10:31Z","updated_at":"2018-02-09T10:10:31Z","html_url":"https://github.com/voveus/weather-app/pull/16#discussion_r167187042","pull_request_url":"https://api.github.com/repos/voveus/weather-app/pulls/16","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/voveus/weather-app/pulls/comments/167187042"},"html":{"href":"https://github.com/voveus/weather-app/pull/16#discussion_r167187042"},"pull_request":{"href":"https://api.github.com/repos/voveus/weather-app/pulls/16"}}},"pull_request":{"url":"https://api.github.com/repos/voveus/weather-app/pulls/16","id":168109141,"html_url":"https://github.com/voveus/weather-app/pull/16","diff_url":"https://github.com/voveus/weather-app/pull/16.diff","patch_url":"https://github.com/voveus/weather-app/pull/16.patch","issue_url":"https://api.github.com/repos/voveus/weather-app/issues/16","number":16,"state":"open","locked":false,"title":"Add local storage","user":{"login":"Boyko-Anna","id":9992981,"avatar_url":"https://avatars0.githubusercontent.com/u/9992981?v=4","gravatar_id":"","url":"https://api.github.com/users/Boyko-Anna","html_url":"https://github.com/Boyko-Anna","followers_url":"https://api.github.com/users/Boyko-Anna/followers","following_url":"https://api.github.com/users/Boyko-Anna/following{/other_user}","gists_url":"https://api.github.com/users/Boyko-Anna/gists{/gist_id}","starred_url":"https://api.github.com/users/Boyko-Anna/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Boyko-Anna/subscriptions","organizations_url":"https://api.github.com/users/Boyko-Anna/orgs","repos_url":"https://api.github.com/users/Boyko-Anna/repos","events_url":"https://api.github.com/users/Boyko-Anna/events{/privacy}","received_events_url":"https://api.github.com/users/Boyko-Anna/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-02-08T22:50:43Z","updated_at":"2018-02-09T10:10:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4bdc3c93df77b752ddabd0ea8df9dda9e07cfbd9","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"milestone":null,"commits_url":"https://api.github.com/repos/voveus/weather-app/pulls/16/commits","review_comments_url":"https://api.github.com/repos/voveus/weather-app/pulls/16/comments","review_comment_url":"https://api.github.com/repos/voveus/weather-app/pulls/comments{/number}","comments_url":"https://api.github.com/repos/voveus/weather-app/issues/16/comments","statuses_url":"https://api.github.com/repos/voveus/weather-app/statuses/f63947389312ba5ccd91de7608b39ab67277b8d3","head":{"label":"voveus:storage","ref":"storage","sha":"f63947389312ba5ccd91de7608b39ab67277b8d3","user":{"login":"voveus","id":10214017,"avatar_url":"https://avatars2.githubusercontent.com/u/10214017?v=4","gravatar_id":"","url":"https://api.github.com/users/voveus","html_url":"https://github.com/voveus","followers_url":"https://api.github.com/users/voveus/followers","following_url":"https://api.github.com/users/voveus/following{/other_user}","gists_url":"https://api.github.com/users/voveus/gists{/gist_id}","starred_url":"https://api.github.com/users/voveus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/voveus/subscriptions","organizations_url":"https://api.github.com/users/voveus/orgs","repos_url":"https://api.github.com/users/voveus/repos","events_url":"https://api.github.com/users/voveus/events{/privacy}","received_events_url":"https://api.github.com/users/voveus/received_events","type":"User","site_admin":false},"repo":{"id":120180730,"name":"weather-app","full_name":"voveus/weather-app","owner":{"login":"voveus","id":10214017,"avatar_url":"https://avatars2.githubusercontent.com/u/10214017?v=4","gravatar_id":"","url":"https://api.github.com/users/voveus","html_url":"https://github.com/voveus","followers_url":"https://api.github.com/users/voveus/followers","following_url":"https://api.github.com/users/voveus/following{/other_user}","gists_url":"https://api.github.com/users/voveus/gists{/gist_id}","starred_url":"https://api.github.com/users/voveus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/voveus/subscriptions","organizations_url":"https://api.github.com/users/voveus/orgs","repos_url":"https://api.github.com/users/voveus/repos","events_url":"https://api.github.com/users/voveus/events{/privacy}","received_events_url":"https://api.github.com/users/voveus/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/voveus/weather-app","description":null,"fork":false,"url":"https://api.github.com/repos/voveus/weather-app","forks_url":"https://api.github.com/repos/voveus/weather-app/forks","keys_url":"https://api.github.com/repos/voveus/weather-app/keys{/key_id}","collaborators_url":"https://api.github.com/repos/voveus/weather-app/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/voveus/weather-app/teams","hooks_url":"https://api.github.com/repos/voveus/weather-app/hooks","issue_events_url":"https://api.github.com/repos/voveus/weather-app/issues/events{/number}","events_url":"https://api.github.com/repos/voveus/weather-app/events","assignees_url":"https://api.github.com/repos/voveus/weather-app/assignees{/user}","branches_url":"https://api.github.com/repos/voveus/weather-app/branches{/branch}","tags_url":"https://api.github.com/repos/voveus/weather-app/tags","blobs_url":"https://api.github.com/repos/voveus/weather-app/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/voveus/weather-app/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/voveus/weather-app/git/refs{/sha}","trees_url":"https://api.github.com/repos/voveus/weather-app/git/trees{/sha}","statuses_url":"https://api.github.com/repos/voveus/weather-app/statuses/{sha}","languages_url":"https://api.github.com/repos/voveus/weather-app/languages","stargazers_url":"https://api.github.com/repos/voveus/weather-app/stargazers","contributors_url":"https://api.github.com/repos/voveus/weather-app/contributors","subscribers_url":"https://api.github.com/repos/voveus/weather-app/subscribers","subscription_url":"https://api.github.com/repos/voveus/weather-app/subscription","commits_url":"https://api.github.com/repos/voveus/weather-app/commits{/sha}","git_commits_url":"https://api.github.com/repos/voveus/weather-app/git/commits{/sha}","comments_url":"https://api.github.com/repos/voveus/weather-app/comments{/number}","issue_comment_url":"https://api.github.com/repos/voveus/weather-app/issues/comments{/number}","contents_url":"https://api.github.com/repos/voveus/weather-app/contents/{+path}","compare_url":"https://api.github.com/repos/voveus/weather-app/compare/{base}...{head}","merges_url":"https://api.github.com/repos/voveus/weather-app/merges","archive_url":"https://api.github.com/repos/voveus/weather-app/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/voveus/weather-app/downloads","issues_url":"https://api.github.com/repos/voveus/weather-app/issues{/number}","pulls_url":"https://api.github.com/repos/voveus/weather-app/pulls{/number}","milestones_url":"https://api.github.com/repos/voveus/weather-app/milestones{/number}","notifications_url":"https://api.github.com/repos/voveus/weather-app/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/voveus/weather-app/labels{/name}","releases_url":"https://api.github.com/repos/voveus/weather-app/releases{/id}","deployments_url":"https://api.github.com/repos/voveus/weather-app/deployments","created_at":"2018-02-04T11:56:16Z","updated_at":"2018-02-07T13:31:16Z","pushed_at":"2018-02-09T09:59:32Z","git_url":"git://github.com/voveus/weather-app.git","ssh_url":"git@github.com:voveus/weather-app.git","clone_url":"https://github.com/voveus/weather-app.git","svn_url":"https://github.com/voveus/weather-app","homepage":null,"size":96,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":8,"license":null,"forks":1,"open_issues":8,"watchers":0,"default_branch":"master"}},"base":{"label":"voveus:master","ref":"master","sha":"925c5bc497268c9049e4f95f392c6a0066cd4023","user":{"login":"voveus","id":10214017,"avatar_url":"https://avatars2.githubusercontent.com/u/10214017?v=4","gravatar_id":"","url":"https://api.github.com/users/voveus","html_url":"https://github.com/voveus","followers_url":"https://api.github.com/users/voveus/followers","following_url":"https://api.github.com/users/voveus/following{/other_user}","gists_url":"https://api.github.com/users/voveus/gists{/gist_id}","starred_url":"https://api.github.com/users/voveus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/voveus/subscriptions","organizations_url":"https://api.github.com/users/voveus/orgs","repos_url":"https://api.github.com/users/voveus/repos","events_url":"https://api.github.com/users/voveus/events{/privacy}","received_events_url":"https://api.github.com/users/voveus/received_events","type":"User","site_admin":false},"repo":{"id":120180730,"name":"weather-app","full_name":"voveus/weather-app","owner":{"login":"voveus","id":10214017,"avatar_url":"https://avatars2.githubusercontent.com/u/10214017?v=4","gravatar_id":"","url":"https://api.github.com/users/voveus","html_url":"https://github.com/voveus","followers_url":"https://api.github.com/users/voveus/followers","following_url":"https://api.github.com/users/voveus/following{/other_user}","gists_url":"https://api.github.com/users/voveus/gists{/gist_id}","starred_url":"https://api.github.com/users/voveus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/voveus/subscriptions","organizations_url":"https://api.github.com/users/voveus/orgs","repos_url":"https://api.github.com/users/voveus/repos","events_url":"https://api.github.com/users/voveus/events{/privacy}","received_events_url":"https://api.github.com/users/voveus/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/voveus/weather-app","description":null,"fork":false,"url":"https://api.github.com/repos/voveus/weather-app","forks_url":"https://api.github.com/repos/voveus/weather-app/forks","keys_url":"https://api.github.com/repos/voveus/weather-app/keys{/key_id}","collaborators_url":"https://api.github.com/repos/voveus/weather-app/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/voveus/weather-app/teams","hooks_url":"https://api.github.com/repos/voveus/weather-app/hooks","issue_events_url":"https://api.github.com/repos/voveus/weather-app/issues/events{/number}","events_url":"https://api.github.com/repos/voveus/weather-app/events","assignees_url":"https://api.github.com/repos/voveus/weather-app/assignees{/user}","branches_url":"https://api.github.com/repos/voveus/weather-app/branches{/branch}","tags_url":"https://api.github.com/repos/voveus/weather-app/tags","blobs_url":"https://api.github.com/repos/voveus/weather-app/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/voveus/weather-app/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/voveus/weather-app/git/refs{/sha}","trees_url":"https://api.github.com/repos/voveus/weather-app/git/trees{/sha}","statuses_url":"https://api.github.com/repos/voveus/weather-app/statuses/{sha}","languages_url":"https://api.github.com/repos/voveus/weather-app/languages","stargazers_url":"https://api.github.com/repos/voveus/weather-app/stargazers","contributors_url":"https://api.github.com/repos/voveus/weather-app/contributors","subscribers_url":"https://api.github.com/repos/voveus/weather-app/subscribers","subscription_url":"https://api.github.com/repos/voveus/weather-app/subscription","commits_url":"https://api.github.com/repos/voveus/weather-app/commits{/sha}","git_commits_url":"https://api.github.com/repos/voveus/weather-app/git/commits{/sha}","comments_url":"https://api.github.com/repos/voveus/weather-app/comments{/number}","issue_comment_url":"https://api.github.com/repos/voveus/weather-app/issues/comments{/number}","contents_url":"https://api.github.com/repos/voveus/weather-app/contents/{+path}","compare_url":"https://api.github.com/repos/voveus/weather-app/compare/{base}...{head}","merges_url":"https://api.github.com/repos/voveus/weather-app/merges","archive_url":"https://api.github.com/repos/voveus/weather-app/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/voveus/weather-app/downloads","issues_url":"https://api.github.com/repos/voveus/weather-app/issues{/number}","pulls_url":"https://api.github.com/repos/voveus/weather-app/pulls{/number}","milestones_url":"https://api.github.com/repos/voveus/weather-app/milestones{/number}","notifications_url":"https://api.github.com/repos/voveus/weather-app/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/voveus/weather-app/labels{/name}","releases_url":"https://api.github.com/repos/voveus/weather-app/releases{/id}","deployments_url":"https://api.github.com/repos/voveus/weather-app/deployments","created_at":"2018-02-04T11:56:16Z","updated_at":"2018-02-07T13:31:16Z","pushed_at":"2018-02-09T09:59:32Z","git_url":"git://github.com/voveus/weather-app.git","ssh_url":"git@github.com:voveus/weather-app.git","clone_url":"https://github.com/voveus/weather-app.git","svn_url":"https://github.com/voveus/weather-app","homepage":null,"size":96,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":8,"license":null,"forks":1,"open_issues":8,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/voveus/weather-app/pulls/16"},"html":{"href":"https://github.com/voveus/weather-app/pull/16"},"issue":{"href":"https://api.github.com/repos/voveus/weather-app/issues/16"},"comments":{"href":"https://api.github.com/repos/voveus/weather-app/issues/16/comments"},"review_comments":{"href":"https://api.github.com/repos/voveus/weather-app/pulls/16/comments"},"review_comment":{"href":"https://api.github.com/repos/voveus/weather-app/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/voveus/weather-app/pulls/16/commits"},"statuses":{"href":"https://api.github.com/repos/voveus/weather-app/statuses/f63947389312ba5ccd91de7608b39ab67277b8d3"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"viktor-yakubiv"}}