fix: artwork fallbacks everywhere and hero layout
- resolveItemImage(): try the item's own images, then series/album/parent artwork - hero sidebar tickers fall back from Thumb to Backdrop/Primary instead of an icon - hero background falls back to the poster when no backdrop exists - stop stacked slides when the carousel advances (drop leaking AnimatePresence) - keep the hero title/logo inside the slide on narrow windows - sensible slides-per-view on tablet/mobile widths
This commit is contained in:
1 parent
1c499f42ec
commit
5a9b3ad273
7 files changed
+196
-33
No files matched your search
@@ -10,6 +10,7 @@ import React, { memo, type Ref, useCallback, useState } from "react";
|
|||||||
import { ErrorBoundary } from "react-error-boundary";
|
import { ErrorBoundary } from "react-error-boundary";
|
||||||
import { useInView } from "react-intersection-observer";
|
import { useInView } from "react-intersection-observer";
|
||||||
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
||||||
|
import { resolveItemImage } from "@/utils/methods/itemImages";
|
||||||
import { useApiInContext } from "@/utils/store/api";
|
import { useApiInContext } from "@/utils/store/api";
|
||||||
import LikeButton from "../buttons/likeButton";
|
import LikeButton from "../buttons/likeButton";
|
||||||
import MarkPlayedButton from "../buttons/markPlayedButton";
|
import MarkPlayedButton from "../buttons/markPlayedButton";
|
||||||
@@ -56,6 +57,10 @@ const CardContent = ({
|
|||||||
const api = useApiInContext((s) => s.api);
|
const api = useApiInContext((s) => s.api);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const image = resolveItemImage(item, imageType, {
|
||||||
|
seriesId: seriesId ? (item.SeriesId ?? undefined) : undefined,
|
||||||
|
});
|
||||||
|
|
||||||
const defaultOnClick = useCallback(() => {
|
const defaultOnClick = useCallback(() => {
|
||||||
if (item?.Id) {
|
if (item?.Id) {
|
||||||
navigate(getItemLinkOptions(item.Id, item?.Type));
|
navigate(getItemLinkOptions(item.Id, item?.Type));
|
||||||
@@ -102,20 +107,20 @@ const CardContent = ({
|
|||||||
? getTypeIcon(overrideIcon)
|
? getTypeIcon(overrideIcon)
|
||||||
: getTypeIcon(item.Type ?? "universal")}
|
: getTypeIcon(item.Type ?? "universal")}
|
||||||
</div>
|
</div>
|
||||||
{inView && (
|
{inView && image && (
|
||||||
<img
|
<img
|
||||||
alt={item.Name ?? "blink"}
|
alt={item.Name ?? "blink"}
|
||||||
src={
|
src={
|
||||||
api
|
api && image
|
||||||
? overrideIcon === "User"
|
? overrideIcon === "User"
|
||||||
? `${api?.basePath}/Users/${item.Id}/Images/Primary`
|
? `${api?.basePath}/Users/${item.Id}/Images/Primary`
|
||||||
: getImageUrlsApi(api).getItemImageUrlById(
|
: getImageUrlsApi(api).getItemImageUrlById(
|
||||||
(seriesId ? item.SeriesId : (item.AlbumId ?? item.Id)) ??
|
image.itemId,
|
||||||
"",
|
image.imageType,
|
||||||
imageType,
|
|
||||||
{
|
{
|
||||||
quality: 90,
|
quality: 90,
|
||||||
fillWidth: cardType === "thumb" ? 560 : 320,
|
fillWidth: cardType === "thumb" ? 560 : 320,
|
||||||
|
tag: image.tag,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
: ""
|
: ""
|
||||||
|
|||||||
@@ -99,14 +99,14 @@ export default function CardScroller({
|
|||||||
},
|
},
|
||||||
tablet: {
|
tablet: {
|
||||||
breakpoint: { max: 925, min: 600 },
|
breakpoint: { max: 925, min: 600 },
|
||||||
items: displayCards - 3,
|
items: Math.max(2, displayCards - 2),
|
||||||
slidesToSlide: displayCards - 3,
|
slidesToSlide: Math.max(2, displayCards - 2),
|
||||||
partialVisibilityGutter: 20,
|
partialVisibilityGutter: 20,
|
||||||
},
|
},
|
||||||
mobile: {
|
mobile: {
|
||||||
breakpoint: { max: 600, min: 424 },
|
breakpoint: { max: 600, min: 424 },
|
||||||
items: displayCards - 5,
|
items: Math.max(1, displayCards - 4),
|
||||||
slidesToSlide: displayCards - 5,
|
slidesToSlide: Math.max(1, displayCards - 4),
|
||||||
partialVisibilityGutter: 10,
|
partialVisibilityGutter: 10,
|
||||||
},
|
},
|
||||||
smallScreen: {
|
smallScreen: {
|
||||||
|
|||||||
@@ -8,6 +8,15 @@
|
|||||||
grid-template-columns: 1fr 340px;
|
grid-template-columns: 1fr 340px;
|
||||||
gap: 1.5em;
|
gap: 1.5em;
|
||||||
|
|
||||||
|
&-slide-wrapper {
|
||||||
|
grid-area: main;
|
||||||
|
position: relative;
|
||||||
|
height: 100%;
|
||||||
|
min-width: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
border-radius: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
&-sidebar {
|
&-sidebar {
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { AnimatePresence } from "motion/react";
|
import { motion } from "motion/react";
|
||||||
import React, { useCallback, useEffect, useState } from "react";
|
import React, { useCallback, useEffect, useState } from "react";
|
||||||
|
import type { Api } from "@jellyfin/sdk";
|
||||||
|
|
||||||
import { useCarouselStore } from "../../utils/store/carousel";
|
import { useCarouselStore } from "../../utils/store/carousel";
|
||||||
import "./carousel.scss";
|
import "./carousel.scss";
|
||||||
@@ -8,6 +9,7 @@ import {
|
|||||||
BaseItemKind,
|
BaseItemKind,
|
||||||
} from "@jellyfin/sdk/lib/generated-client";
|
} from "@jellyfin/sdk/lib/generated-client";
|
||||||
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
||||||
|
import { resolveItemImage } from "@/utils/methods/itemImages";
|
||||||
import { useApiInContext } from "@/utils/store/api";
|
import { useApiInContext } from "@/utils/store/api";
|
||||||
import CarouselSlide from "../carouselSlide";
|
import CarouselSlide from "../carouselSlide";
|
||||||
import CarouselTickers from "./tickers";
|
import CarouselTickers from "./tickers";
|
||||||
@@ -15,6 +17,24 @@ import CarouselTickers from "./tickers";
|
|||||||
// Memoize CarouselSlide to prevent unnecessary re-renders
|
// Memoize CarouselSlide to prevent unnecessary re-renders
|
||||||
const MemoizedCarouselSlide = React.memo(CarouselSlide);
|
const MemoizedCarouselSlide = React.memo(CarouselSlide);
|
||||||
|
|
||||||
|
/** Sidebar thumbnail: prefer Thumb, fall back to Backdrop/Primary when missing. */
|
||||||
|
const tickerImageUrl = (
|
||||||
|
api: Api,
|
||||||
|
item: BaseItemDto,
|
||||||
|
): string | undefined => {
|
||||||
|
const image = resolveItemImage(item, "Thumb");
|
||||||
|
if (!image) return undefined;
|
||||||
|
return getImageUrlsApi(api).getItemImageUrlById(
|
||||||
|
image.itemId,
|
||||||
|
image.imageType,
|
||||||
|
{
|
||||||
|
quality: 90,
|
||||||
|
fillHeight: 360,
|
||||||
|
tag: image.tag,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const Carousel = ({
|
const Carousel = ({
|
||||||
content,
|
content,
|
||||||
onChange,
|
onChange,
|
||||||
@@ -96,12 +116,15 @@ const Carousel = ({
|
|||||||
onMouseEnter={() => setIsPaused(true)}
|
onMouseEnter={() => setIsPaused(true)}
|
||||||
onMouseLeave={() => setIsPaused(false)}
|
onMouseLeave={() => setIsPaused(false)}
|
||||||
>
|
>
|
||||||
<AnimatePresence mode="sync">
|
<motion.div
|
||||||
<MemoizedCarouselSlide
|
|
||||||
item={content[currentSlide]}
|
|
||||||
key={content[currentSlide].Id}
|
key={content[currentSlide].Id}
|
||||||
/>
|
className="hero-carousel-slide-wrapper"
|
||||||
</AnimatePresence>
|
initial={{ opacity: 0 }}
|
||||||
|
animate={{ opacity: 1 }}
|
||||||
|
transition={{ duration: 0.35, ease: "easeInOut" }}
|
||||||
|
>
|
||||||
|
<MemoizedCarouselSlide item={content[currentSlide]} />
|
||||||
|
</motion.div>
|
||||||
<div className="carousel-sidebar" ref={sidebarRef}>
|
<div className="carousel-sidebar" ref={sidebarRef}>
|
||||||
{content.map((item, index) => (
|
{content.map((item, index) => (
|
||||||
<div
|
<div
|
||||||
@@ -112,18 +135,7 @@ const Carousel = ({
|
|||||||
className="carousel-ticker-wrapper"
|
className="carousel-ticker-wrapper"
|
||||||
>
|
>
|
||||||
<CarouselTickers
|
<CarouselTickers
|
||||||
imageUrl={
|
imageUrl={tickerImageUrl(api, item)}
|
||||||
item.ImageTags?.Thumb
|
|
||||||
? getImageUrlsApi(api).getItemImageUrlById(
|
|
||||||
item.Id ?? "",
|
|
||||||
"Thumb",
|
|
||||||
{
|
|
||||||
quality: 90,
|
|
||||||
fillHeight: 360,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
: undefined
|
|
||||||
}
|
|
||||||
isActive={index === currentSlide}
|
isActive={index === currentSlide}
|
||||||
itemName={item.Name ?? "Unknown"}
|
itemName={item.Name ?? "Unknown"}
|
||||||
itemYear={
|
itemYear={
|
||||||
|
|||||||
@@ -61,6 +61,16 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
|||||||
|
|
||||||
const [animationDirection] = useCarouselStore((state) => [state.direction]);
|
const [animationDirection] = useCarouselStore((state) => [state.direction]);
|
||||||
|
|
||||||
|
// Hero background: a real backdrop when the item has one, otherwise fall back
|
||||||
|
// to the poster instead of a big type icon.
|
||||||
|
const heroBackgroundSrc = item.BackdropImageTags?.length
|
||||||
|
? item.ParentBackdropItemId
|
||||||
|
? `${api?.basePath}/Items/${item.ParentBackdropItemId}/Images/Backdrop?quality=80`
|
||||||
|
: `${api?.basePath}/Items/${item.Id}/Images/Backdrop?quality=80&fillHeight=1400`
|
||||||
|
: item.ImageTags?.Primary
|
||||||
|
? `${api?.basePath}/Items/${item.Id}/Images/Primary?quality=80&fillHeight=1400`
|
||||||
|
: undefined;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="hero-carousel-slide">
|
<div className="hero-carousel-slide">
|
||||||
<motion.div
|
<motion.div
|
||||||
@@ -70,15 +80,11 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
|||||||
exit={{ opacity: 0 }}
|
exit={{ opacity: 0 }}
|
||||||
transition={{ duration: 0.4, ease: "easeInOut" }}
|
transition={{ duration: 0.4, ease: "easeInOut" }}
|
||||||
>
|
>
|
||||||
{item.BackdropImageTags?.length ? (
|
{heroBackgroundSrc ? (
|
||||||
<img
|
<img
|
||||||
alt={item.Name ?? "item"}
|
alt={item.Name ?? "item"}
|
||||||
className="hero-carousel-background-image"
|
className="hero-carousel-background-image"
|
||||||
src={
|
src={heroBackgroundSrc}
|
||||||
item.ParentBackdropItemId
|
|
||||||
? `${api?.basePath}/Items/${item.ParentBackdropItemId}/Images/Backdrop?quality=80`
|
|
||||||
: `${api?.basePath}/Items/${item.Id}/Images/Backdrop?quality=80&fillHeight=1400`
|
|
||||||
}
|
|
||||||
style={{
|
style={{
|
||||||
opacity: 0,
|
opacity: 0,
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -95,6 +95,9 @@
|
|||||||
object-fit: contain;
|
object-fit: contain;
|
||||||
object-position: left bottom;
|
object-position: left bottom;
|
||||||
filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
|
filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
|
||||||
|
// The logo is an <img> inside a line-clamped heading; as an inline image
|
||||||
|
// its box was clipped by the heading's line box (cut-off titles).
|
||||||
|
display: block;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,10 +147,15 @@
|
|||||||
@media (max-width: 1140px) {
|
@media (max-width: 1140px) {
|
||||||
.carousel {
|
.carousel {
|
||||||
height: 60vh !important;
|
height: 60vh !important;
|
||||||
|
// Never squeeze the hero below the height its own content needs,
|
||||||
|
// otherwise the title/logo is clipped by the slide's overflow.
|
||||||
|
min-height: 430px;
|
||||||
}
|
}
|
||||||
.hero-carousel {
|
.hero-carousel {
|
||||||
&-detail {
|
&-detail {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
padding: 3rem;
|
||||||
|
padding-bottom: 4rem;
|
||||||
background: linear-gradient(to top, rgba(0,0,0,0.9), transparent);
|
background: linear-gradient(to top, rgba(0,0,0,0.9), transparent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,6 +164,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&-text {
|
&-text {
|
||||||
|
// Narrow layouts: the hero column is ~400px, a 3.75rem title wraps
|
||||||
|
// to two lines and overflows the slide, clipping the top line.
|
||||||
|
font-size: 2.5rem !important;
|
||||||
|
line-height: 1.15 !important;
|
||||||
|
|
||||||
&-logo {
|
&-logo {
|
||||||
max-width: 60vw;
|
max-width: 60vw;
|
||||||
max-height: 10vh;
|
max-height: 10vh;
|
||||||
|
|||||||
@@ -0,0 +1,118 @@
|
|||||||
|
import type { BaseItemDto, ImageType } from "@jellyfin/sdk/lib/generated-client";
|
||||||
|
|
||||||
|
export type ResolvedItemImage = {
|
||||||
|
/** Item that actually owns the image (episodes borrow their series' artwork). */
|
||||||
|
itemId: string;
|
||||||
|
imageType: ImageType;
|
||||||
|
tag?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const ownFallbackOrder: Partial<Record<ImageType, ImageType[]>> = {
|
||||||
|
Primary: ["Primary", "Thumb", "Backdrop"],
|
||||||
|
Thumb: ["Thumb", "Backdrop", "Primary"],
|
||||||
|
Backdrop: ["Backdrop", "Thumb", "Primary"],
|
||||||
|
Logo: ["Logo", "Primary", "Thumb"],
|
||||||
|
Banner: ["Banner", "Backdrop", "Primary"],
|
||||||
|
Art: ["Art", "Backdrop", "Primary"],
|
||||||
|
Disc: ["Disc", "Backdrop", "Primary"],
|
||||||
|
};
|
||||||
|
|
||||||
|
const hasOwnImage = (item: BaseItemDto, type: ImageType): boolean => {
|
||||||
|
if (type === "Backdrop") {
|
||||||
|
return Boolean(item.BackdropImageTags?.length || item.ImageTags?.Backdrop);
|
||||||
|
}
|
||||||
|
return Boolean(item.ImageTags?.[type]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const ownTag = (item: BaseItemDto, type: ImageType): string | undefined => {
|
||||||
|
if (type === "Backdrop") {
|
||||||
|
return item.BackdropImageTags?.[0] ?? item.ImageTags?.Backdrop ?? undefined;
|
||||||
|
}
|
||||||
|
return item.ImageTags?.[type] ?? undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pick the best real image for an item. Many items do not have the requested
|
||||||
|
* image type (movies rarely have `Thumb`, episodes borrow artwork from their
|
||||||
|
* series), so try the item's own images first, then the series/parent ones.
|
||||||
|
* Returns `undefined` when there is genuinely nothing to show.
|
||||||
|
*/
|
||||||
|
export const resolveItemImage = (
|
||||||
|
item: BaseItemDto | undefined | null,
|
||||||
|
preferred: ImageType = "Primary",
|
||||||
|
options: { seriesId?: string | null } = {},
|
||||||
|
): ResolvedItemImage | undefined => {
|
||||||
|
if (!item) return undefined;
|
||||||
|
|
||||||
|
// Library grids show one poster per episode, owned by the series.
|
||||||
|
const seriesId = options.seriesId ?? item.SeriesId;
|
||||||
|
if (options.seriesId && seriesId) {
|
||||||
|
return {
|
||||||
|
itemId: seriesId,
|
||||||
|
imageType: "Primary",
|
||||||
|
tag: item.SeriesPrimaryImageTag ?? undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const order = ownFallbackOrder[preferred] ?? [preferred];
|
||||||
|
for (const type of order) {
|
||||||
|
if (hasOwnImage(item, type) && item.Id) {
|
||||||
|
return { itemId: item.Id, imageType: type, tag: ownTag(item, type) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Episodes (and some other child items) inherit artwork from their parent.
|
||||||
|
if (seriesId && item.SeriesPrimaryImageTag) {
|
||||||
|
return {
|
||||||
|
itemId: seriesId,
|
||||||
|
imageType: "Primary",
|
||||||
|
tag: item.SeriesPrimaryImageTag,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (seriesId && item.Type === "Episode") {
|
||||||
|
return { itemId: seriesId, imageType: "Primary" };
|
||||||
|
}
|
||||||
|
// Audio inherits its cover from the album.
|
||||||
|
if (item.AlbumId) {
|
||||||
|
return { itemId: item.AlbumId, imageType: "Primary" };
|
||||||
|
}
|
||||||
|
if (item.ParentBackdropItemId && item.ParentBackdropImageTags?.length) {
|
||||||
|
return {
|
||||||
|
itemId: item.ParentBackdropItemId,
|
||||||
|
imageType: "Backdrop",
|
||||||
|
tag: item.ParentBackdropImageTags[0],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nothing known: keep the requested type so the server gets a chance, but
|
||||||
|
// only when the item exists. Callers render their icon placeholder on 404.
|
||||||
|
if (item.Id) {
|
||||||
|
return { itemId: item.Id, imageType: preferred };
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Image tag for the resolved type, so caches reuse the exact displayed image. */
|
||||||
|
export const getImageTag = (
|
||||||
|
item: BaseItemDto | undefined | null,
|
||||||
|
type: ImageType,
|
||||||
|
series = false,
|
||||||
|
): string | undefined => {
|
||||||
|
if (!item) return undefined;
|
||||||
|
if (series && type === "Primary" && item.SeriesPrimaryImageTag) {
|
||||||
|
return item.SeriesPrimaryImageTag;
|
||||||
|
}
|
||||||
|
return ownTag(item, type);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getAvailableImageType = (
|
||||||
|
item: BaseItemDto | undefined | null,
|
||||||
|
preferred: ImageType = "Primary",
|
||||||
|
): ImageType => {
|
||||||
|
if (!item) return preferred;
|
||||||
|
const order = ownFallbackOrder[preferred] ?? [preferred];
|
||||||
|
for (const type of order) {
|
||||||
|
if (hasOwnImage(item, type)) return type;
|
||||||
|
}
|
||||||
|
return preferred;
|
||||||
|
};
|
||||||
Reference in new issue
Block a user