import layoutManager from 'components/layoutManager'; import { getUserViewsQuery } from 'hooks/useUserViews'; import globalize from 'lib/globalize'; import { DEFAULT_SECTIONS, HomeSectionType } from 'types/homeSectionType'; import Dashboard from 'utils/dashboard'; import { toApi } from 'utils/jellyfin-apiclient/compat'; import { queryClient } from 'utils/query/queryClient'; import { loadRecordings } from './sections/activeRecordings'; import { loadLibraryButtons } from './sections/libraryButtons'; import { loadLibraryTiles } from './sections/libraryTiles'; import { loadLiveTV } from './sections/liveTv'; import { loadNextUp } from './sections/nextUp'; import { loadRecentlyAdded } from './sections/recentlyAdded'; import { loadResume } from './sections/resume'; import 'elements/emby-button/paper-icon-button-light'; import 'elements/emby-itemscontainer/emby-itemscontainer'; import 'elements/emby-scroller/emby-scroller'; import 'elements/emby-button/emby-button'; import './homesections.scss'; export function getDefaultSection(index) { if (index < 0 || index > DEFAULT_SECTIONS.length) return ''; return DEFAULT_SECTIONS[index]; } function getAllSectionsToShow(userSettings, sectionCount) { const sections = []; for (let i = 0, length = sectionCount; i < length; i++) { let section = userSettings.get('homesection' + i) || getDefaultSection(i); if (section === 'folders') { section = getDefaultSection(0); } sections.push(section); } // Ensure libraries are visible in TV layout if ( layoutManager.tv && !sections.includes(HomeSectionType.SmallLibraryTiles) && !sections.includes(HomeSectionType.LibraryButtons) ) { return [ HomeSectionType.SmallLibraryTiles, ...sections ]; } return sections; } export function loadSections(elem, apiClient, user, userSettings) { const userId = user.Id || apiClient.getCurrentUserId(); return queryClient .fetchQuery(getUserViewsQuery(toApi(apiClient), userId)) .then(result => result.Items || []) .then(function (userViews) { let html = ''; if (userViews.length) { const userSectionCount = 10; // TV layout can have an extra section to ensure libraries are visible const totalSectionCount = layoutManager.tv ? userSectionCount + 1 : userSectionCount; for (let i = 0; i < totalSectionCount; i++) { html += '
'; } elem.innerHTML = html; elem.classList.add('homeSectionsContainer'); const promises = []; const sections = getAllSectionsToShow(userSettings, userSectionCount); for (let i = 0; i < sections.length; i++) { promises.push(loadSection(elem, apiClient, user, userSettings, userViews, sections, i)); } return Promise.all(promises) // Timeout for polyfilled CustomElements (webOS 1.2) .then(() => new Promise((resolve) => setTimeout(resolve, 0))) .then(() => { return resume(elem, { refresh: true }); }); } else { let noLibDescription; if (user.Policy?.IsAdministrator) { noLibDescription = globalize.translate('NoCreatedLibraries', '' + noLibDescription + '
'; html += '