[Fix] Put History in Chronological order again and better sub handling

This commit is contained in:
PrestonN 2018-11-08 14:21:04 -05:00
parent 0797d426f8
commit cb32ae7db3
4 changed files with 47 additions and 31 deletions

View File

@ -58,9 +58,12 @@ function showHistory(){
historyDb.find({}).sort({
timeWatched: -1
}).exec((err, docs) => {
let position = 0;
docs.forEach((video) => {
invidiousAPI('videos', video.videoId, {}, (data) => {
data.position = position;
displayVideo(data, 'history');
position++;
});
});

View File

@ -108,33 +108,15 @@ function loadSubscriptions() {
progressView.progressWidth = (counter / results.length) * 100;
if (counter === results.length) {
videoList.sort((a, b) => {
return b.published - a.published;
});
subscriptionView.videoList = [];
console.log(videoList);
if (videoList.length > 100) {
for (let i = 0; i < 100; i++) {
displayVideo(videoList[i], 'subscriptions');
}
} else {
videoList.forEach((video) => {
displayVideo(video, 'subscriptions');
});
}
loadingView.seen = false;
progressView.seen = false;
progressView.progressWidth = 0;
subscriptionTimer = window.setTimeout(() => {
checkSubscriptions = true;
}, 60000);
console.log('Done');
addSubsToView(videoList);
}
},(errorData) => {
showToast('Unable to load channel: ' + results[i]['channelName']);
counter = counter + 1;
progressView.progressWidth = (counter / results.length) * 100;
if (counter === results.length) {
addSubsToView(videoList);
}
});
}
} else {
@ -146,6 +128,35 @@ function loadSubscriptions() {
});
}
function addSubsToView (videoList) {
videoList.sort((a, b) => {
return b.published - a.published;
});
subscriptionView.videoList = [];
console.log(videoList);
if (videoList.length > 100) {
for (let i = 0; i < 100; i++) {
displayVideo(videoList[i], 'subscriptions');
}
} else {
videoList.forEach((video) => {
displayVideo(video, 'subscriptions');
});
}
loadingView.seen = false;
progressView.seen = false;
progressView.progressWidth = 0;
subscriptionTimer = window.setTimeout(() => {
checkSubscriptions = true;
}, 60000);
console.log('Done');
}
/**
* Get the list of subscriptions from the user's subscription database.
*

View File

@ -193,7 +193,8 @@ function displayVideo(videoData, listType = '') {
video.removeFromSave = false;
break;
case 'history':
historyView.videoList = historyView.videoList.concat(video);
historyView.videoList.splice(videoData.position, 0, video);
console.log(video);
video.removeFromSave = false;
break;
case 'channel':

View File

@ -25,7 +25,10 @@
* @return {Void}
*/
function invidiousAPI(resource, id, params, success) {
function invidiousAPI(resource, id, params, success, fail = function(){
showToast('There was an error calling the Invidious API.');
loadingView.seen = false;
}) {
let requestUrl = 'https://www.invidio.us/api/v1/' + resource + '/' + id + '?' + $.param(params);
if (useTor) {
@ -45,12 +48,10 @@ function invidiousAPI(resource, id, params, success) {
requestUrl,
success
).fail((xhr, textStatus, error) => {
showToast('There was an error calling the Invidious API.');
console.log(error);
fail(xhr);
console.log(xhr);
console.log(textStatus);
console.log(requestUrl);
loadingView.seen = false;
});
}
}