diff --git a/src/apps/experimental/components/library/SortButton.tsx b/src/apps/experimental/components/library/SortButton.tsx index 2c7425f0de..237cd3da8a 100644 --- a/src/apps/experimental/components/library/SortButton.tsx +++ b/src/apps/experimental/components/library/SortButton.tsx @@ -16,18 +16,89 @@ import { LibraryTab } from 'types/libraryTab'; import { ItemSortBy } from '@jellyfin/sdk/lib/models/api/item-sort-by'; import { SortOrder } from '@jellyfin/sdk/lib/generated-client'; -const sortMenuOptions = [ - { label: 'Name', value: ItemSortBy.SortName }, - { label: 'OptionRandom', value: ItemSortBy.Random }, - { label: 'OptionImdbRating', value: ItemSortBy.CommunityRating }, - { label: 'OptionCriticRating', value: ItemSortBy.CriticRating }, - { label: 'OptionDateAdded', value: ItemSortBy.DateCreated }, - { label: 'OptionDatePlayed', value: ItemSortBy.DatePlayed }, - { label: 'OptionParentalRating', value: ItemSortBy.OfficialRating }, - { label: 'OptionPlayCount', value: ItemSortBy.PlayCount }, - { label: 'OptionReleaseDate', value: ItemSortBy.PremiereDate }, - { label: 'Runtime', value: ItemSortBy.Runtime } -]; +type SortOption = { + label: string; + value: ItemSortBy; +}; + +type SortOptionsMapping = { + [key: string]: SortOption[]; +}; + +const getMoviesOrFavoritesOptions = () => { + return [ + { label: 'Name', value: ItemSortBy.SortName }, + { label: 'OptionRandom', value: ItemSortBy.Random }, + { label: 'OptionImdbRating', value: ItemSortBy.CommunityRating }, + { label: 'OptionCriticRating', value: ItemSortBy.CriticRating }, + { label: 'OptionDateAdded', value: ItemSortBy.DateCreated }, + { label: 'OptionDatePlayed', value: ItemSortBy.DatePlayed }, + { label: 'OptionParentalRating', value: ItemSortBy.OfficialRating }, + { label: 'OptionPlayCount', value: ItemSortBy.PlayCount }, + { label: 'OptionReleaseDate', value: ItemSortBy.PremiereDate }, + { label: 'Runtime', value: ItemSortBy.Runtime } + ]; +}; + +const sortOptionsMapping: SortOptionsMapping = { + [LibraryTab.Movies]: getMoviesOrFavoritesOptions(), + [LibraryTab.Trailers]: [ + { label: 'Name', value: ItemSortBy.SortName }, + { label: 'OptionImdbRating', value: ItemSortBy.CommunityRating }, + { label: 'OptionDateAdded', value: ItemSortBy.DateCreated }, + { label: 'OptionDatePlayed', value: ItemSortBy.DatePlayed }, + { label: 'OptionParentalRating', value: ItemSortBy.OfficialRating }, + { label: 'OptionPlayCount', value: ItemSortBy.PlayCount }, + { label: 'OptionReleaseDate', value: ItemSortBy.PremiereDate } + ], + [LibraryTab.Favorites]: getMoviesOrFavoritesOptions(), + [LibraryTab.Series]: [ + { label: 'Name', value: ItemSortBy.SortName }, + { label: 'OptionRandom', value: ItemSortBy.Random }, + { label: 'OptionImdbRating', value: ItemSortBy.CommunityRating }, + { label: 'OptionDateShowAdded', value: ItemSortBy.DateCreated }, + { label: 'OptionDateEpisodeAdded', value: ItemSortBy.DateLastContentAdded }, + { label: 'OptionDatePlayed', value: ItemSortBy.SeriesDatePlayed }, + { label: 'OptionParentalRating', value: ItemSortBy.OfficialRating }, + { label: 'OptionReleaseDate', value: ItemSortBy.PremiereDate } + ], + [LibraryTab.Episodes]: [ + { label: 'Name', value: ItemSortBy.SeriesSortName }, + { label: 'OptionImdbRating', value: ItemSortBy.CommunityRating }, + { label: 'OptionDateAdded', value: ItemSortBy.DateCreated }, + { label: 'OptionReleaseDate', value: ItemSortBy.PremiereDate }, + { label: 'OptionDatePlayed', value: ItemSortBy.DatePlayed }, + { label: 'OptionParentalRating', value: ItemSortBy.OfficialRating }, + { label: 'OptionPlayCount', value: ItemSortBy.PlayCount }, + { label: 'Runtime', value: ItemSortBy.Runtime }, + { label: 'OptionRandom', value: ItemSortBy.Random } + ], + [LibraryTab.Albums]: [ + { label: 'Name', value: ItemSortBy.SortName }, + { label: 'OptionRandom', value: ItemSortBy.Random }, + { label: 'AlbumArtist', value: ItemSortBy.AlbumArtist }, + { label: 'OptionImdbRating', value: ItemSortBy.CommunityRating }, + { label: 'OptionCriticRating', value: ItemSortBy.CriticRating }, + { label: 'OptionReleaseDate', value: ItemSortBy.ProductionYear }, + { label: 'OptionDateAdded', value: ItemSortBy.DateCreated } + ], + [LibraryTab.Songs]: [ + { label: 'Name', value: ItemSortBy.SortName }, + { label: 'Album', value: ItemSortBy.Album }, + { label: 'AlbumArtist', value: ItemSortBy.AlbumArtist }, + { label: 'Artist', value: ItemSortBy.Artist }, + { label: 'OptionDateAdded', value: ItemSortBy.DateCreated }, + { label: 'OptionDatePlayed', value: ItemSortBy.DatePlayed }, + { label: 'OptionPlayCount', value: ItemSortBy.PlayCount }, + { label: 'OptionReleaseDate', value: ItemSortBy.PremiereDate }, + { label: 'Runtime', value: ItemSortBy.Runtime }, + { label: 'OptionRandom', value: ItemSortBy.Random } + ] +}; + +const getSortMenuOptions = (viewType: LibraryTab): SortOption[] => { + return sortOptionsMapping[viewType] || []; +}; const sortOrderMenuOptions = [ { label: 'Ascending', value: SortOrder.Ascending }, @@ -72,25 +143,7 @@ const SortButton: FC = ({ [setLibraryViewSettings] ); - const getVisibleSortMenu = () => { - const visibleSortMenu: ItemSortBy[] = [ItemSortBy.SortName, ItemSortBy.Random, ItemSortBy.DateCreated]; - - if ( - viewType !== LibraryTab.Photos - && viewType !== LibraryTab.Videos - && viewType !== LibraryTab.Books - ) { - visibleSortMenu.push(ItemSortBy.CommunityRating); - visibleSortMenu.push(ItemSortBy.CriticRating); - visibleSortMenu.push(ItemSortBy.DatePlayed); - visibleSortMenu.push(ItemSortBy.OfficialRating); - visibleSortMenu.push(ItemSortBy.PlayCount); - visibleSortMenu.push(ItemSortBy.PremiereDate); - visibleSortMenu.push(ItemSortBy.Runtime); - } - - return visibleSortMenu; - }; + const sortMenuOptions = getSortMenuOptions(viewType); return ( @@ -120,7 +173,6 @@ const SortButton: FC = ({ '& .MuiFormControl-root': { m: 1, width: 200 } }} > - @@ -136,7 +188,6 @@ const SortButton: FC = ({ onChange={onSelectChange} > {sortMenuOptions - .filter((option) => getVisibleSortMenu().includes(option.value)) .map((option) => ( = ({ onChange={onSelectChange} > {sortOrderMenuOptions.map((option) => ( - + {option.label} diff --git a/src/utils/items.ts b/src/utils/items.ts index b80c8ed057..8510fabac6 100644 --- a/src/utils/items.ts +++ b/src/utils/items.ts @@ -144,6 +144,14 @@ export const getSettingsKey = (viewType: LibraryTab, parentId: ParentId) => { return `${viewType} - ${parentId}`; }; +export const getDefaultSortBy = (viewType: LibraryTab) => { + if (viewType === LibraryTab.Episodes ) { + return ItemSortBy.SeriesSortName; + } + + return ItemSortBy.SortName; +}; + export const getDefaultLibraryViewSettings = (viewType: LibraryTab): LibraryViewSettings => { return { ShowTitle: true, @@ -151,7 +159,7 @@ export const getDefaultLibraryViewSettings = (viewType: LibraryTab): LibraryView ViewMode: viewType === LibraryTab.Songs ? ViewMode.ListView : ViewMode.GridView, ImageType: viewType === LibraryTab.Networks ? ImageType.Thumb : ImageType.Primary, CardLayout: false, - SortBy: ItemSortBy.SortName, + SortBy: getDefaultSortBy(viewType), SortOrder: SortOrder.Ascending, StartIndex: 0 };