From 92e88e03e068b9b3b05f42ef26f376f2c7b65646 Mon Sep 17 00:00:00 2001 From: Nathan Mascitelli Date: Wed, 21 Apr 2021 22:59:16 -0400 Subject: [PATCH] Add a continue reading section --- src/components/homesections/homesections.js | 101 ++++---------------- src/strings/en-gb.json | 1 + src/strings/en-us.json | 1 + 3 files changed, 18 insertions(+), 85 deletions(-) diff --git a/src/components/homesections/homesections.js b/src/components/homesections/homesections.js index 794422ad1f..b2edfc7136 100644 --- a/src/components/homesections/homesections.js +++ b/src/components/homesections/homesections.js @@ -24,12 +24,14 @@ import ServerConnections from '../ServerConnections'; case 2: return 'resumeaudio'; case 3: - return 'livetv'; + return 'resumebook'; case 4: - return 'nextup'; + return 'livetv'; case 5: - return 'latestmedia'; + return 'nextup'; case 6: + return 'latestmedia'; + case 7: return 'none'; default: return ''; @@ -142,15 +144,17 @@ import ServerConnections from '../ServerConnections'; } else if (section === 'librarybuttons') { loadlibraryButtons(elem, apiClient, user, userSettings, userViews); } else if (section === 'resume') { - loadResumeVideo(elem, apiClient); + return loadResume(elem, apiClient, 'HeaderContinueWatching', 'Video'); } else if (section === 'resumeaudio') { - loadResumeAudio(elem, apiClient); + return loadResume(elem, apiClient, 'HeaderContinueListening', 'Audio'); } else if (section === 'activerecordings') { loadLatestLiveTvRecordings(elem, true, apiClient); } else if (section === 'nextup') { loadNextUp(elem, apiClient); } else if (section === 'onnow' || section === 'livetv') { return loadOnNow(elem, apiClient, user); + } else if (section == 'resumebook') { + return loadResume(elem, apiClient, 'HeaderContinueReading', 'Book'); } else { elem.innerHTML = ''; return Promise.resolve(); @@ -365,58 +369,10 @@ import ServerConnections from '../ServerConnections'; imageLoader.lazyChildren(elem); } - function getContinueWatchingFetchFn(serverId) { - return function () { - const apiClient = ServerConnections.getApiClient(serverId); - const screenWidth = dom.getWindowSize().innerWidth; - - let limit; - if (enableScrollX()) { - limit = 12; - } else { - limit = screenWidth >= 1920 ? 8 : (screenWidth >= 1600 ? 8 : (screenWidth >= 1200 ? 9 : 6)); - limit = Math.min(limit, 5); - } - - const options = { - Limit: limit, - Recursive: true, - Fields: 'PrimaryImageAspectRatio,BasicSyncInfo', - ImageTypeLimit: 1, - EnableImageTypes: 'Primary,Backdrop,Thumb', - EnableTotalRecordCount: false, - MediaTypes: 'Video' - }; - - return apiClient.getResumableItems(apiClient.getCurrentUserId(), options); - }; - } - - function getContinueWatchingItemsHtml(items) { - const cardLayout = false; - return cardBuilder.getCardsHtml({ - items: items, - preferThumb: true, - shape: getThumbShape(), - overlayText: false, - showTitle: true, - showParentTitle: true, - lazy: true, - showDetailsMenu: true, - overlayPlayButton: true, - context: 'home', - centerText: !cardLayout, - allowBottomPadding: false, - cardLayout: cardLayout, - showYear: true, - lines: 2 - }); - } - - function loadResumeVideo(elem, apiClient) { + function loadResume(elem, apiClient, headerText, mediaType) { let html = ''; - html += '

' + globalize.translate('HeaderContinueWatching') + '

'; + html += '

' + globalize.translate(headerText) + '

'; if (enableScrollX()) { html += '
'; html += '
'; @@ -433,12 +389,12 @@ import ServerConnections from '../ServerConnections'; elem.innerHTML = html; const itemsContainer = elem.querySelector('.itemsContainer'); - itemsContainer.fetchData = getContinueWatchingFetchFn(apiClient.serverId()); - itemsContainer.getItemsHtml = getContinueWatchingItemsHtml; + itemsContainer.fetchData = getItemsToResumeFn(mediaType, apiClient.serverId()); + itemsContainer.getItemsHtml = getItemsToResumeHtml; itemsContainer.parentContainer = elem; } - function getContinueListeningFetchFn(serverId) { + function getItemsToResumeFn(mediaType, serverId) { return function () { const apiClient = ServerConnections.getApiClient(serverId); const screenWidth = dom.getWindowSize().innerWidth; @@ -458,14 +414,14 @@ import ServerConnections from '../ServerConnections'; ImageTypeLimit: 1, EnableImageTypes: 'Primary,Backdrop,Thumb', EnableTotalRecordCount: false, - MediaTypes: 'Audio' + MediaTypes: mediaType }; return apiClient.getResumableItems(apiClient.getCurrentUserId(), options); }; } - function getContinueListeningItemsHtml(items) { + function getItemsToResumeHtml(items) { const cardLayout = false; return cardBuilder.getCardsHtml({ items: items, @@ -486,31 +442,6 @@ import ServerConnections from '../ServerConnections'; }); } - function loadResumeAudio(elem, apiClient) { - let html = ''; - - html += '

' + globalize.translate('HeaderContinueListening') + '

'; - if (enableScrollX()) { - html += '
'; - html += '
'; - } else { - html += '
'; - } - - if (enableScrollX()) { - html += '
'; - } - html += '
'; - - elem.classList.add('hide'); - elem.innerHTML = html; - - const itemsContainer = elem.querySelector('.itemsContainer'); - itemsContainer.fetchData = getContinueListeningFetchFn(apiClient.serverId()); - itemsContainer.getItemsHtml = getContinueListeningItemsHtml; - itemsContainer.parentContainer = elem; - } - function getOnNowFetchFn(serverId) { return function () { const apiClient = ServerConnections.getApiClient(serverId); diff --git a/src/strings/en-gb.json b/src/strings/en-gb.json index d1a563d919..15b379d00b 100644 --- a/src/strings/en-gb.json +++ b/src/strings/en-gb.json @@ -37,6 +37,7 @@ "Folders": "Folders", "Genres": "Genres", "HeaderAlbumArtists": "Album Artists", + "HeaderContinueReading": "Continue Reading", "HeaderContinueWatching": "Continue Watching", "Movies": "Movies", "Photos": "Photos", diff --git a/src/strings/en-us.json b/src/strings/en-us.json index bf6d74a0b6..54d4a8ca75 100644 --- a/src/strings/en-us.json +++ b/src/strings/en-us.json @@ -321,6 +321,7 @@ "HeaderContainerProfileHelp": "Container profiles indicate the limitations of a device when playing specific formats. If a limitation applies then the media will be transcoded, even if the format is configured for direct play.", "HeaderContinueListening": "Continue Listening", "HeaderContinueWatching": "Continue Watching", + "HeaderContinueReading": "Continue Reading", "HeaderCustomDlnaProfiles": "Custom Profiles", "HeaderDateIssued": "Date Issued", "HeaderDebugging": "Debugging and Tracing",