1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/components/favoriteitems.js

233 lines
7.2 KiB
JavaScript
Raw Normal View History

2023-10-01 02:49:36 -04:00
import dom from 'scripts/dom';
2024-08-14 13:31:34 -04:00
import globalize from 'lib/globalize';
2023-10-01 02:49:36 -04:00
import { getBackdropShape, getPortraitShape, getSquareShape } from 'utils/card';
import { getParameterByName } from 'utils/url';
2020-08-16 20:24:45 +02:00
import { appHost } from './apphost';
2023-10-01 02:49:36 -04:00
import cardBuilder from './cardbuilder/cardBuilder';
2020-08-14 08:46:34 +02:00
import imageLoader from './images/imageLoader';
import layoutManager from './layoutManager';
2023-10-01 02:49:36 -04:00
import loading from './loading/loading';
2023-04-19 01:56:05 -04:00
2023-10-01 02:49:36 -04:00
import 'elements/emby-itemscontainer/emby-itemscontainer';
2023-04-19 01:56:05 -04:00
2023-10-01 02:49:36 -04:00
import 'styles/scrollstyles.scss';
2023-04-19 01:56:05 -04:00
2023-10-01 02:49:36 -04:00
function enableScrollX() {
return !layoutManager.desktop;
2023-04-19 01:56:05 -04:00
}
function getSections() {
return [{
name: 'Movies',
types: 'Movie',
id: 'favoriteMovies',
2023-10-01 02:49:36 -04:00
shape: getPortraitShape(enableScrollX()),
2023-04-19 01:56:05 -04:00
showTitle: false,
overlayPlayButton: true
}, {
name: 'Shows',
types: 'Series',
id: 'favoriteShows',
2023-10-01 02:49:36 -04:00
shape: getPortraitShape(enableScrollX()),
2023-04-19 01:56:05 -04:00
showTitle: false,
overlayPlayButton: true
}, {
name: 'Episodes',
types: 'Episode',
id: 'favoriteEpisode',
2023-10-01 02:49:36 -04:00
shape: getBackdropShape(enableScrollX()),
2023-04-19 01:56:05 -04:00
preferThumb: false,
showTitle: true,
showParentTitle: true,
overlayPlayButton: true,
overlayText: false,
centerText: true
}, {
name: 'Videos',
types: 'Video,MusicVideo',
id: 'favoriteVideos',
2023-10-01 02:49:36 -04:00
shape: getBackdropShape(enableScrollX()),
2023-04-19 01:56:05 -04:00
preferThumb: true,
showTitle: true,
overlayPlayButton: true,
overlayText: false,
centerText: true
}, {
name: 'Artists',
types: 'MusicArtist',
id: 'favoriteArtists',
2023-10-01 02:49:36 -04:00
shape: getSquareShape(enableScrollX()),
2023-04-19 01:56:05 -04:00
preferThumb: false,
showTitle: true,
overlayText: false,
showParentTitle: false,
centerText: true,
overlayPlayButton: true,
coverImage: true
}, {
name: 'Albums',
types: 'MusicAlbum',
id: 'favoriteAlbums',
2023-10-01 02:49:36 -04:00
shape: getSquareShape(enableScrollX()),
2023-04-19 01:56:05 -04:00
preferThumb: false,
showTitle: true,
overlayText: false,
showParentTitle: true,
centerText: true,
overlayPlayButton: true,
coverImage: true
}, {
name: 'Songs',
types: 'Audio',
id: 'favoriteSongs',
2023-10-01 02:49:36 -04:00
shape: getSquareShape(enableScrollX()),
2023-04-19 01:56:05 -04:00
preferThumb: false,
showTitle: true,
overlayText: false,
showParentTitle: true,
centerText: true,
overlayMoreButton: true,
action: 'instantmix',
coverImage: true
}];
}
function loadSection(elem, userId, topParentId, section, isSingleSection) {
const screenWidth = dom.getWindowSize().innerWidth;
const options = {
SortBy: 'SortName',
SortOrder: 'Ascending',
Filters: 'IsFavorite',
Recursive: true,
2024-01-11 02:24:16 -05:00
Fields: 'PrimaryImageAspectRatio',
2023-04-19 01:56:05 -04:00
CollapseBoxSetItems: false,
ExcludeLocationTypes: 'Virtual',
EnableTotalRecordCount: false
};
if (topParentId) {
options.ParentId = topParentId;
2018-10-23 01:05:09 +03:00
}
2023-04-19 01:56:05 -04:00
if (!isSingleSection) {
options.Limit = 6;
2018-10-23 01:05:09 +03:00
2023-04-19 01:56:05 -04:00
if (enableScrollX()) {
options.Limit = 20;
} else if (screenWidth >= 1920) {
options.Limit = 10;
} else if (screenWidth >= 1440) {
options.Limit = 8;
}
2018-10-23 01:05:09 +03:00
}
2023-04-19 01:56:05 -04:00
let promise;
2018-10-23 01:05:09 +03:00
2023-04-19 01:56:05 -04:00
if (section.types === 'MusicArtist') {
promise = ApiClient.getArtists(userId, options);
} else {
options.IncludeItemTypes = section.types;
promise = ApiClient.getItems(userId, options);
2018-10-23 01:05:09 +03:00
}
2023-04-19 01:56:05 -04:00
return promise.then(function (result) {
let html = '';
if (result.Items.length) {
html += '<div class="sectionTitleContainer sectionTitleContainer-cards padded-left">';
if (!layoutManager.tv && options.Limit && result.Items.length >= options.Limit) {
html += '<a is="emby-linkbutton" href="' + ('#/list.html?serverId=' + ApiClient.serverId() + '&type=' + section.types + '&IsFavorite=true') + '" class="more button-flat button-flat-mini sectionTitleTextButton">';
html += '<h2 class="sectionTitle sectionTitle-cards">';
html += globalize.translate(section.name);
html += '</h2>';
html += '<span class="material-icons chevron_right" aria-hidden="true"></span>';
html += '</a>';
} else {
html += '<h2 class="sectionTitle sectionTitle-cards">' + globalize.translate(section.name) + '</h2>';
2019-10-09 19:23:47 +03:00
}
2023-04-19 01:56:05 -04:00
html += '</div>';
if (enableScrollX()) {
let scrollXClass = 'scrollX hiddenScrollX';
if (layoutManager.tv) {
scrollXClass += ' smoothScrollX';
2019-10-09 19:23:47 +03:00
}
2023-04-19 01:56:05 -04:00
html += '<div is="emby-itemscontainer" class="itemsContainer ' + scrollXClass + ' padded-left padded-right">';
} else {
html += '<div is="emby-itemscontainer" class="itemsContainer vertical-wrap padded-left padded-right">';
2018-10-23 01:05:09 +03:00
}
2019-10-09 19:23:47 +03:00
2023-04-19 01:56:05 -04:00
let cardLayout = appHost.preferVisualCards && section.autoCardLayout && section.showTitle;
cardLayout = false;
html += cardBuilder.getCardsHtml(result.Items, {
preferThumb: section.preferThumb,
shape: section.shape,
centerText: section.centerText && !cardLayout,
overlayText: section.overlayText !== false,
showTitle: section.showTitle,
showParentTitle: section.showParentTitle,
scalable: true,
coverImage: section.coverImage,
overlayPlayButton: section.overlayPlayButton,
overlayMoreButton: section.overlayMoreButton && !cardLayout,
action: section.action,
allowBottomPadding: !enableScrollX(),
cardLayout: cardLayout
2019-10-09 19:23:47 +03:00
});
2023-04-19 01:56:05 -04:00
html += '</div>';
2019-10-09 19:23:47 +03:00
}
2023-04-19 01:56:05 -04:00
elem.innerHTML = html;
imageLoader.lazyChildren(elem);
});
}
2019-10-09 19:23:47 +03:00
2023-04-19 01:56:05 -04:00
export function loadSections(page, userId, topParentId, types) {
loading.show();
let sections = getSections();
const sectionid = getParameterByName('sectionid');
2019-10-09 19:23:47 +03:00
2023-04-19 01:56:05 -04:00
if (sectionid) {
sections = sections.filter(function (s) {
return s.id === sectionid;
});
}
2019-10-09 19:23:47 +03:00
2023-04-19 01:56:05 -04:00
if (types) {
sections = sections.filter(function (s) {
return types.indexOf(s.id) !== -1;
});
}
2019-10-09 19:23:47 +03:00
2023-04-19 01:56:05 -04:00
let elem = page.querySelector('.favoriteSections');
2019-10-09 19:23:47 +03:00
2023-04-19 01:56:05 -04:00
if (!elem.innerHTML) {
let html = '';
2019-10-09 19:23:47 +03:00
for (let i = 0, length = sections.length; i < length; i++) {
2023-04-19 01:56:05 -04:00
html += '<div class="verticalSection section' + sections[i].id + '"></div>';
2018-10-23 01:05:09 +03:00
}
2019-10-09 19:23:47 +03:00
2023-04-19 01:56:05 -04:00
elem.innerHTML = html;
}
const promises = [];
for (let i = 0, length = sections.length; i < length; i++) {
const section = sections[i];
elem = page.querySelector('.section' + section.id);
promises.push(loadSection(elem, userId, topParentId, section, sections.length === 1));
2018-10-23 01:05:09 +03:00
}
2019-10-09 19:23:47 +03:00
2023-04-19 01:56:05 -04:00
Promise.all(promises).then(function () {
loading.hide();
});
}
export default {
render: loadSections
};