jellyfish-web/src/controllers/hometab.js

75 lines
2.2 KiB
JavaScript
Raw Normal View History

2020-08-14 08:46:34 +02:00
import * as userSettings from '../scripts/settings/userSettings';
import loading from '../components/loading/loading';
import focusManager from '../components/focusManager';
import homeSections from '../components/homesections/homesections';
import '../elements/emby-itemscontainer/emby-itemscontainer';
2018-10-23 01:05:09 +03:00
class HomeTab {
constructor(view, params) {
this.view = view;
this.params = params;
2020-08-16 20:24:45 +02:00
this.apiClient = window.ConnectionManager.currentApiClient();
2020-05-04 12:44:12 +02:00
this.sectionsContainer = view.querySelector('.sections');
view.querySelector('.sections').addEventListener('settingschange', onHomeScreenSettingsChanged.bind(this));
2018-10-23 01:05:09 +03:00
}
onResume(options) {
2018-10-23 01:05:09 +03:00
if (this.sectionsRendered) {
const sectionsContainer = this.sectionsContainer;
if (sectionsContainer) {
return homeSections.resume(sectionsContainer, options);
}
return Promise.resolve();
2018-10-23 01:05:09 +03:00
}
2018-10-23 01:05:09 +03:00
loading.show();
const view = this.view;
const apiClient = this.apiClient;
this.destroyHomeSections();
this.sectionsRendered = true;
return apiClient.getCurrentUser().then(function (user) {
2020-05-04 12:44:12 +02:00
return homeSections.loadSections(view.querySelector('.sections'), apiClient, user, userSettings).then(function () {
if (options.autoFocus) {
focusManager.autoFocus(view);
}
loading.hide();
});
});
}
onPause() {
const sectionsContainer = this.sectionsContainer;
if (sectionsContainer) {
homeSections.pause(sectionsContainer);
}
}
destroy() {
this.view = null;
this.params = null;
this.apiClient = null;
this.destroyHomeSections();
this.sectionsContainer = null;
}
destroyHomeSections() {
const sectionsContainer = this.sectionsContainer;
if (sectionsContainer) {
homeSections.destroySections(sectionsContainer);
}
}
}
function onHomeScreenSettingsChanged() {
this.sectionsRendered = false;
if (!this.paused) {
this.onResume({
refresh: true
});
}
}
export default HomeTab;