From 29ca428b6aaf1d5af5b92ab5116bd0e2ad54b76d Mon Sep 17 00:00:00 2001 From: Pas <74743263+Pasithea0@users.noreply.github.com> Date: Mon, 2 Jun 2025 12:38:55 -0600 Subject: [PATCH] Remove media card overlay --- src/components/media/MediaCard.tsx | 494 ++++++++--------------------- 1 file changed, 140 insertions(+), 354 deletions(-) diff --git a/src/components/media/MediaCard.tsx b/src/components/media/MediaCard.tsx index 9cff8a19..4422d84c 100644 --- a/src/components/media/MediaCard.tsx +++ b/src/components/media/MediaCard.tsx @@ -1,20 +1,19 @@ // I'm sorry this is so confusing 😭 import classNames from "classnames"; -import { useCallback, useRef, useState } from "react"; +import { useCallback, useState } from "react"; import { useTranslation } from "react-i18next"; import { Link } from "react-router-dom"; -import { useCopyToClipboard } from "react-use"; import { mediaItemToId } from "@/backend/metadata/tmdb"; import { DotList } from "@/components/text/DotList"; import { Flare } from "@/components/utils/Flare"; +import { useIsMobile } from "@/hooks/useIsMobile"; import { useSearchQuery } from "@/hooks/useSearchQuery"; import { usePreferencesStore } from "@/stores/preferences"; import { MediaItem } from "@/utils/mediaTypes"; import { MediaBookmarkButton } from "./MediaBookmark"; -import { Button } from "../buttons/Button"; import { IconPatch } from "../buttons/IconPatch"; import { Icon, Icons } from "../Icon"; import { DetailsModal } from "../overlays/details/DetailsModal"; @@ -49,10 +48,6 @@ function checkReleased(media: MediaItem): boolean { return isReleased; } -function getBaseUrl(): string { - return window.location.origin; -} - function MediaCardContent({ media, linkable, @@ -60,23 +55,11 @@ function MediaCardContent({ percentage, closable, onClose, - overlayVisible, - setOverlayVisible, - handleMouseEnter, - handleMouseLeave, - link, - isHoveringCard, onShowDetails, -}: MediaCardProps & { - overlayVisible: boolean; - setOverlayVisible: React.Dispatch>; - handleMouseEnter: () => void; - handleMouseLeave: () => void; - link: string; - isHoveringCard: boolean; -}) { +}: MediaCardProps) { const { t } = useTranslation(); const percentageString = `${Math.round(percentage ?? 0).toFixed(0)}%`; + const { isMobile } = useIsMobile(); const isReleased = useCallback(() => checkReleased(media), [media]); @@ -84,19 +67,8 @@ function MediaCardContent({ const dotListContent = [t(`media.types.${media.type}`)]; - const altDotListContent = [t(`ID: ${media.id}`)]; - const [searchQuery] = useSearchQuery(); - const [, copyToClipboard] = useCopyToClipboard(); - const [hasCopied, setHasCopied] = useState(false); - - const [hasCopiedID, setHasCopiedID] = useState(false); - - if (closable) { - setOverlayVisible(false); - } - if (isReleased() && media.year) { dotListContent.push(media.year.toFixed()); } @@ -105,252 +77,146 @@ function MediaCardContent({ dotListContent.push(t("media.unreleased")); } - const handleCopyClick = ( - e: React.MouseEvent, - ) => { - e.preventDefault(); - copyToClipboard(link); - setHasCopied(true); - setTimeout(() => setHasCopied(false), 2000); - }; - - const handleCopyIDClick = ( - e: React.MouseEvent, - ) => { - e.preventDefault(); - copyToClipboard(media.id); - setHasCopiedID(true); - setTimeout(() => setHasCopiedID(false), 2000); - }; - return ( -
e.key === "Enter" && e.currentTarget.click()} > - + e.key === "Enter" && e.currentTarget.click()} > - - -
- {!overlayVisible ? ( -
- {series ? ( + {series ? ( +
+

+ {t("media.episodeDisplay", { + season: series.season || 1, + episode: series.episode, + })} +

+
+ ) : null} + + {percentage !== undefined ? ( + <> +
+
+
+
-

- {t("media.episodeDisplay", { - season: series.season || 1, - episode: series.episode, - })} -

-
- ) : null} - - {percentage !== undefined ? ( - <> -
-
-
-
-
-
-
- - ) : null} -
- ) : null} - - {!overlayVisible ? ( -
- {!closable ? ( -
-
e.preventDefault()} - > - -
- {searchQuery.length > 0 ? ( -
e.preventDefault()} - > - -
- ) : null} -
- ) : null} -
- closable && onClose?.()} - icon={Icons.X} + className="absolute inset-y-0 left-0 rounded-full bg-mediaCard-barFillColor" + style={{ + width: percentageString, + }} />
- ) : null} -
+ + ) : null} - {overlayVisible ? ( -
-
- + {!closable && ( +
e.preventDefault()} + > + +
+ )} - {canLink ? ( - - ) : null} - - -
+ {searchQuery.length > 0 && !closable ? ( +
e.preventDefault()}> +
) : null} -

- {media.title} -

-
- {!overlayVisible ? ( - - ) : ( - - )} +
+ closable && onClose?.()} + icon={Icons.X} + />
+
- {!overlayVisible && !closable ? ( -
- -
- ) : null} - - -
+

+ {media.title} +

+
+ +
+ + {!closable && ( +
+ +
+ )} + + ); } export function MediaCard(props: MediaCardProps) { const { media, onShowDetails } = props; - const [overlayVisible, setOverlayVisible] = useState(false); - const [timeoutId, setTimeoutId] = useState(null); - const hoverTimer = useRef(); - const [isHoveringCard, setIsHoveringCard] = useState(false); const [detailsData, setDetailsData] = useState<{ id: number; type: "movie" | "show"; @@ -360,36 +226,6 @@ export function MediaCard(props: MediaCardProps) { (state) => state.enableDetailsModal, ); - const handleMouseEnter = () => { - setIsHoveringCard(true); - - if (timeoutId) { - clearTimeout(timeoutId); - setTimeoutId(null); - } - - if (hoverTimer.current) { - clearTimeout(hoverTimer.current); - } - }; - - const handleMouseLeave = () => { - setIsHoveringCard(false); - if (hoverTimer.current) { - clearTimeout(hoverTimer.current); - } - - const id = setTimeout(() => { - setOverlayVisible(false); - }, 2000); // 2 seconds - setTimeoutId(id); - }; - - const handleContextMenu = (e: React.MouseEvent) => { - e.preventDefault(); - setOverlayVisible(true); - }; - const isReleased = useCallback( () => checkReleased(props.media), [props.media], @@ -398,7 +234,7 @@ export function MediaCard(props: MediaCardProps) { const canLink = props.linkable && !props.closable && isReleased(); let link = canLink - ? `${getBaseUrl()}/media/${encodeURIComponent(mediaItemToId(props.media))}` + ? `/media/${encodeURIComponent(mediaItemToId(props.media))}` : "#"; if (canLink && props.series) { if (props.series.season === 0 && !props.series.episodeId) { @@ -427,92 +263,42 @@ export function MediaCard(props: MediaCardProps) { if (enableDetailsModal && canLink) { e.preventDefault(); handleShowDetails(); - } else if (overlayVisible || e.defaultPrevented) { - e.preventDefault(); } }; const content = ( <> - + {detailsData && } ); - if (!canLink) + if (!canLink) { return ( { - if (overlayVisible || e.defaultPrevented) { + if (e.defaultPrevented) { e.preventDefault(); } }} > - {content}{" "} + {content} ); + } + return ( -
- {!overlayVisible ? ( - - - - ) : ( -
- -
+ + onClick={handleCardClick} + > + {content} + ); }