Skip to content

Commit

Permalink
fix: episodes tooltip will be scrollable and show episodes in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
OwsleyJr committed Nov 26, 2022
1 parent a897766 commit d66d98d
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 105 deletions.
2 changes: 0 additions & 2 deletions server/api/servarr/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,6 @@ class ServarrBase<QueueItemAppendT> extends ExternalAPI {
}
);

console.log(response.data.records);

return response.data.records;
} catch (e) {
throw new Error(
Expand Down
74 changes: 55 additions & 19 deletions src/components/CollectionDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import ButtonWithDropdown from '@app/components/Common/ButtonWithDropdown';
import CachedImage from '@app/components/Common/CachedImage';
import LoadingSpinner from '@app/components/Common/LoadingSpinner';
import PageTitle from '@app/components/Common/PageTitle';
import DownloadBlock from '@app/components/DownloadBlock';
import RequestModal from '@app/components/RequestModal';
import Slider from '@app/components/Slider';
import StatusBadge from '@app/components/StatusBadge';
Expand Down Expand Up @@ -40,9 +41,6 @@ const CollectionDetails = ({ collection }: CollectionDetailsProps) => {
const [requestModal, setRequestModal] = useState(false);
const [is4k, setIs4k] = useState(false);
const [downloadStatus, setDownloadStatus] = useState<DownloadingItem[]>([]);
const [formattedTitle, setFormattedTitle] = useState<string | undefined>(
undefined
);

const {
data,
Expand All @@ -57,24 +55,20 @@ const CollectionDetails = ({ collection }: CollectionDetailsProps) => {
useSWR<{ id: number; name: string }[]>(`/api/v1/genres/movie`);

useEffect(() => {
const tempArray: DownloadingItem[] = [];

data?.parts.map((item) =>
(item.mediaInfo?.downloadStatus4k ?? []).length > 0
? setDownloadStatus(item.mediaInfo?.downloadStatus4k ?? [])
: (item.mediaInfo?.downloadStatus ?? []).length > 0 &&
setDownloadStatus(item.mediaInfo?.downloadStatus ?? [])
? item.mediaInfo?.downloadStatus4k?.forEach((status) =>
tempArray.push(status)
)
: item.mediaInfo?.downloadStatus?.forEach((status) =>
tempArray.push(status)
)
);

if (downloadStatus.length > 0) {
const correctMedia = data?.parts.filter((e) =>
e.mediaInfo?.externalServiceId4k
? e.mediaInfo?.externalServiceId4k === downloadStatus[0].externalId
: e.mediaInfo?.externalServiceId === downloadStatus[0].externalId
);
if (correctMedia) {
setFormattedTitle(correctMedia[0].title);
}
}
}, [data?.parts, downloadStatus]);
setDownloadStatus(tempArray);
}, [data?.parts]);

if (!data && !error) {
return <LoadingSpinner />;
Expand Down Expand Up @@ -231,7 +225,28 @@ const CollectionDetails = ({ collection }: CollectionDetailsProps) => {
<StatusBadge
status={collectionStatus}
downloadItem={downloadStatus[0]}
formattedTitle={formattedTitle}
downloadBlock={
<ul>
{downloadStatus.map((status, index) => (
<li
key={`dl-status-${status.externalId}-${index}`}
className="border-b border-gray-700 last:border-b-0"
>
<DownloadBlock
downloadItem={status}
title={data.parts
.filter(
(item) =>
item.mediaInfo?.externalServiceId ===
status.externalId
)
.map((title) => title.title)
.join('')}
/>
</li>
))}
</ul>
}
inProgress={data.parts.some(
(part) => (part.mediaInfo?.downloadStatus ?? []).length > 0
)}
Expand All @@ -246,8 +261,29 @@ const CollectionDetails = ({ collection }: CollectionDetailsProps) => {
<StatusBadge
status={collectionStatus4k}
downloadItem={downloadStatus[0]}
downloadBlock={
<ul>
{downloadStatus.map((status, index) => (
<li
key={`dl-status-${status.externalId}-${index}`}
className="border-b border-gray-700 last:border-b-0"
>
<DownloadBlock
downloadItem={status}
title={data.parts
.filter(
(item) =>
item.mediaInfo?.externalServiceId4k ===
status.externalId
)
.map((title) => title.title)
.join('')}
/>
</li>
))}
</ul>
}
is4k
formattedTitle={formattedTitle}
inProgress={data.parts.some(
(part) =>
(part.mediaInfo?.downloadStatus4k ?? []).length > 0
Expand Down
19 changes: 16 additions & 3 deletions src/components/Common/Tooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ type TooltipProps = {
content: React.ReactNode;
children: React.ReactElement;
tooltipConfig?: Partial<Config>;
className?: string;
};

const Tooltip = ({ children, content, tooltipConfig }: TooltipProps) => {
const Tooltip = ({
children,
content,
tooltipConfig,
className,
}: TooltipProps) => {
const { getTooltipProps, setTooltipRef, setTriggerRef, visible } =
usePopperTooltip({
followCursor: true,
Expand All @@ -18,6 +24,14 @@ const Tooltip = ({ children, content, tooltipConfig }: TooltipProps) => {
...tooltipConfig,
});

const tooltipStyle = [
'z-50 text-sm absolute font-normal bg-gray-800 px-2 py-1 rounded border border-gray-600 shadow text-gray-100',
];

if (className) {
tooltipStyle.push(className);
}

return (
<>
{React.cloneElement(children, { ref: setTriggerRef })}
Expand All @@ -27,8 +41,7 @@ const Tooltip = ({ children, content, tooltipConfig }: TooltipProps) => {
<div
ref={setTooltipRef}
{...getTooltipProps({
className:
'z-50 text-sm absolute font-normal bg-gray-800 px-2 py-1 rounded border border-gray-600 shadow text-gray-100',
className: tooltipStyle.join(' '),
})}
>
{content}
Expand Down
28 changes: 13 additions & 15 deletions src/components/DownloadBlock/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,38 @@ import { defineMessages, FormattedRelativeTime, useIntl } from 'react-intl';

const messages = defineMessages({
estimatedtime: 'Estimated {time}',
seasonepisodenumber: ': Season {seasonNumber} Episode {episodeNumber}',
});

interface DownloadBlockProps {
downloadItem: DownloadingItem;
is4k?: boolean;
outsideSlideover?: boolean;
formattedTitle?: string;
title?: string;
}

const DownloadBlock = ({
downloadItem,
is4k = false,
outsideSlideover = false,
formattedTitle,
title,
}: DownloadBlockProps) => {
const intl = useIntl();
const { hasPermission } = useUser();

const formattedTitle: string =
title +
intl.formatMessage(messages.seasonepisodenumber, {
seasonNumber: downloadItem?.episode?.seasonNumber,
episodeNumber: downloadItem?.episode?.episodeNumber,
});

return (
<div className="p-4">
<div
className={`mb-2 w-56 truncate text-sm sm:w-80 ${
outsideSlideover ? 'md:w-80' : 'md:w-full'
}`}
>
<div className="mb-2 w-56 truncate text-sm sm:w-80 md:w-full">
{hasPermission(Permission.ADMIN)
? downloadItem.title
: downloadItem.episode
? formattedTitle +
': Season ' +
downloadItem?.episode?.seasonNumber +
' Episode ' +
downloadItem?.episode?.episodeNumber
: formattedTitle}
? formattedTitle
: title}
</div>
<div className="relative mb-2 h-6 min-w-0 overflow-hidden rounded-full bg-gray-700">
<div
Expand Down
33 changes: 31 additions & 2 deletions src/components/MovieDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import PageTitle from '@app/components/Common/PageTitle';
import type { PlayButtonLink } from '@app/components/Common/PlayButton';
import PlayButton from '@app/components/Common/PlayButton';
import Tooltip from '@app/components/Common/Tooltip';
import DownloadBlock from '@app/components/DownloadBlock';
import ExternalLinkBlock from '@app/components/ExternalLinkBlock';
import IssueModal from '@app/components/IssueModal';
import ManageSlideOver from '@app/components/ManageSlideOver';
Expand Down Expand Up @@ -309,7 +310,18 @@ const MovieDetails = ({ movie }: MovieDetailsProps) => {
data.mediaInfo?.downloadStatus &&
data.mediaInfo?.downloadStatus[0]
}
formattedTitle={data.title}
downloadBlock={
<ul>
{data.mediaInfo?.downloadStatus?.map((status, index) => (
<li
key={`dl-status-${status.externalId}-${index}`}
className="border-b border-gray-700 last:border-b-0"
>
<DownloadBlock downloadItem={status} title={data.title} />
</li>
))}
</ul>
}
inProgress={(data.mediaInfo?.downloadStatus ?? []).length > 0}
tmdbId={data.mediaInfo?.tmdbId}
mediaType="movie"
Expand All @@ -333,7 +345,24 @@ const MovieDetails = ({ movie }: MovieDetailsProps) => {
data.mediaInfo?.downloadStatus4k &&
data.mediaInfo?.downloadStatus4k[0]
}
formattedTitle={data.title}
downloadBlock={
<ul>
{data.mediaInfo?.downloadStatus4k?.map(
(status, index) => (
<li
key={`dl-status-${status.externalId}-${index}`}
className="border-b border-gray-700 last:border-b-0"
>
<DownloadBlock
downloadItem={status}
is4k
title={data.title}
/>
</li>
)
)}
</ul>
}
is4k
inProgress={
(data.mediaInfo?.downloadStatus4k ?? []).length > 0
Expand Down
31 changes: 30 additions & 1 deletion src/components/RequestCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Badge from '@app/components/Common/Badge';
import Button from '@app/components/Common/Button';
import CachedImage from '@app/components/Common/CachedImage';
import Tooltip from '@app/components/Common/Tooltip';
import DownloadBlock from '@app/components/DownloadBlock';
import RequestModal from '@app/components/RequestModal';
import StatusBadge from '@app/components/StatusBadge';
import useDeepLinks from '@app/hooks/useDeepLinks';
Expand Down Expand Up @@ -404,7 +405,35 @@ const RequestCard = ({ request, onTitleData }: RequestCardProps) => {
: requestData.media?.downloadStatus &&
requestData.media?.downloadStatus[0]
}
formattedTitle={isMovie(title) ? title.title : title.name}
downloadBlock={
<ul>
{requestData.media?.downloadStatus?.map((status, index) => (
<li
key={`dl-status-${status.externalId}-${index}`}
className="border-b border-gray-700 last:border-b-0"
>
<DownloadBlock
downloadItem={status}
title={isMovie(title) ? title.title : title.name}
/>
</li>
))}
{requestData.media?.downloadStatus4k?.map(
(status, index) => (
<li
key={`dl-status-${status.externalId}-${index}`}
className="border-b border-gray-700 last:border-b-0"
>
<DownloadBlock
downloadItem={status}
is4k
title={isMovie(title) ? title.title : title.name}
/>
</li>
)
)}
</ul>
}
inProgress={
(
requestData.media[
Expand Down
33 changes: 32 additions & 1 deletion src/components/RequestList/RequestItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Badge from '@app/components/Common/Badge';
import Button from '@app/components/Common/Button';
import CachedImage from '@app/components/Common/CachedImage';
import ConfirmButton from '@app/components/Common/ConfirmButton';
import DownloadBlock from '@app/components/DownloadBlock';
import RequestModal from '@app/components/RequestModal';
import StatusBadge from '@app/components/StatusBadge';
import useDeepLinks from '@app/hooks/useDeepLinks';
Expand Down Expand Up @@ -476,7 +477,37 @@ const RequestItem = ({ request, revalidateList }: RequestItemProps) => {
: requestData.media?.downloadStatus &&
requestData.media?.downloadStatus[0]
}
formattedTitle={isMovie(title) ? title.title : title.name}
downloadBlock={
<ul>
{requestData.media?.downloadStatus?.map(
(status, index) => (
<li
key={`dl-status-${status.externalId}-${index}`}
className="border-b border-gray-700 last:border-b-0"
>
<DownloadBlock
downloadItem={status}
title={isMovie(title) ? title.title : title.name}
/>
</li>
)
)}
{requestData.media?.downloadStatus4k?.map(
(status, index) => (
<li
key={`dl-status-${status.externalId}-${index}`}
className="border-b border-gray-700 last:border-b-0"
>
<DownloadBlock
downloadItem={status}
is4k
title={isMovie(title) ? title.title : title.name}
/>
</li>
)
)}
</ul>
}
inProgress={
(
requestData.media[
Expand Down
Loading

0 comments on commit d66d98d

Please sign in to comment.