Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add music view #4919

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions src/apps/experimental/components/library/ItemsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { CollectionType } from 'types/collectionType';
import { LibraryTab } from 'types/libraryTab';

import { CardOptions } from 'types/cardOptions';
import { ListOptions } from 'types/listOptions';

interface ItemsViewProps {
viewType: LibraryTab;
Expand Down Expand Up @@ -77,12 +78,33 @@ const ItemsView: FC<ItemsViewProps> = ({
);
const { data: item } = useGetItem(parentId);

const getListOptions = useCallback(() => {
const listOptions: ListOptions = {
items: itemsResult?.Items ?? [],
context: collectionType
};

if (viewType === LibraryTab.Songs) {
listOptions.showParentTitle = true;
listOptions.action = 'playallfromhere';
listOptions.smallIcon = true;
listOptions.artist = true;
listOptions.addToListButton = true;
} else if (viewType === LibraryTab.Albums) {
listOptions.sortBy = libraryViewSettings.SortBy;
listOptions.addToListButton = true;
} else if (viewType === LibraryTab.Episodes) {
listOptions.showParentTitle = true;
}

return listOptions;
}, [itemsResult?.Items, collectionType, viewType, libraryViewSettings.SortBy]);

const getCardOptions = useCallback(() => {
let shape;
let preferThumb;
let preferDisc;
let preferLogo;
let lines = libraryViewSettings.ShowTitle ? 2 : 0;

if (libraryViewSettings.ImageType === ImageType.Banner) {
shape = 'banner';
Expand Down Expand Up @@ -122,12 +144,9 @@ const ItemsView: FC<ItemsViewProps> = ({
) {
cardOptions.showParentTitle = libraryViewSettings.ShowTitle;
} else if (viewType === LibraryTab.Artists) {
cardOptions.showYear = false;
lines = 1;
cardOptions.lines = 1;
}

cardOptions.lines = lines;

return cardOptions;
}, [
libraryViewSettings.ShowTitle,
Expand All @@ -142,10 +161,7 @@ const ItemsView: FC<ItemsViewProps> = ({
let html = '';

if (libraryViewSettings.ViewMode === ViewMode.ListView) {
html = listview.getListViewHtml({
items: itemsResult?.Items ?? [],
context: collectionType
});
html = listview.getListViewHtml(getListOptions());
} else {
html = cardBuilder.getCardsHtml(
itemsResult?.Items ?? [],
Expand All @@ -161,13 +177,7 @@ const ItemsView: FC<ItemsViewProps> = ({
}

return html;
}, [
libraryViewSettings.ViewMode,
itemsResult?.Items,
collectionType,
getCardOptions,
noItemsMessage
]);
}, [libraryViewSettings.ViewMode, itemsResult?.Items, getListOptions, getCardOptions, noItemsMessage]);

const totalRecordCount = itemsResult?.TotalRecordCount ?? 0;
const items = itemsResult?.Items ?? [];
Expand Down
3 changes: 2 additions & 1 deletion src/apps/experimental/routes/asyncRoutes/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export const ASYNC_USER_ROUTES: AsyncRoute[] = [
{ path: 'userprofile.html', page: 'user/userprofile' },
{ path: 'home.html', page: 'home', type: AsyncRouteType.Experimental },
{ path: 'movies.html', page: 'movies', type: AsyncRouteType.Experimental },
{ path: 'tv.html', page: 'shows', type: AsyncRouteType.Experimental }
{ path: 'tv.html', page: 'shows', type: AsyncRouteType.Experimental },
{ path: 'music.html', page: 'music', type: AsyncRouteType.Experimental }
];
6 changes: 0 additions & 6 deletions src/apps/experimental/routes/legacyRoutes/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ export const LEGACY_USER_ROUTES: LegacyRoute[] = [
controller: 'livetv/livetvsuggested',
view: 'livetv.html'
}
}, {
path: 'music.html',
pageProps: {
controller: 'music/musicrecommended',
view: 'music/music.html'
}
}, {
path: 'mypreferencesmenu.html',
pageProps: {
Expand Down
94 changes: 94 additions & 0 deletions src/apps/experimental/routes/music/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { BaseItemKind } from '@jellyfin/sdk/lib/generated-client/models/base-item-kind';
import React, { FC } from 'react';
import useCurrentTab from 'hooks/useCurrentTab';
import Page from 'components/Page';
import PageTabContent from '../../components/library/PageTabContent';
import { LibraryTab } from 'types/libraryTab';
import { CollectionType } from 'types/collectionType';
import { LibraryTabContent, LibraryTabMapping } from 'types/libraryTabContent';
import { SectionsView } from 'types/suggestionsSections';

const albumArtistsTabContent: LibraryTabContent = {
viewType: LibraryTab.AlbumArtists,
collectionType: CollectionType.Music,
isBtnSortEnabled: false
};

const albumsTabContent: LibraryTabContent = {
viewType: LibraryTab.Albums,
collectionType: CollectionType.Music,
isBtnPlayAllEnabled: true,
isBtnShuffleEnabled: true,
itemType: [BaseItemKind.MusicAlbum]
};

const artistsTabContent: LibraryTabContent = {
viewType: LibraryTab.Artists,
collectionType: CollectionType.Music,
isBtnSortEnabled: false
};

const playlistsTabContent: LibraryTabContent = {
viewType: LibraryTab.Playlists,
isBtnFilterEnabled: false,
isBtnGridListEnabled: false,
isBtnSortEnabled: false,
isAlphabetPickerEnabled: false,
itemType: [BaseItemKind.Playlist]
};

const songsTabContent: LibraryTabContent = {
viewType: LibraryTab.Songs,
isBtnGridListEnabled: false,
isAlphabetPickerEnabled: false,
itemType: [BaseItemKind.Audio]
};

const suggestionsTabContent: LibraryTabContent = {
viewType: LibraryTab.Suggestions,
collectionType: CollectionType.Music,
sectionsType: {
suggestionSectionsView: [
SectionsView.LatestMusic,
SectionsView.FrequentlyPlayedMusic,
SectionsView.RecentlyPlayedMusic
]
}
};

const genresTabContent: LibraryTabContent = {
viewType: LibraryTab.Genres,
collectionType: CollectionType.Music,
itemType: [BaseItemKind.MusicAlbum]
};

const musicTabMapping: LibraryTabMapping = {
0: albumsTabContent,
1: suggestionsTabContent,
2: albumArtistsTabContent,
3: artistsTabContent,
4: playlistsTabContent,
5: songsTabContent,
6: genresTabContent
};

const Music: FC = () => {
const { searchParamsParentId, currentTabIndex } = useCurrentTab();
const currentTab = musicTabMapping[currentTabIndex];

return (
<Page
id='musicPage'
className='mainAnimatedPage libraryPage backdropPage collectionEditorPage pageWithAbsoluteTabs withTabs'
backDropType='musicartist'
>
<PageTabContent
key={`${currentTab.viewType} - ${searchParamsParentId}`}
currentTab={currentTab}
parentId={searchParamsParentId}
/>
</Page>
);
};

export default Music;
49 changes: 49 additions & 0 deletions src/types/listOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { BaseItemDto } from '@jellyfin/sdk/lib/generated-client';
import { ItemSortBy } from '@jellyfin/sdk/lib/models/api/item-sort-by';
import { CollectionType } from './collectionType';

export interface ListOptions {
items?: BaseItemDto[] | null;
index?: string;
showIndex?: boolean;
action?: string | null;
imageSize?: string;
enableOverview?: boolean;
enableSideMediaInfo?: boolean;
playlistId?: string | null;
collectionId?: string | null;
context?: CollectionType;
parentId?: string | null;
border?: boolean;
highlight?: boolean;
dragHandle?: boolean;
showIndexNumberLeft?: boolean;
mediaInfo?: boolean;
recordButton?: boolean;
image?: boolean;
imageSource?: string;
defaultCardImageIcon?: string;
disableIndicators?: boolean;
imagePlayButton?: boolean;
showProgramDateTime?: boolean;
showProgramTime?: boolean;
showChannel?: boolean;
showParentTitle?: boolean;
showIndexNumber?: boolean;
parentTitleWithTitle?: boolean;
artist?: boolean;
includeParentInfoInTitle?: boolean;
addToListButton?: boolean;
infoButton?: boolean;
enableUserDataButtons?: boolean;
moreButton?: boolean;
rightButtons?: {
icon: string;
title: string;
id: string;
}[];
enablePlayedButton?: boolean;
enableRatingButton?: boolean;
smallIcon?: boolean;
sortBy?: ItemSortBy;
}
Loading