diff --git a/src/core/rtkQuery/splitV3Api.ts b/src/core/rtkQuery/splitV3Api.ts index 4b43fd5a8..424ca9d17 100644 --- a/src/core/rtkQuery/splitV3Api.ts +++ b/src/core/rtkQuery/splitV3Api.ts @@ -22,6 +22,7 @@ export const splitV3Api = createApi({ 'ImportFolder', 'QueueItems', 'SeriesAniDB', + 'SeriesImages', 'SeriesEpisodes', 'SeriesUpdated', 'Settings', diff --git a/src/core/rtkQuery/splitV3Api/seriesApi.ts b/src/core/rtkQuery/splitV3Api/seriesApi.ts index a8fe418ea..49c1f44a4 100644 --- a/src/core/rtkQuery/splitV3Api/seriesApi.ts +++ b/src/core/rtkQuery/splitV3Api/seriesApi.ts @@ -198,15 +198,19 @@ const seriesApi = splitV3Api.injectEndpoints({ query: ({ seriesId }) => ({ url: `Series/${seriesId}/Images`, }), + providesTags: ['SeriesImages'], }), - changeSeriesImage: build.mutation({ - query: ({ imageType, params, seriesId }) => ({ - url: `Series/${seriesId}/Images/${imageType}`, + changeSeriesImage: build.mutation< + ResponseType, + { seriesId: string, image: Pick } + >({ + query: ({ image, seriesId }) => ({ + url: `Series/${seriesId}/Images/${image.Type}`, method: 'PUT', - body: params, + body: { ID: image.ID, Source: image.Source }, }), - invalidatesTags: ['SeriesAniDB'], + invalidatesTags: ['SeriesAniDB', 'SeriesImages'], }), // Queue a refresh of all the TvDB data linked to a series using the seriesID. diff --git a/src/pages/collection/Series.tsx b/src/pages/collection/Series.tsx index 64f2ebdd0..7eec75a5c 100644 --- a/src/pages/collection/Series.tsx +++ b/src/pages/collection/Series.tsx @@ -13,7 +13,7 @@ import { } from '@mdi/js'; import { Icon } from '@mdi/react'; import cx from 'classnames'; -import { get, isArray } from 'lodash'; +import { get } from 'lodash'; import BackgroundImagePlaceholderDiv from '@/components/BackgroundImagePlaceholderDiv'; import AnidbDescription from '@/components/Collection/AnidbDescription'; @@ -28,6 +28,7 @@ import { import useMainPoster from '@/hooks/useMainPoster'; import type { CollectionGroupType } from '@/core/types/api/collection'; +import type { ImageType } from '@/core/types/api/common'; import type { SeriesDetailsType } from '@/core/types/api/series'; import type { TagType } from '@/core/types/api/tags'; @@ -77,11 +78,13 @@ const Series = () => { const group = groupData?.data ?? {} as CollectionGroupType; useEffect(() => { - const fanarts = get(images, 'data.Fanarts', []); - if (!isArray(fanarts) || fanarts.length === 0) return; - const randomIdx = Math.floor(Math.random() * fanarts.length); - const randomImage = fanarts[randomIdx]; - setFanartUri(`/api/v3/Image/${randomImage.Source}/${randomImage.Type}/${randomImage.ID}`); + const allFanarts: ImageType[] = get(images, 'data.Fanarts', []); + if (!Array.isArray(allFanarts) || allFanarts.length === 0) return; + + const defaultFanart = allFanarts.find(fanart => fanart.Preferred); + if (defaultFanart) { + setFanartUri(`/api/v3/Image/${defaultFanart.Source}/${defaultFanart.Type}/${defaultFanart.ID}`); + } }, [images, imagesData]); if (!seriesId || !seriesData.isSuccess) return null; diff --git a/src/pages/collection/series/SeriesImages.tsx b/src/pages/collection/series/SeriesImages.tsx index 5d0fd652f..13720e9e8 100644 --- a/src/pages/collection/series/SeriesImages.tsx +++ b/src/pages/collection/series/SeriesImages.tsx @@ -14,7 +14,9 @@ import { useChangeSeriesImageMutation, useGetSeriesImagesQuery } from '@/core/rt import type { ImageType } from '@/core/types/api/common'; -const Heading = React.memo(({ setType, type }: { type: string, setType: (type: string) => void }) => ( +const Heading = React.memo(( + { onTypeChange, setType, type }: { type: string, setType: (type: string) => void, onTypeChange: () => void }, +) => (
Images @@ -22,10 +24,11 @@ const Heading = React.memo(({ setType, type }: { type: string, setType: (type: s { setType('Posters'); + onTypeChange(); }} className={cx(type === 'Posters' && 'text-panel-text-primary')} > - Poster + Posters | - Fanart + Fanarts | { Banners: 'h-[8rem] w-[43.25rem]', }; + const resetSelectedImage = () => { + setSelectedImage({} as ImageType); + }; + if (!seriesId) return null; return ( @@ -97,25 +104,27 @@ const SeriesImages = () => {
- +
{get(images, type, []).length}