Skip to content

Instantly share code, notes, and snippets.

@IgorKurkov
Created February 10, 2018 22:56
Show Gist options
  • Save IgorKurkov/d62405b70d28b11273d6ae55285f00ff to your computer and use it in GitHub Desktop.
Save IgorKurkov/d62405b70d28b11273d6ae55285f00ff to your computer and use it in GitHub Desktop.
Get data by 100 items per request
var data = [];
var oldestMessageId = null;
function fetchAllMessages(oldestMessageId) {
fetch(getAllMessages(100, oldestMessageId))
.then(function(response) {
return response.json();
})
.then( function(response) {
Array.prototype.push.apply(data, response);
var oldestMessageId = response[0].id;
console.log(JSON.stringify(response[0]))
if(response.length == 100) {
fetchAllMessages(oldestMessageId); // fetch again
}
else {
var messagesArr = buildMessagesArr (data);
var finishedArr = filterFinishedMessages (messagesArr);
var activityArr = buildActivityArrOfChattingByDay (messagesArr);
var users = extractActiveUsersFromFinishedArr (finishedArr);
insertTaskListToPage (finishedArr); //void
insertValuesToFeaturesCards (messagesArr); //void
//var usersUrls = getUrlsOfUsersInChat (messagesArr, getAllUsersOfChat);
//console.log(usersUrls)
//getLocationsFromUserUrls (usersUrls, buildLocationsGraphArray); //void
drawTimelineChart (buildTimelineGraphArr (finishedArr, users));
drawVerticalBarChart (buildSumOfTasksByUserGraphArr (users));
drawActivityLineChart (activityArr);
}
})
.catch(alert);
}
fetchAllMessages(oldestMessageId);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment