From 164332d752e778efe210284139bb342d17d31620 Mon Sep 17 00:00:00 2001 From: jeffvli Date: Thu, 13 Nov 2025 22:04:00 -0800 Subject: [PATCH] refactor domain types to rename itemType --- .../item-list/helpers/get-dragged-items.ts | 4 +-- .../item-list/helpers/item-list-controls.ts | 2 +- .../item-list/helpers/item-list-state.ts | 4 +-- .../columns/actions-column.tsx | 2 +- .../item-table-list/item-table-list.tsx | 6 ++--- src/shared/api/jellyfin/jellyfin-normalize.ts | 26 ++++++++++++------- .../api/navidrome/navidrome-normalize.ts | 24 ++++++++++------- src/shared/api/subsonic/subsonic-normalize.ts | 14 +++++----- src/shared/types/domain-types.ts | 12 ++++----- 9 files changed, 54 insertions(+), 40 deletions(-) diff --git a/src/renderer/components/item-list/helpers/get-dragged-items.ts b/src/renderer/components/item-list/helpers/get-dragged-items.ts index 563b1ec6c..7f830e197 100644 --- a/src/renderer/components/item-list/helpers/get-dragged-items.ts +++ b/src/renderer/components/item-list/helpers/get-dragged-items.ts @@ -15,8 +15,8 @@ const hasRequiredDragProperties = ( item !== null && 'id' in item && typeof (item as any).id === 'string' && - 'itemType' in item && - typeof (item as any).itemType === 'string' && + '_itemType' in item && + typeof (item as any)._itemType === 'string' && '_serverId' in item && typeof (item as any)._serverId === 'string' ); diff --git a/src/renderer/components/item-list/helpers/item-list-controls.ts b/src/renderer/components/item-list/helpers/item-list-controls.ts index c520e7ad0..541e809a4 100644 --- a/src/renderer/components/item-list/helpers/item-list-controls.ts +++ b/src/renderer/components/item-list/helpers/item-list-controls.ts @@ -87,7 +87,7 @@ export const useDefaultItemListControls = () => { rangeItem && typeof rangeItem === 'object' && '_serverId' in rangeItem && - 'itemType' in rangeItem + '_itemType' in rangeItem ) { const rangeRowId = internalState.extractRowId(rangeItem); if (rangeRowId) { diff --git a/src/renderer/components/item-list/helpers/item-list-state.ts b/src/renderer/components/item-list/helpers/item-list-state.ts index 9e3542bf5..abdcbcbeb 100644 --- a/src/renderer/components/item-list/helpers/item-list-state.ts +++ b/src/renderer/components/item-list/helpers/item-list-state.ts @@ -73,15 +73,15 @@ export interface ItemListStateActions { } export interface ItemListStateItem { + _itemType: LibraryItem; _serverId: string; id: string; - itemType: LibraryItem; } export type ItemListStateItemWithRequiredProperties = Record & { + _itemType: LibraryItem; _serverId: string; id: string; - itemType: LibraryItem; }; /** diff --git a/src/renderer/components/item-list/item-table-list/columns/actions-column.tsx b/src/renderer/components/item-list/item-table-list/columns/actions-column.tsx index 0eb64c1e9..2256e2931 100644 --- a/src/renderer/components/item-list/item-table-list/columns/actions-column.tsx +++ b/src/renderer/components/item-list/item-table-list/columns/actions-column.tsx @@ -36,8 +36,8 @@ export const ActionsColumn = (props: ItemTableListInnerColumn) => { color: 'muted', size: 'md', }} - onDoubleClick={handleActionDoubleClick} onClick={handleActionClick} + onDoubleClick={handleActionDoubleClick} size="xs" variant="subtle" /> diff --git a/src/renderer/components/item-list/item-table-list/item-table-list.tsx b/src/renderer/components/item-list/item-table-list/item-table-list.tsx index 3955efccf..0c650103f 100644 --- a/src/renderer/components/item-list/item-table-list/item-table-list.tsx +++ b/src/renderer/components/item-list/item-table-list/item-table-list.tsx @@ -70,8 +70,8 @@ const hasRequiredStateItemProperties = ( typeof (item as any).id === 'string' && '_serverId' in item && typeof (item as any)._serverId === 'string' && - 'itemType' in item && - typeof (item as any).itemType === 'string' && + '_itemType' in item && + typeof (item as any)._itemType === 'string' && 'rowId' in item && typeof (item as any).rowId === 'string' ); @@ -1126,7 +1126,7 @@ export const ItemTableList = ({ typeof item === 'object' && item !== null && '_serverId' in item && - 'itemType' in item + '_itemType' in item ) { return item as ItemListStateItemWithRequiredProperties; } diff --git a/src/shared/api/jellyfin/jellyfin-normalize.ts b/src/shared/api/jellyfin/jellyfin-normalize.ts index b0a58a5c3..a251146ef 100644 --- a/src/shared/api/jellyfin/jellyfin-normalize.ts +++ b/src/shared/api/jellyfin/jellyfin-normalize.ts @@ -227,6 +227,7 @@ const normalizeSong = ( } return { + _itemType: LibraryItem.SONG, _serverId: server?.id || '', _serverType: ServerType.JELLYFIN, album: item.Album, @@ -265,15 +266,16 @@ const normalizeSong = ( } : null, genres: item.GenreItems?.map((entry) => ({ + _itemType: LibraryItem.GENRE, + _serverId: server?.id || '', + _serverType: ServerType.JELLYFIN, id: entry.Id, imageUrl: null, - itemType: LibraryItem.GENRE, name: entry.Name, })), id: item.Id, imagePlaceholderUrl: null, imageUrl: getSongCoverArtUrl({ baseUrl: server?.url || '', item, size: imageSize || 100 }), - itemType: LibraryItem.SONG, lastPlayedAt: null, lyrics: null, mbzRecordingId: null, @@ -307,6 +309,7 @@ const normalizeAlbum = ( imageSize?: number, ): Album => { return { + _itemType: LibraryItem.ALBUM, _serverId: server?.id || '', _serverType: ServerType.JELLYFIN, albumArtist: item.AlbumArtist, @@ -327,9 +330,11 @@ const normalizeAlbum = ( duration: item.RunTimeTicks / 10000, explicitStatus: null, genres: item.GenreItems?.map((entry) => ({ + _itemType: LibraryItem.GENRE, + _serverId: server?.id || '', + _serverType: ServerType.JELLYFIN, id: entry.Id, imageUrl: null, - itemType: LibraryItem.GENRE, name: entry.Name, })), id: item.Id, @@ -340,7 +345,6 @@ const normalizeAlbum = ( size: imageSize || 300, }), isCompilation: null, - itemType: LibraryItem.ALBUM, lastPlayedAt: null, mbzId: item.ProviderIds?.MusicBrainzAlbum || null, name: item.Name, @@ -383,6 +387,7 @@ const normalizeAlbumArtist = ( ) || []; return { + _itemType: LibraryItem.ALBUM_ARTIST, _serverId: server?.id || '', _serverType: ServerType.JELLYFIN, albumCount: item.AlbumCount ?? null, @@ -390,9 +395,11 @@ const normalizeAlbumArtist = ( biography: item.Overview || null, duration: item.RunTimeTicks / 10000, genres: item.GenreItems?.map((entry) => ({ + _itemType: LibraryItem.GENRE, + _serverId: server?.id || '', + _serverType: ServerType.JELLYFIN, id: entry.Id, imageUrl: null, - itemType: LibraryItem.GENRE, name: entry.Name, })), id: item.Id, @@ -401,7 +408,6 @@ const normalizeAlbumArtist = ( item, size: imageSize || 300, }), - itemType: LibraryItem.ALBUM_ARTIST, lastPlayedAt: null, mbz: item.ProviderIds?.MusicBrainzArtist || null, name: item.Name, @@ -427,20 +433,22 @@ const normalizePlaylist = ( const imagePlaceholderUrl = null; return { + _itemType: LibraryItem.PLAYLIST, _serverId: server?.id || '', _serverType: ServerType.JELLYFIN, description: item.Overview || null, duration: item.RunTimeTicks / 10000, genres: item.GenreItems?.map((entry) => ({ + _itemType: LibraryItem.GENRE, + _serverId: server?.id || '', + _serverType: ServerType.JELLYFIN, id: entry.Id, imageUrl: null, - itemType: LibraryItem.GENRE, name: entry.Name, })), id: item.Id, imagePlaceholderUrl, imageUrl: imageUrl || null, - itemType: LibraryItem.PLAYLIST, name: item.Name, owner: null, ownerId: null, @@ -504,12 +512,12 @@ const normalizeGenre = ( server: null | ServerListItem, ): Genre => { return { + _itemType: LibraryItem.GENRE, _serverId: server?.id || '', _serverType: ServerType.JELLYFIN, albumCount: undefined, id: item.Id, imageUrl: getGenreCoverArtUrl({ baseUrl: server?.url || '', item, size: 200 }), - itemType: LibraryItem.GENRE, name: item.Name, songCount: undefined, }; diff --git a/src/shared/api/navidrome/navidrome-normalize.ts b/src/shared/api/navidrome/navidrome-normalize.ts index ae712af1b..b327bf952 100644 --- a/src/shared/api/navidrome/navidrome-normalize.ts +++ b/src/shared/api/navidrome/navidrome-normalize.ts @@ -151,6 +151,7 @@ const normalizeSong = ( album: item.album, albumId: item.albumId, ...getArtists(item), + _itemType: LibraryItem.SONG, _serverId: server?.id || 'unknown', _serverType: ServerType.NAVIDROME, artistName: item.artist, @@ -176,15 +177,16 @@ const normalizeSong = ( ? { album: item.rgAlbumGain, track: item.rgTrackGain } : null, genres: (item.genres || []).map((genre) => ({ + _itemType: LibraryItem.GENRE, + _serverId: server?.id || 'unknown', + _serverType: ServerType.NAVIDROME, id: genre.id, imageUrl: null, - itemType: LibraryItem.GENRE, name: genre.name, })), id, imagePlaceholderUrl, imageUrl, - itemType: LibraryItem.SONG, lastPlayedAt: normalizePlayDate(item), lyrics: item.lyrics ? item.lyrics : null, mbzRecordingId: item.mbzReleaseTrackId || null, @@ -278,6 +280,7 @@ const normalizeAlbum = ( return { ...parseAlbumTags(item), ...getArtists(item), + _itemType: LibraryItem.ALBUM, _serverId: server?.id || 'unknown', _serverType: ServerType.NAVIDROME, albumArtist: item.albumArtist, @@ -292,17 +295,18 @@ const normalizeAlbum = ( ? ExplicitStatus.CLEAN : null, genres: (item.genres || []).map((genre) => ({ + _itemType: LibraryItem.GENRE, + _serverId: server?.id || 'unknown', + _serverType: ServerType.NAVIDROME, id: genre.id, imageUrl: null, - itemType: LibraryItem.GENRE, name: genre.name, })), id: item.id, imagePlaceholderUrl, imageUrl, - isCompilation: item.compilation, - itemType: LibraryItem.ALBUM, + isCompilation: item.compilation, lastPlayedAt: normalizePlayDate(item), mbzId: item.mbzAlbumId || null, name: item.name, @@ -363,6 +367,7 @@ const normalizeAlbumArtist = ( } return { + _itemType: LibraryItem.ALBUM_ARTIST, _serverId: server?.id || 'unknown', _serverType: ServerType.NAVIDROME, albumCount, @@ -370,14 +375,15 @@ const normalizeAlbumArtist = ( biography: item.biography || null, duration: null, genres: (item.genres || []).map((genre) => ({ + _itemType: LibraryItem.GENRE, + _serverId: server?.id || 'unknown', + _serverType: ServerType.NAVIDROME, id: genre.id, imageUrl: null, - itemType: LibraryItem.GENRE, name: genre.name, })), id: item.id, imageUrl: imageUrl || null, - itemType: LibraryItem.ALBUM_ARTIST, lastPlayedAt: normalizePlayDate(item), mbz: item.mbzArtistId || null, name: item.name, @@ -410,6 +416,7 @@ const normalizePlaylist = ( const imagePlaceholderUrl = null; return { + _itemType: LibraryItem.PLAYLIST, _serverId: server?.id || 'unknown', _serverType: ServerType.NAVIDROME, description: item.comment, @@ -418,7 +425,6 @@ const normalizePlaylist = ( id: item.id, imagePlaceholderUrl, imageUrl, - itemType: LibraryItem.PLAYLIST, name: item.name, owner: item.ownerName, ownerId: item.ownerId, @@ -435,12 +441,12 @@ const normalizeGenre = ( server: null | ServerListItem, ): Genre => { return { + _itemType: LibraryItem.GENRE, _serverId: server?.id || 'unknown', _serverType: ServerType.NAVIDROME, albumCount: undefined, id: item.id, imageUrl: null, - itemType: LibraryItem.GENRE, name: item.name, songCount: undefined, }; diff --git a/src/shared/api/subsonic/subsonic-normalize.ts b/src/shared/api/subsonic/subsonic-normalize.ts index f66295c34..c16c51ed5 100644 --- a/src/shared/api/subsonic/subsonic-normalize.ts +++ b/src/shared/api/subsonic/subsonic-normalize.ts @@ -98,21 +98,21 @@ const getGenres = ( ): Genre[] => { return item.genres ? item.genres.map((genre) => ({ + _itemType: LibraryItem.GENRE, _serverId: server?.id || 'unknown', _serverType: ServerType.SUBSONIC, id: genre.name, imageUrl: null, - itemType: LibraryItem.GENRE, name: genre.name, })) : item.genre ? [ { + _itemType: LibraryItem.GENRE, _serverId: server?.id || 'unknown', _serverType: ServerType.SUBSONIC, id: item.genre, imageUrl: null, - itemType: LibraryItem.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}`; return { + _itemType: LibraryItem.SONG, _serverId: server?.id || 'unknown', _serverType: ServerType.SUBSONIC, album: item.album || '', @@ -170,7 +171,6 @@ const normalizeSong = ( id: item.id.toString(), imagePlaceholderUrl: null, imageUrl, - itemType: LibraryItem.SONG, lastPlayedAt: null, lyrics: null, mbzRecordingId: item.musicBrainzId || null, @@ -215,6 +215,7 @@ const normalizeAlbumArtist = ( }) || null; return { + _itemType: LibraryItem.ALBUM_ARTIST, _serverId: server?.id || 'unknown', _serverType: ServerType.SUBSONIC, albumCount: item.albumCount ? Number(item.albumCount) : 0, @@ -224,7 +225,6 @@ const normalizeAlbumArtist = ( genres: [], id: item.id.toString(), imageUrl, - itemType: LibraryItem.ALBUM_ARTIST, lastPlayedAt: null, mbz: null, name: item.name, @@ -250,6 +250,7 @@ const normalizeAlbum = ( }) || null; return { + _itemType: LibraryItem.ALBUM, _serverId: server?.id || 'unknown', _serverType: ServerType.SUBSONIC, albumArtist: item.artist, @@ -270,7 +271,6 @@ const normalizeAlbum = ( imagePlaceholderUrl: null, imageUrl, isCompilation: null, - itemType: LibraryItem.ALBUM, lastPlayedAt: null, mbzId: null, name: item.name, @@ -302,6 +302,7 @@ const normalizePlaylist = ( server?: null | ServerListItemWithCredential, ): Playlist => { return { + _itemType: LibraryItem.PLAYLIST, _serverId: server?.id || 'unknown', _serverType: ServerType.SUBSONIC, description: item.comment || null, @@ -315,7 +316,6 @@ const normalizePlaylist = ( credential: server?.credential, size: 300, }), - itemType: LibraryItem.PLAYLIST, name: item.name, owner: item.owner, ownerId: item.owner, @@ -330,12 +330,12 @@ const normalizeGenre = ( server: null | ServerListItemWithCredential, ): Genre => { return { + _itemType: LibraryItem.GENRE, _serverId: server?.id || 'unknown', _serverType: ServerType.SUBSONIC, albumCount: item.albumCount, id: item.value, imageUrl: null, - itemType: LibraryItem.GENRE, name: item.value, songCount: item.songCount, }; diff --git a/src/shared/types/domain-types.ts b/src/shared/types/domain-types.ts index 121b511be..473d1679b 100644 --- a/src/shared/types/domain-types.ts +++ b/src/shared/types/domain-types.ts @@ -164,6 +164,7 @@ export enum ImageType { } export type Album = { + _itemType: LibraryItem.ALBUM; _serverId: string; _serverType: ServerType; albumArtist: string; @@ -179,7 +180,6 @@ export type Album = { imagePlaceholderUrl: null | string; imageUrl: null | string; isCompilation: boolean | null; - itemType: LibraryItem.ALBUM; lastPlayedAt: null | string; mbzId: null | string; name: string; @@ -201,6 +201,7 @@ export type Album = { } & { songs?: Song[] }; export type AlbumArtist = { + _itemType: LibraryItem.ALBUM_ARTIST; _serverId: string; _serverType: ServerType; albumCount: null | number; @@ -210,7 +211,6 @@ export type AlbumArtist = { genres: Genre[]; id: string; imageUrl: null | string; - itemType: LibraryItem.ALBUM_ARTIST; lastPlayedAt: null | string; mbz: null | string; name: string; @@ -222,12 +222,12 @@ export type AlbumArtist = { }; export type Artist = { + _itemType: LibraryItem.ARTIST; _serverId: string; _serverType: ServerType; biography: null | string; createdAt: string; id: string; - itemType: LibraryItem.ARTIST; name: string; remoteCreatedAt: null | string; updatedAt: string; @@ -262,12 +262,12 @@ export type GainInfo = { }; export type Genre = { + _itemType: LibraryItem.GENRE; _serverId: string; _serverType: ServerType; albumCount?: number; id: string; imageUrl: null | string; - itemType: LibraryItem.GENRE; name: string; songCount?: number; }; @@ -300,6 +300,7 @@ export type MusicFolder = { export type MusicFoldersResponse = MusicFolder[]; export type Playlist = { + _itemType: LibraryItem.PLAYLIST; _serverId: string; _serverType: ServerType; description: null | string; @@ -308,7 +309,6 @@ export type Playlist = { id: string; imagePlaceholderUrl: null | string; imageUrl: null | string; - itemType: LibraryItem.PLAYLIST; name: string; owner: null | string; ownerId: null | string; @@ -331,6 +331,7 @@ export type RelatedArtist = { }; export type Song = { + _itemType: LibraryItem.SONG; _serverId: string; _serverType: ServerType; album: null | string; @@ -355,7 +356,6 @@ export type Song = { id: string; imagePlaceholderUrl: null | string; imageUrl: null | string; - itemType: LibraryItem.SONG; lastPlayedAt: null | string; lyrics: null | string; mbzRecordingId: null | string;