Skip to content

Commit

Permalink
Show other show links for episodes
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithmohan committed Sep 7, 2024
1 parent f7c23c0 commit ffa67db
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 18 deletions.
18 changes: 16 additions & 2 deletions src/components/Collection/Tmdb/EpisodeRow.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { useMemo } from 'react';
import { useSearchParams } from 'react-router-dom';
import { mdiLoading } from '@mdi/js';
import { Icon } from '@mdi/react';
import cx from 'classnames';
import { find, map } from 'lodash';
import { find, map, toNumber } from 'lodash';

import AniDBEpisode from '@/components/Collection/Tmdb/AniDBEpisode';
import EpisodeSelect from '@/components/Collection/Tmdb/EpisodeSelect';
Expand Down Expand Up @@ -35,6 +36,9 @@ const EpisodeRow = React.memo((props: Props) => {
xrefs,
} = props;

const [searchParams] = useSearchParams();
const tmdbId = toNumber(searchParams.get('id'));

const xref = useMemo(
() => {
if (!xrefs?.[episode.IDs.AniDB]) return undefined;
Expand Down Expand Up @@ -117,6 +121,11 @@ const EpisodeRow = React.memo((props: Props) => {
return xref?.Rating;
}, [isPending, xref]);

const isDisabled = useMemo(() => {
if (!tmdbEpisode) return false;
return tmdbEpisode.ShowID !== tmdbId;
}, [tmdbEpisode, tmdbId]);

return (
<>
<AniDBEpisode
Expand All @@ -126,10 +135,15 @@ const EpisodeRow = React.memo((props: Props) => {
onIconClick={(offset > 0 || (tmdbEpisode ?? xref?.TmdbEpisodeID)) ? editExtraEpisodeLink : undefined}
/>

<MatchRating rating={matchRating} isOdd={isOdd} />
<MatchRating
rating={matchRating}
isOdd={isOdd}
isDisabled={isDisabled}
/>

{!isPending && (
<EpisodeSelect
isDisabled={isDisabled}
isOdd={isOdd}
overrideLink={overrideLink}
tmdbEpisode={tmdbEpisode}
Expand Down
15 changes: 12 additions & 3 deletions src/components/Collection/Tmdb/EpisodeSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ import useFlattenListResult from '@/hooks/useFlattenListResult';
import type { TmdbEpisodeType } from '@/core/types/api/tmdb';

type Props = {
isDisabled: boolean;
isOdd: boolean;
overrideLink: (newTmdbId?: number) => void;
tmdbEpisode?: TmdbEpisodeType;
};

const EpisodeSelect = React.memo((props: Props) => {
const { isOdd, overrideLink, tmdbEpisode: initialTmdbEpisode } = props;
const { isDisabled, isOdd, overrideLink, tmdbEpisode: initialTmdbEpisode } = props;
const [searchParams] = useSearchParams();
const tmdbId = toNumber(searchParams.get('id'));

Expand Down Expand Up @@ -65,13 +66,21 @@ const EpisodeSelect = React.memo((props: Props) => {
);

return (
<Listbox value={tmdbEpisode ?? {}} by="ID" onChange={handleSelect}>
<Listbox
value={tmdbEpisode ?? {}}
by="ID"
onChange={handleSelect}
disabled={isDisabled}
>
<ListboxButton
className={cx(
'flex items-center grow basis-0 gap-x-6 rounded-lg border border-panel-border p-4',
'data-[open]:border-panel-text-primary',
isOdd ? 'bg-panel-background-alt' : 'bg-panel-background',
isDisabled && 'opacity-65',
)}
data-tooltip-id="tooltip"
data-tooltip-content={isDisabled ? 'Episode is linked to another show.' : ''}
>
{({ open }) => (
<>
Expand All @@ -87,7 +96,7 @@ const EpisodeSelect = React.memo((props: Props) => {

<div
className="flex grow flex-col text-left"
data-tooltip-id="tooltip"
data-tooltip-id={!isDisabled ? 'tooltip' : ''}
data-tooltip-content={tmdbEpisode?.Title ?? ''}
>
<div className="line-clamp-1 text-xs font-semibold opacity-65">
Expand Down
9 changes: 8 additions & 1 deletion src/components/Collection/Tmdb/MatchRating.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ const getAbbreviation = (rating?: MatchRatingType) => {
}
};

const MatchRating = React.memo(({ isOdd, rating }: { isOdd: boolean, rating?: MatchRatingType }) => (
type Props = {
isDisabled: boolean;
isOdd: boolean;
rating?: MatchRatingType;
};

const MatchRating = React.memo(({ isDisabled, isOdd, rating }: Props) => (
<div
className={cx(
'flex justify-center items-center rounded-md border border-panel-border w-16 text-button-primary-text',
Expand All @@ -31,6 +37,7 @@ const MatchRating = React.memo(({ isOdd, rating }: { isOdd: boolean, rating?: Ma
'bg-panel-text-danger': rating === MatchRatingType.FirstAvailable,
'bg-panel-background': (!rating || rating === MatchRatingType.None) && !isOdd,
'bg-panel-background-alt': (!rating || rating === MatchRatingType.None) && isOdd,
'opacity-65': isDisabled,
},
)}
>
Expand Down
7 changes: 0 additions & 7 deletions src/core/react-query/tmdb/helpers.ts

This file was deleted.

9 changes: 5 additions & 4 deletions src/core/react-query/tmdb/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { useInfiniteQuery, useQuery } from '@tanstack/react-query';
import { toNumber } from 'lodash';

import { axios } from '@/core/axios';
import { transformListResultSimplified } from '@/core/react-query/helpers';
import queryClient from '@/core/react-query/queryClient';
import { cleanTmdbEpisodeXrefs } from '@/core/react-query/tmdb/helpers';

import type {
TmdbBulkRequestType,
Expand All @@ -26,17 +26,18 @@ import type {
export const useTmdbEpisodeXrefsQuery = (
seriesId: number,
isNewLink: boolean,
tmdbShowID: number,
params: TmdbEpisodeXrefRequestType,
enabled = true,
) =>
useQuery<ListResultType<TmdbEpisodeXrefType>, unknown, TmdbEpisodeXrefType[]>({
queryKey: ['series', seriesId, 'tmdb', 'cross-references', 'episode', isNewLink, params],
queryKey: ['series', seriesId, 'tmdb', 'cross-references', 'episode', isNewLink, params, tmdbShowID],
queryFn: () =>
axios.get(
`Series/${seriesId}/TMDB/Show/CrossReferences/Episode${isNewLink ? '/Auto' : ''}`,
{ params },
{ params: isNewLink ? { ...params, tmdbShowID } : params },
),
select: cleanTmdbEpisodeXrefs,
select: transformListResultSimplified,
enabled,
});

Expand Down
3 changes: 2 additions & 1 deletion src/pages/collection/series/TmdbLinking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ const TmdbLinking = () => {
const episodeXrefsQuery = useTmdbEpisodeXrefsQuery(
seriesId,
isNewLink,
{ tmdbShowID: tmdbId, pageSize: 0 },
tmdbId,
{ pageSize: 0 },
!createInProgress && !!seriesId && type === 'Show' && !!seriesQuery.data,
);
const episodeXrefs = useMemo(
Expand Down

0 comments on commit ffa67db

Please sign in to comment.