refactor domain types to rename itemType

This commit is contained in:
jeffvli
2025-11-13 22:04:00 -08:00
parent 8c4e9895e6
commit 895dc19736
9 changed files with 54 additions and 40 deletions
@@ -15,8 +15,8 @@ const hasRequiredDragProperties = (
item !== null && item !== null &&
'id' in item && 'id' in item &&
typeof (item as any).id === 'string' && typeof (item as any).id === 'string' &&
'itemType' in item && '_itemType' in item &&
typeof (item as any).itemType === 'string' && typeof (item as any)._itemType === 'string' &&
'_serverId' in item && '_serverId' in item &&
typeof (item as any)._serverId === 'string' typeof (item as any)._serverId === 'string'
); );
@@ -87,7 +87,7 @@ export const useDefaultItemListControls = () => {
rangeItem && rangeItem &&
typeof rangeItem === 'object' && typeof rangeItem === 'object' &&
'_serverId' in rangeItem && '_serverId' in rangeItem &&
'itemType' in rangeItem '_itemType' in rangeItem
) { ) {
const rangeRowId = internalState.extractRowId(rangeItem); const rangeRowId = internalState.extractRowId(rangeItem);
if (rangeRowId) { if (rangeRowId) {
@@ -73,15 +73,15 @@ export interface ItemListStateActions {
} }
export interface ItemListStateItem { export interface ItemListStateItem {
_itemType: LibraryItem;
_serverId: string; _serverId: string;
id: string; id: string;
itemType: LibraryItem;
} }
export type ItemListStateItemWithRequiredProperties = Record<string, unknown> & { export type ItemListStateItemWithRequiredProperties = Record<string, unknown> & {
_itemType: LibraryItem;
_serverId: string; _serverId: string;
id: string; id: string;
itemType: LibraryItem;
}; };
/** /**
@@ -36,8 +36,8 @@ export const ActionsColumn = (props: ItemTableListInnerColumn) => {
color: 'muted', color: 'muted',
size: 'md', size: 'md',
}} }}
onDoubleClick={handleActionDoubleClick}
onClick={handleActionClick} onClick={handleActionClick}
onDoubleClick={handleActionDoubleClick}
size="xs" size="xs"
variant="subtle" variant="subtle"
/> />
@@ -70,8 +70,8 @@ const hasRequiredStateItemProperties = (
typeof (item as any).id === 'string' && typeof (item as any).id === 'string' &&
'_serverId' in item && '_serverId' in item &&
typeof (item as any)._serverId === 'string' && typeof (item as any)._serverId === 'string' &&
'itemType' in item && '_itemType' in item &&
typeof (item as any).itemType === 'string' && typeof (item as any)._itemType === 'string' &&
'rowId' in item && 'rowId' in item &&
typeof (item as any).rowId === 'string' typeof (item as any).rowId === 'string'
); );
@@ -1126,7 +1126,7 @@ export const ItemTableList = ({
typeof item === 'object' && typeof item === 'object' &&
item !== null && item !== null &&
'_serverId' in item && '_serverId' in item &&
'itemType' in item '_itemType' in item
) { ) {
return item as ItemListStateItemWithRequiredProperties; return item as ItemListStateItemWithRequiredProperties;
} }
+17 -9
View File
@@ -227,6 +227,7 @@ const normalizeSong = (
} }
return { return {
_itemType: LibraryItem.SONG,
_serverId: server?.id || '', _serverId: server?.id || '',
_serverType: ServerType.JELLYFIN, _serverType: ServerType.JELLYFIN,
album: item.Album, album: item.Album,
@@ -265,15 +266,16 @@ const normalizeSong = (
} }
: null, : null,
genres: item.GenreItems?.map((entry) => ({ genres: item.GenreItems?.map((entry) => ({
_itemType: LibraryItem.GENRE,
_serverId: server?.id || '',
_serverType: ServerType.JELLYFIN,
id: entry.Id, id: entry.Id,
imageUrl: null, imageUrl: null,
itemType: LibraryItem.GENRE,
name: entry.Name, name: entry.Name,
})), })),
id: item.Id, id: item.Id,
imagePlaceholderUrl: null, imagePlaceholderUrl: null,
imageUrl: getSongCoverArtUrl({ baseUrl: server?.url || '', item, size: imageSize || 100 }), imageUrl: getSongCoverArtUrl({ baseUrl: server?.url || '', item, size: imageSize || 100 }),
itemType: LibraryItem.SONG,
lastPlayedAt: null, lastPlayedAt: null,
lyrics: null, lyrics: null,
mbzRecordingId: null, mbzRecordingId: null,
@@ -307,6 +309,7 @@ const normalizeAlbum = (
imageSize?: number, imageSize?: number,
): Album => { ): Album => {
return { return {
_itemType: LibraryItem.ALBUM,
_serverId: server?.id || '', _serverId: server?.id || '',
_serverType: ServerType.JELLYFIN, _serverType: ServerType.JELLYFIN,
albumArtist: item.AlbumArtist, albumArtist: item.AlbumArtist,
@@ -327,9 +330,11 @@ const normalizeAlbum = (
duration: item.RunTimeTicks / 10000, duration: item.RunTimeTicks / 10000,
explicitStatus: null, explicitStatus: null,
genres: item.GenreItems?.map((entry) => ({ genres: item.GenreItems?.map((entry) => ({
_itemType: LibraryItem.GENRE,
_serverId: server?.id || '',
_serverType: ServerType.JELLYFIN,
id: entry.Id, id: entry.Id,
imageUrl: null, imageUrl: null,
itemType: LibraryItem.GENRE,
name: entry.Name, name: entry.Name,
})), })),
id: item.Id, id: item.Id,
@@ -340,7 +345,6 @@ const normalizeAlbum = (
size: imageSize || 300, size: imageSize || 300,
}), }),
isCompilation: null, isCompilation: null,
itemType: LibraryItem.ALBUM,
lastPlayedAt: null, lastPlayedAt: null,
mbzId: item.ProviderIds?.MusicBrainzAlbum || null, mbzId: item.ProviderIds?.MusicBrainzAlbum || null,
name: item.Name, name: item.Name,
@@ -383,6 +387,7 @@ const normalizeAlbumArtist = (
) || []; ) || [];
return { return {
_itemType: LibraryItem.ALBUM_ARTIST,
_serverId: server?.id || '', _serverId: server?.id || '',
_serverType: ServerType.JELLYFIN, _serverType: ServerType.JELLYFIN,
albumCount: item.AlbumCount ?? null, albumCount: item.AlbumCount ?? null,
@@ -390,9 +395,11 @@ const normalizeAlbumArtist = (
biography: item.Overview || null, biography: item.Overview || null,
duration: item.RunTimeTicks / 10000, duration: item.RunTimeTicks / 10000,
genres: item.GenreItems?.map((entry) => ({ genres: item.GenreItems?.map((entry) => ({
_itemType: LibraryItem.GENRE,
_serverId: server?.id || '',
_serverType: ServerType.JELLYFIN,
id: entry.Id, id: entry.Id,
imageUrl: null, imageUrl: null,
itemType: LibraryItem.GENRE,
name: entry.Name, name: entry.Name,
})), })),
id: item.Id, id: item.Id,
@@ -401,7 +408,6 @@ const normalizeAlbumArtist = (
item, item,
size: imageSize || 300, size: imageSize || 300,
}), }),
itemType: LibraryItem.ALBUM_ARTIST,
lastPlayedAt: null, lastPlayedAt: null,
mbz: item.ProviderIds?.MusicBrainzArtist || null, mbz: item.ProviderIds?.MusicBrainzArtist || null,
name: item.Name, name: item.Name,
@@ -427,20 +433,22 @@ const normalizePlaylist = (
const imagePlaceholderUrl = null; const imagePlaceholderUrl = null;
return { return {
_itemType: LibraryItem.PLAYLIST,
_serverId: server?.id || '', _serverId: server?.id || '',
_serverType: ServerType.JELLYFIN, _serverType: ServerType.JELLYFIN,
description: item.Overview || null, description: item.Overview || null,
duration: item.RunTimeTicks / 10000, duration: item.RunTimeTicks / 10000,
genres: item.GenreItems?.map((entry) => ({ genres: item.GenreItems?.map((entry) => ({
_itemType: LibraryItem.GENRE,
_serverId: server?.id || '',
_serverType: ServerType.JELLYFIN,
id: entry.Id, id: entry.Id,
imageUrl: null, imageUrl: null,
itemType: LibraryItem.GENRE,
name: entry.Name, name: entry.Name,
})), })),
id: item.Id, id: item.Id,
imagePlaceholderUrl, imagePlaceholderUrl,
imageUrl: imageUrl || null, imageUrl: imageUrl || null,
itemType: LibraryItem.PLAYLIST,
name: item.Name, name: item.Name,
owner: null, owner: null,
ownerId: null, ownerId: null,
@@ -504,12 +512,12 @@ const normalizeGenre = (
server: null | ServerListItem, server: null | ServerListItem,
): Genre => { ): Genre => {
return { return {
_itemType: LibraryItem.GENRE,
_serverId: server?.id || '', _serverId: server?.id || '',
_serverType: ServerType.JELLYFIN, _serverType: ServerType.JELLYFIN,
albumCount: undefined, albumCount: undefined,
id: item.Id, id: item.Id,
imageUrl: getGenreCoverArtUrl({ baseUrl: server?.url || '', item, size: 200 }), imageUrl: getGenreCoverArtUrl({ baseUrl: server?.url || '', item, size: 200 }),
itemType: LibraryItem.GENRE,
name: item.Name, name: item.Name,
songCount: undefined, songCount: undefined,
}; };
@@ -151,6 +151,7 @@ const normalizeSong = (
album: item.album, album: item.album,
albumId: item.albumId, albumId: item.albumId,
...getArtists(item), ...getArtists(item),
_itemType: LibraryItem.SONG,
_serverId: server?.id || 'unknown', _serverId: server?.id || 'unknown',
_serverType: ServerType.NAVIDROME, _serverType: ServerType.NAVIDROME,
artistName: item.artist, artistName: item.artist,
@@ -176,15 +177,16 @@ const normalizeSong = (
? { album: item.rgAlbumGain, track: item.rgTrackGain } ? { album: item.rgAlbumGain, track: item.rgTrackGain }
: null, : null,
genres: (item.genres || []).map((genre) => ({ genres: (item.genres || []).map((genre) => ({
_itemType: LibraryItem.GENRE,
_serverId: server?.id || 'unknown',
_serverType: ServerType.NAVIDROME,
id: genre.id, id: genre.id,
imageUrl: null, imageUrl: null,
itemType: LibraryItem.GENRE,
name: genre.name, name: genre.name,
})), })),
id, id,
imagePlaceholderUrl, imagePlaceholderUrl,
imageUrl, imageUrl,
itemType: LibraryItem.SONG,
lastPlayedAt: normalizePlayDate(item), lastPlayedAt: normalizePlayDate(item),
lyrics: item.lyrics ? item.lyrics : null, lyrics: item.lyrics ? item.lyrics : null,
mbzRecordingId: item.mbzReleaseTrackId || null, mbzRecordingId: item.mbzReleaseTrackId || null,
@@ -278,6 +280,7 @@ const normalizeAlbum = (
return { return {
...parseAlbumTags(item), ...parseAlbumTags(item),
...getArtists(item), ...getArtists(item),
_itemType: LibraryItem.ALBUM,
_serverId: server?.id || 'unknown', _serverId: server?.id || 'unknown',
_serverType: ServerType.NAVIDROME, _serverType: ServerType.NAVIDROME,
albumArtist: item.albumArtist, albumArtist: item.albumArtist,
@@ -292,17 +295,18 @@ const normalizeAlbum = (
? ExplicitStatus.CLEAN ? ExplicitStatus.CLEAN
: null, : null,
genres: (item.genres || []).map((genre) => ({ genres: (item.genres || []).map((genre) => ({
_itemType: LibraryItem.GENRE,
_serverId: server?.id || 'unknown',
_serverType: ServerType.NAVIDROME,
id: genre.id, id: genre.id,
imageUrl: null, imageUrl: null,
itemType: LibraryItem.GENRE,
name: genre.name, name: genre.name,
})), })),
id: item.id, id: item.id,
imagePlaceholderUrl, imagePlaceholderUrl,
imageUrl, imageUrl,
isCompilation: item.compilation,
itemType: LibraryItem.ALBUM, isCompilation: item.compilation,
lastPlayedAt: normalizePlayDate(item), lastPlayedAt: normalizePlayDate(item),
mbzId: item.mbzAlbumId || null, mbzId: item.mbzAlbumId || null,
name: item.name, name: item.name,
@@ -363,6 +367,7 @@ const normalizeAlbumArtist = (
} }
return { return {
_itemType: LibraryItem.ALBUM_ARTIST,
_serverId: server?.id || 'unknown', _serverId: server?.id || 'unknown',
_serverType: ServerType.NAVIDROME, _serverType: ServerType.NAVIDROME,
albumCount, albumCount,
@@ -370,14 +375,15 @@ const normalizeAlbumArtist = (
biography: item.biography || null, biography: item.biography || null,
duration: null, duration: null,
genres: (item.genres || []).map((genre) => ({ genres: (item.genres || []).map((genre) => ({
_itemType: LibraryItem.GENRE,
_serverId: server?.id || 'unknown',
_serverType: ServerType.NAVIDROME,
id: genre.id, id: genre.id,
imageUrl: null, imageUrl: null,
itemType: LibraryItem.GENRE,
name: genre.name, name: genre.name,
})), })),
id: item.id, id: item.id,
imageUrl: imageUrl || null, imageUrl: imageUrl || null,
itemType: LibraryItem.ALBUM_ARTIST,
lastPlayedAt: normalizePlayDate(item), lastPlayedAt: normalizePlayDate(item),
mbz: item.mbzArtistId || null, mbz: item.mbzArtistId || null,
name: item.name, name: item.name,
@@ -410,6 +416,7 @@ const normalizePlaylist = (
const imagePlaceholderUrl = null; const imagePlaceholderUrl = null;
return { return {
_itemType: LibraryItem.PLAYLIST,
_serverId: server?.id || 'unknown', _serverId: server?.id || 'unknown',
_serverType: ServerType.NAVIDROME, _serverType: ServerType.NAVIDROME,
description: item.comment, description: item.comment,
@@ -418,7 +425,6 @@ const normalizePlaylist = (
id: item.id, id: item.id,
imagePlaceholderUrl, imagePlaceholderUrl,
imageUrl, imageUrl,
itemType: LibraryItem.PLAYLIST,
name: item.name, name: item.name,
owner: item.ownerName, owner: item.ownerName,
ownerId: item.ownerId, ownerId: item.ownerId,
@@ -435,12 +441,12 @@ const normalizeGenre = (
server: null | ServerListItem, server: null | ServerListItem,
): Genre => { ): Genre => {
return { return {
_itemType: LibraryItem.GENRE,
_serverId: server?.id || 'unknown', _serverId: server?.id || 'unknown',
_serverType: ServerType.NAVIDROME, _serverType: ServerType.NAVIDROME,
albumCount: undefined, albumCount: undefined,
id: item.id, id: item.id,
imageUrl: null, imageUrl: null,
itemType: LibraryItem.GENRE,
name: item.name, name: item.name,
songCount: undefined, songCount: undefined,
}; };
@@ -98,21 +98,21 @@ const getGenres = (
): Genre[] => { ): Genre[] => {
return item.genres return item.genres
? item.genres.map((genre) => ({ ? item.genres.map((genre) => ({
_itemType: LibraryItem.GENRE,
_serverId: server?.id || 'unknown', _serverId: server?.id || 'unknown',
_serverType: ServerType.SUBSONIC, _serverType: ServerType.SUBSONIC,
id: genre.name, id: genre.name,
imageUrl: null, imageUrl: null,
itemType: LibraryItem.GENRE,
name: genre.name, name: genre.name,
})) }))
: item.genre : item.genre
? [ ? [
{ {
_itemType: LibraryItem.GENRE,
_serverId: server?.id || 'unknown', _serverId: server?.id || 'unknown',
_serverType: ServerType.SUBSONIC, _serverType: ServerType.SUBSONIC,
id: item.genre, id: item.genre,
imageUrl: null, imageUrl: null,
itemType: LibraryItem.GENRE,
name: item.genre, name: item.genre,
}, },
] ]
@@ -135,6 +135,7 @@ const normalizeSong = (
const streamUrl = `${server?.url}/rest/stream.view?id=${item.id}&v=1.13.0&c=Feishin&${server?.credential}`; const streamUrl = `${server?.url}/rest/stream.view?id=${item.id}&v=1.13.0&c=Feishin&${server?.credential}`;
return { return {
_itemType: LibraryItem.SONG,
_serverId: server?.id || 'unknown', _serverId: server?.id || 'unknown',
_serverType: ServerType.SUBSONIC, _serverType: ServerType.SUBSONIC,
album: item.album || '', album: item.album || '',
@@ -170,7 +171,6 @@ const normalizeSong = (
id: item.id.toString(), id: item.id.toString(),
imagePlaceholderUrl: null, imagePlaceholderUrl: null,
imageUrl, imageUrl,
itemType: LibraryItem.SONG,
lastPlayedAt: null, lastPlayedAt: null,
lyrics: null, lyrics: null,
mbzRecordingId: item.musicBrainzId || null, mbzRecordingId: item.musicBrainzId || null,
@@ -215,6 +215,7 @@ const normalizeAlbumArtist = (
}) || null; }) || null;
return { return {
_itemType: LibraryItem.ALBUM_ARTIST,
_serverId: server?.id || 'unknown', _serverId: server?.id || 'unknown',
_serverType: ServerType.SUBSONIC, _serverType: ServerType.SUBSONIC,
albumCount: item.albumCount ? Number(item.albumCount) : 0, albumCount: item.albumCount ? Number(item.albumCount) : 0,
@@ -224,7 +225,6 @@ const normalizeAlbumArtist = (
genres: [], genres: [],
id: item.id.toString(), id: item.id.toString(),
imageUrl, imageUrl,
itemType: LibraryItem.ALBUM_ARTIST,
lastPlayedAt: null, lastPlayedAt: null,
mbz: null, mbz: null,
name: item.name, name: item.name,
@@ -250,6 +250,7 @@ const normalizeAlbum = (
}) || null; }) || null;
return { return {
_itemType: LibraryItem.ALBUM,
_serverId: server?.id || 'unknown', _serverId: server?.id || 'unknown',
_serverType: ServerType.SUBSONIC, _serverType: ServerType.SUBSONIC,
albumArtist: item.artist, albumArtist: item.artist,
@@ -270,7 +271,6 @@ const normalizeAlbum = (
imagePlaceholderUrl: null, imagePlaceholderUrl: null,
imageUrl, imageUrl,
isCompilation: null, isCompilation: null,
itemType: LibraryItem.ALBUM,
lastPlayedAt: null, lastPlayedAt: null,
mbzId: null, mbzId: null,
name: item.name, name: item.name,
@@ -302,6 +302,7 @@ const normalizePlaylist = (
server?: null | ServerListItemWithCredential, server?: null | ServerListItemWithCredential,
): Playlist => { ): Playlist => {
return { return {
_itemType: LibraryItem.PLAYLIST,
_serverId: server?.id || 'unknown', _serverId: server?.id || 'unknown',
_serverType: ServerType.SUBSONIC, _serverType: ServerType.SUBSONIC,
description: item.comment || null, description: item.comment || null,
@@ -315,7 +316,6 @@ const normalizePlaylist = (
credential: server?.credential, credential: server?.credential,
size: 300, size: 300,
}), }),
itemType: LibraryItem.PLAYLIST,
name: item.name, name: item.name,
owner: item.owner, owner: item.owner,
ownerId: item.owner, ownerId: item.owner,
@@ -330,12 +330,12 @@ const normalizeGenre = (
server: null | ServerListItemWithCredential, server: null | ServerListItemWithCredential,
): Genre => { ): Genre => {
return { return {
_itemType: LibraryItem.GENRE,
_serverId: server?.id || 'unknown', _serverId: server?.id || 'unknown',
_serverType: ServerType.SUBSONIC, _serverType: ServerType.SUBSONIC,
albumCount: item.albumCount, albumCount: item.albumCount,
id: item.value, id: item.value,
imageUrl: null, imageUrl: null,
itemType: LibraryItem.GENRE,
name: item.value, name: item.value,
songCount: item.songCount, songCount: item.songCount,
}; };
+6 -6
View File
@@ -164,6 +164,7 @@ export enum ImageType {
} }
export type Album = { export type Album = {
_itemType: LibraryItem.ALBUM;
_serverId: string; _serverId: string;
_serverType: ServerType; _serverType: ServerType;
albumArtist: string; albumArtist: string;
@@ -179,7 +180,6 @@ export type Album = {
imagePlaceholderUrl: null | string; imagePlaceholderUrl: null | string;
imageUrl: null | string; imageUrl: null | string;
isCompilation: boolean | null; isCompilation: boolean | null;
itemType: LibraryItem.ALBUM;
lastPlayedAt: null | string; lastPlayedAt: null | string;
mbzId: null | string; mbzId: null | string;
name: string; name: string;
@@ -201,6 +201,7 @@ export type Album = {
} & { songs?: Song[] }; } & { songs?: Song[] };
export type AlbumArtist = { export type AlbumArtist = {
_itemType: LibraryItem.ALBUM_ARTIST;
_serverId: string; _serverId: string;
_serverType: ServerType; _serverType: ServerType;
albumCount: null | number; albumCount: null | number;
@@ -210,7 +211,6 @@ export type AlbumArtist = {
genres: Genre[]; genres: Genre[];
id: string; id: string;
imageUrl: null | string; imageUrl: null | string;
itemType: LibraryItem.ALBUM_ARTIST;
lastPlayedAt: null | string; lastPlayedAt: null | string;
mbz: null | string; mbz: null | string;
name: string; name: string;
@@ -222,12 +222,12 @@ export type AlbumArtist = {
}; };
export type Artist = { export type Artist = {
_itemType: LibraryItem.ARTIST;
_serverId: string; _serverId: string;
_serverType: ServerType; _serverType: ServerType;
biography: null | string; biography: null | string;
createdAt: string; createdAt: string;
id: string; id: string;
itemType: LibraryItem.ARTIST;
name: string; name: string;
remoteCreatedAt: null | string; remoteCreatedAt: null | string;
updatedAt: string; updatedAt: string;
@@ -262,12 +262,12 @@ export type GainInfo = {
}; };
export type Genre = { export type Genre = {
_itemType: LibraryItem.GENRE;
_serverId: string; _serverId: string;
_serverType: ServerType; _serverType: ServerType;
albumCount?: number; albumCount?: number;
id: string; id: string;
imageUrl: null | string; imageUrl: null | string;
itemType: LibraryItem.GENRE;
name: string; name: string;
songCount?: number; songCount?: number;
}; };
@@ -300,6 +300,7 @@ export type MusicFolder = {
export type MusicFoldersResponse = MusicFolder[]; export type MusicFoldersResponse = MusicFolder[];
export type Playlist = { export type Playlist = {
_itemType: LibraryItem.PLAYLIST;
_serverId: string; _serverId: string;
_serverType: ServerType; _serverType: ServerType;
description: null | string; description: null | string;
@@ -308,7 +309,6 @@ export type Playlist = {
id: string; id: string;
imagePlaceholderUrl: null | string; imagePlaceholderUrl: null | string;
imageUrl: null | string; imageUrl: null | string;
itemType: LibraryItem.PLAYLIST;
name: string; name: string;
owner: null | string; owner: null | string;
ownerId: null | string; ownerId: null | string;
@@ -331,6 +331,7 @@ export type RelatedArtist = {
}; };
export type Song = { export type Song = {
_itemType: LibraryItem.SONG;
_serverId: string; _serverId: string;
_serverType: ServerType; _serverType: ServerType;
album: null | string; album: null | string;
@@ -355,7 +356,6 @@ export type Song = {
id: string; id: string;
imagePlaceholderUrl: null | string; imagePlaceholderUrl: null | string;
imageUrl: null | string; imageUrl: null | string;
itemType: LibraryItem.SONG;
lastPlayedAt: null | string; lastPlayedAt: null | string;
lyrics: null | string; lyrics: null | string;
mbzRecordingId: null | string; mbzRecordingId: null | string;