Skip to content

Commit

Permalink
feat: add ability to remove tvdb links
Browse files Browse the repository at this point in the history
and also make it display all links for a given site, since you want to
delete the right link if you have multiple.
  • Loading branch information
revam committed Nov 14, 2023
1 parent e2beda1 commit 66b5c50
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 10 deletions.
19 changes: 17 additions & 2 deletions src/components/Collection/SeriesMetadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import { mdiCloseCircleOutline, mdiOpenInNew, mdiPencilCircleOutline, mdiPlusCir
import { Icon } from '@mdi/react';

import Button from '@/components/Input/Button';
import { useDeleteSeriesTvdbLinkMutation } from '@/core/rtkQuery/splitV3Api/seriesApi';

const MetadataLink = ({ id, site }: { site: string, id: number | number[] }) => {
const MetadataLink = ({ id, seriesId, site }: { id: number | number[], seriesId: number, site: string }) => {
const linkId = Array.isArray(id) ? id[0] : id;

const [disableTvDBTrigger] = useDeleteSeriesTvdbLinkMutation();

const siteLink = useMemo(() => {
switch (site) {
case 'AniDB':
Expand All @@ -24,6 +27,18 @@ const MetadataLink = ({ id, site }: { site: string, id: number | number[] }) =>
}
}, [linkId, site]);

const canDisable = site === 'TvDB';

const disableMetadata = () => {
switch (site) {
case 'TvDB':
disableTvDBTrigger({ seriesId, tvdbShowId: linkId }).catch(() => {});
break;
default:
break;
}
};

return (
<div key={site} className="flex justify-between">
<div className="flex gap-x-4">
Expand All @@ -50,7 +65,7 @@ const MetadataLink = ({ id, site }: { site: string, id: number | number[] }) =>
<Button disabled>
<Icon className="text-panel-icon-action" path={mdiPencilCircleOutline} size={1} />
</Button>
<Button disabled>
<Button disabled={!canDisable} onClick={disableMetadata}>
<Icon className="text-panel-icon-danger" path={mdiCloseCircleOutline} size={1} />
</Button>
</>
Expand Down
10 changes: 10 additions & 0 deletions src/core/rtkQuery/splitV3Api/seriesApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ const seriesApi = splitV3Api.injectEndpoints({
invalidatesTags: ['SeriesUpdated'],
}),

deleteSeriesTvdbLink: build.mutation<void, { seriesId: number, tvdbShowId: number }>({
query: ({ seriesId, tvdbShowId }) => ({
url: `Series/${seriesId}/TvDB`,
method: 'DELETE',
body: { ID: tvdbShowId },
}),
invalidatesTags: ['SeriesUpdated', 'SeriesAniDB', 'SeriesEpisodes'],
}),

// Get a paginated list of Shoko.Server.API.v3.Models.Shoko.Series without local files, available to the current Shoko.Server.API.v3.Models.Shoko.User.
getSeriesWithoutFiles: build.query<ListResultType<SeriesType[]>, PaginationType>({
query: params => ({ url: 'Series/WithoutFiles', params }),
Expand Down Expand Up @@ -231,6 +240,7 @@ const seriesApi = splitV3Api.injectEndpoints({

export const {
useDeleteSeriesMutation,
useDeleteSeriesTvdbLinkMutation,
useGetAniDBRecommendedAnimeQuery,
useGetAniDBRelatedQuery,
useGetAniDBSimilarQuery,
Expand Down
33 changes: 25 additions & 8 deletions src/pages/collection/series/SeriesOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ const NextUpEpisode = ({ nextUpEpisode }: { nextUpEpisode: EpisodeType }) => {
);
};

// Links
const MetadataLinks = ['AniDB', 'TMDB', 'TvDB', 'TraktTv'];

const SeriesOverview = () => {
const { seriesId } = useParams();

Expand All @@ -44,9 +47,6 @@ const SeriesOverview = () => {
const similarData = useGetAniDBSimilarQuery({ seriesId: seriesId! }, { skip: !seriesId });
const similar: SeriesAniDBSimilarType[] = similarData?.data ?? [] as SeriesAniDBSimilarType[];

// Links
const metadataLinks = ['AniDB', 'TMDB', 'TvDB', 'TraktTv'];

if (!seriesId || !series) return null;

return (
Expand All @@ -68,11 +68,28 @@ const SeriesOverview = () => {
transparent
>
<div className="flex flex-col gap-y-2">
{metadataLinks.map(site => (
<div className="rounded border border-panel-border bg-panel-background-alt px-4 py-3" key={site}>
<SeriesMetadata site={site} id={series.IDs[site]} />
</div>
))}
{MetadataLinks.map((site) => {
const idOrIds = series.IDs[site] as number | number[];
if (typeof idOrIds === 'number' || idOrIds.length === 0) {
const id = typeof idOrIds === 'number' ? idOrIds : idOrIds[0] || 0;
return (
<div
className="rounded border border-panel-border bg-panel-background-alt px-4 py-3"
key={`${site}-${id}`}
>
<SeriesMetadata site={site} id={idOrIds} seriesId={series.IDs.ID} />
</div>
);
}
return idOrIds.map(id => (
<div
className="rounded border border-panel-border bg-panel-background-alt px-4 py-3"
key={`${site}-${id}`}
>
<SeriesMetadata site={site} id={id} seriesId={series.IDs.ID} />
</div>
));
})}
</div>
</ShokoPanel>
</div>
Expand Down

0 comments on commit 66b5c50

Please sign in to comment.