update lazy loader

This commit is contained in:
Luke Pulverenti 2016-11-16 01:00:28 -05:00
parent 0291450ffb
commit 71b0be28b8
8 changed files with 226 additions and 126 deletions

View file

@ -22,34 +22,32 @@
}
}
function loadSection(page, user, displayPreferences, index) {
function loadSection(page, user, userSettings, index) {
var userId = user.Id;
var section = displayPreferences.CustomPrefs['home' + index] || getDefaultSection(index);
var section = userSettings.get('homesection' + index) || getDefaultSection(index);
if (section == 'folders') {
section = defaultFirstSection;
}
var showLibraryTileNames = displayPreferences.CustomPrefs.enableLibraryTileNames != '0';
var elem = page.querySelector('.section' + index);
if (section == 'latestmedia') {
return Sections.loadRecentlyAdded(elem, user);
}
else if (section == 'librarytiles') {
return Sections.loadLibraryTiles(elem, user, 'backdrop', index, false, showLibraryTileNames);
return Sections.loadLibraryTiles(elem, user, 'backdrop', index, false);
}
else if (section == 'smalllibrarytiles') {
return Sections.loadLibraryTiles(elem, user, 'smallBackdrop', index, false, showLibraryTileNames);
return Sections.loadLibraryTiles(elem, user, 'smallBackdrop', index, false);
}
else if (section == 'smalllibrarytiles-automobile') {
return Sections.loadLibraryTiles(elem, user, 'smallBackdrop', index, true, showLibraryTileNames);
return Sections.loadLibraryTiles(elem, user, 'smallBackdrop', index, true);
}
else if (section == 'librarytiles-automobile') {
return Sections.loadLibraryTiles(elem, user, 'backdrop', index, true, showLibraryTileNames);
return Sections.loadLibraryTiles(elem, user, 'backdrop', index, true);
}
else if (section == 'librarybuttons') {
return Sections.loadlibraryButtons(elem, userId, index);
@ -77,7 +75,7 @@
}
}
function loadSections(page, user, displayPreferences) {
function loadSections(page, user, userSettings) {
var i, length;
var sectionCount = 5;
@ -98,7 +96,7 @@
for (i = 0, length = sectionCount; i < length; i++) {
promises.push(loadSection(page, user, displayPreferences, i));
promises.push(loadSection(page, user, userSettings, i));
}
return Promise.all(promises);
@ -186,24 +184,37 @@
});
}
function getRequirePromise(deps) {
return new Promise(function (resolve, reject) {
require(deps, resolve);
});
}
function loadHomeTab(page, tabContent) {
if (window.ApiClient) {
var userId = Dashboard.getCurrentUserId();
Dashboard.showLoadingMsg();
getDisplayPreferences('home', userId).then(function (result) {
var promises = [
getDisplayPreferences('home', userId),
Dashboard.getCurrentUser(),
getRequirePromise(['userSettings'])
];
Dashboard.getCurrentUser().then(function (user) {
Promise.all(promises).then(function(responses) {
var displayPreferences = responses[0];
var user = responses[1];
var userSettings = responses[2];
loadSections(tabContent, user, result).then(function () {
if (!AppInfo.isNativeApp) {
showWelcomeIfNeeded(page, result);
}
Dashboard.hideLoadingMsg();
});
loadSections(tabContent, user, userSettings).then(function () {
if (!AppInfo.isNativeApp) {
showWelcomeIfNeeded(page, displayPreferences);
}
Dashboard.hideLoadingMsg();
});
});
}