diff --git a/src/core/rtkQuery/splitV3Api/seriesApi.ts b/src/core/rtkQuery/splitV3Api/seriesApi.ts index ffccb3c67..7e61e2dbc 100644 --- a/src/core/rtkQuery/splitV3Api/seriesApi.ts +++ b/src/core/rtkQuery/splitV3Api/seriesApi.ts @@ -198,6 +198,19 @@ const seriesApi = splitV3Api.injectEndpoints({ query: ({ seriesId }) => ({ url: `Series/${seriesId}/Images`, }), + providesTags: ['SeriesAniDB'], + }), + + changeSeriesImage: build.mutation< + ResponseType, + { seriesId: string, image: Pick } + >({ + query: ({ image, seriesId }) => ({ + url: `Series/${seriesId}/Images/${image.Type}`, + method: 'PUT', + body: { ID: image.ID, Source: image.Source }, + }), + invalidatesTags: ['SeriesAniDB'], }), // Queue a refresh of all the TvDB data linked to a series using the seriesID. @@ -230,6 +243,7 @@ const seriesApi = splitV3Api.injectEndpoints({ }); export const { + useChangeSeriesImageMutation, useDeleteSeriesMutation, useGetAniDBRecommendedAnimeQuery, useGetAniDBRelatedQuery, 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 aa5ffa047..13720e9e8 100644 --- a/src/pages/collection/series/SeriesImages.tsx +++ b/src/pages/collection/series/SeriesImages.tsx @@ -9,11 +9,14 @@ import BackgroundImagePlaceholderDiv from '@/components/BackgroundImagePlacehold import Button from '@/components/Input/Button'; import Checkbox from '@/components/Input/Checkbox'; import ShokoPanel from '@/components/Panels/ShokoPanel'; -import { useGetSeriesImagesQuery } from '@/core/rtkQuery/splitV3Api/seriesApi'; +import toast from '@/components/Toast'; +import { useChangeSeriesImageMutation, useGetSeriesImagesQuery } from '@/core/rtkQuery/splitV3Api/seriesApi'; 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 @@ -21,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 | { const [type, setType] = useState('Posters'); const [selectedImage, setSelectedImage] = useState({} as ImageType); - const imagesData = useGetSeriesImagesQuery({ seriesId: seriesId! }, { skip: !seriesId }); + const [changeImage] = useChangeSeriesImageMutation(); const images = imagesData.data; const splitPath = split(selectedImage?.RelativeFilepath ?? '-', '/'); @@ -74,6 +78,10 @@ const SeriesImages = () => { Banners: 'h-[8rem] w-[43.25rem]', }; + const resetSelectedImage = () => { + setSelectedImage({} as ImageType); + }; + if (!seriesId) return null; return ( @@ -96,16 +104,27 @@ const SeriesImages = () => {
- +
{get(images, type, []).length}   diff --git a/src/pages/collection/series/SeriesTags.tsx b/src/pages/collection/series/SeriesTags.tsx index 2b5a5c361..a5c296abc 100644 --- a/src/pages/collection/series/SeriesTags.tsx +++ b/src/pages/collection/series/SeriesTags.tsx @@ -74,7 +74,7 @@ const SeriesTags = () => {
- {map(tags, item => )} + {map(tags, item => )}