Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b00f93d262 | ||
|
|
4c9dd86962 |
No files matched your search
@@ -5,15 +5,20 @@ import { useBackdropStore } from "@/utils/store/backdrop";
|
||||
import BlurhashCanvas from "../blurhash-canvas";
|
||||
|
||||
export default function Backdrop() {
|
||||
// const [backdropLoading, setBackdropLoading] = useState(true);
|
||||
|
||||
const { backdropHash } = useBackdropStore(
|
||||
useShallow((state) => ({
|
||||
backdropHash: state.backdropHash,
|
||||
})),
|
||||
);
|
||||
|
||||
if (!backdropHash) {
|
||||
// Routes clear the backdrop when they mount ("") and some set it later.
|
||||
// Keep the last non-empty hash so the app background never blanks out
|
||||
// (which looked like a flash on every page open).
|
||||
const lastHash = React.useRef<string | undefined>(undefined);
|
||||
if (backdropHash) lastHash.current = backdropHash;
|
||||
const hash = backdropHash || lastHash.current;
|
||||
|
||||
if (!hash) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -22,16 +27,16 @@ export default function Backdrop() {
|
||||
<motion.div
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
key={backdropHash}
|
||||
key={hash}
|
||||
exit={{ opacity: 0 }}
|
||||
transition={{
|
||||
duration: 2,
|
||||
duration: 0.45,
|
||||
ease: "easeInOut",
|
||||
}}
|
||||
className="app-backdrop-container"
|
||||
>
|
||||
<BlurhashCanvas
|
||||
blurhashString={backdropHash}
|
||||
blurhashString={hash}
|
||||
width={300}
|
||||
height={150}
|
||||
canvasProps={{
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
transition: all $transition-time-fast;
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
top: 0;
|
||||
|
||||
@@ -107,7 +107,7 @@ const CardContent = ({
|
||||
? getTypeIcon(overrideIcon)
|
||||
: getTypeIcon(item.Type ?? "universal")}
|
||||
</div>
|
||||
{inView && image && (
|
||||
{image && (
|
||||
<img
|
||||
alt={item.Name ?? "blink"}
|
||||
src={
|
||||
@@ -128,14 +128,9 @@ const CardContent = ({
|
||||
style={{
|
||||
height: "100%",
|
||||
width: "100%",
|
||||
opacity: 0,
|
||||
display: "block",
|
||||
transition: "opacity 0.3s ease-in-out",
|
||||
}}
|
||||
loading="lazy"
|
||||
onLoad={(e) => {
|
||||
e.currentTarget.style.opacity = "1";
|
||||
}}
|
||||
className="card-image"
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { motion } from "motion/react";
|
||||
import React, { useCallback, useEffect, useState } from "react";
|
||||
import type { Api } from "@jellyfin/sdk";
|
||||
|
||||
@@ -116,15 +115,9 @@ const Carousel = ({
|
||||
onMouseEnter={() => setIsPaused(true)}
|
||||
onMouseLeave={() => setIsPaused(false)}
|
||||
>
|
||||
<motion.div
|
||||
key={content[currentSlide].Id}
|
||||
className="hero-carousel-slide-wrapper"
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
transition={{ duration: 0.35, ease: "easeInOut" }}
|
||||
>
|
||||
<div className="hero-carousel-slide-wrapper">
|
||||
<MemoizedCarouselSlide item={content[currentSlide]} />
|
||||
</motion.div>
|
||||
</div>
|
||||
<div className="carousel-sidebar" ref={sidebarRef}>
|
||||
{content.map((item, index) => (
|
||||
<div
|
||||
|
||||
@@ -8,9 +8,16 @@ import { green, red, yellow } from "@mui/material/colors";
|
||||
import Stack from "@mui/material/Stack";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import { useNavigate } from "@tanstack/react-router";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { motion, type Variants } from "motion/react";
|
||||
import React from "react";
|
||||
import { endsAt, getRuntime } from "@/utils/date/time";
|
||||
import {
|
||||
getHeroPosterUrl,
|
||||
getItemImagesQueryOptions,
|
||||
resolveHeroArtwork,
|
||||
} from "@/utils/methods/heroArtwork";
|
||||
import BlurhashCanvas from "../blurhash-canvas";
|
||||
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useCarouselStore } from "@/utils/store/carousel";
|
||||
@@ -25,10 +32,11 @@ const MotionTypography = motion.create(Typography);
|
||||
const MotionStack = motion.create(Stack);
|
||||
|
||||
const textVariants: Variants = {
|
||||
initial: (direction: string) => ({
|
||||
x: direction === "right" ? 40 : -40,
|
||||
opacity: 0,
|
||||
}),
|
||||
// No hidden start state: hero text must not blink on slide changes.
|
||||
initial: {
|
||||
x: 0,
|
||||
opacity: 1,
|
||||
},
|
||||
animate: {
|
||||
x: 0,
|
||||
opacity: 1,
|
||||
@@ -61,36 +69,38 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
||||
|
||||
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`
|
||||
// Jellyfin stores several images per item (poster, thumb, backdrops).
|
||||
// Ask the server which ones exist and their real size, then pick the wide one.
|
||||
const imageInfos = useQuery(getItemImagesQueryOptions(api, item.Id));
|
||||
const heroArtwork = resolveHeroArtwork(api, item, imageInfos.data);
|
||||
const heroPoster = heroArtwork?.isPortrait
|
||||
? getHeroPosterUrl(api, item)
|
||||
: undefined;
|
||||
|
||||
return (
|
||||
<div className="hero-carousel-slide">
|
||||
<motion.div
|
||||
className="hero-carousel-background-container"
|
||||
initial={{ opacity: 0 }}
|
||||
initial={{ opacity: 1 }}
|
||||
animate={{ opacity: 1 }}
|
||||
exit={{ opacity: 0 }}
|
||||
transition={{ duration: 0.4, ease: "easeInOut" }}
|
||||
>
|
||||
{heroBackgroundSrc ? (
|
||||
{heroArtwork?.blurhash && (
|
||||
<BlurhashCanvas
|
||||
blurhashString={heroArtwork.blurhash}
|
||||
width={48}
|
||||
height={27}
|
||||
canvasProps={{
|
||||
className: "hero-carousel-background-blurhash",
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{heroArtwork ? (
|
||||
<img
|
||||
alt={item.Name ?? "item"}
|
||||
className="hero-carousel-background-image"
|
||||
src={heroBackgroundSrc}
|
||||
style={{
|
||||
opacity: 0,
|
||||
}}
|
||||
onLoad={(e) => {
|
||||
e.currentTarget.style.opacity = "1";
|
||||
}}
|
||||
className={`hero-carousel-background-image${heroArtwork.isPortrait ? " is-poster" : ""}`}
|
||||
src={heroArtwork.url}
|
||||
loading="eager"
|
||||
/>
|
||||
) : (
|
||||
@@ -98,6 +108,14 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
||||
{getTypeIcon(item.Type ?? "Movie")}
|
||||
</div>
|
||||
)}
|
||||
{heroPoster && (
|
||||
<img
|
||||
alt={item.Name ?? "poster"}
|
||||
className="hero-carousel-poster"
|
||||
src={heroPoster}
|
||||
loading="eager"
|
||||
/>
|
||||
)}
|
||||
</motion.div>
|
||||
<motion.div
|
||||
className="hero-carousel-detail"
|
||||
|
||||
@@ -21,10 +21,12 @@ interface ItemBackdropProps {
|
||||
const MotionImg = motion.img;
|
||||
|
||||
const animationProps = {
|
||||
initial: { opacity: 0 },
|
||||
// Do not fade in from black on every navigation: cached artwork should be
|
||||
// visible immediately (a fade here reads as a flash).
|
||||
initial: { opacity: 1 },
|
||||
animate: { opacity: 1 },
|
||||
exit: { opacity: 0 },
|
||||
transition: { duration: 0.5 },
|
||||
transition: { duration: 0.3 },
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -113,6 +115,9 @@ export function ItemBackdrop({
|
||||
alt={alt}
|
||||
src={src}
|
||||
className={className ?? "item-hero-backdrop"}
|
||||
ref={(el) => {
|
||||
if (el?.complete && el.naturalWidth > 0) el.style.opacity = "1";
|
||||
}}
|
||||
onLoad={(e) => {
|
||||
e.currentTarget.style.opacity = "1";
|
||||
onLoad?.(e);
|
||||
|
||||
@@ -101,8 +101,6 @@
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
opacity: 0;
|
||||
transition: opacity $transition-time-default;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
|
||||
@@ -77,9 +77,6 @@ const ItemHeader = ({
|
||||
tag: logoTag,
|
||||
})
|
||||
}
|
||||
onLoad={(e) => {
|
||||
e.currentTarget.style.opacity = "1";
|
||||
}}
|
||||
className="item-hero-logo"
|
||||
/>
|
||||
) : (
|
||||
@@ -143,9 +140,6 @@ const ItemHeader = ({
|
||||
},
|
||||
)
|
||||
}
|
||||
onLoad={(e) => {
|
||||
e.currentTarget.style.opacity = "1";
|
||||
}}
|
||||
className="item-hero-image"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -12,10 +12,8 @@ $cardWidth: 18%;
|
||||
grid-template-columns: $cardWidth 1fr;
|
||||
grid-template-rows: 1fr auto;
|
||||
&-image {
|
||||
opacity: 0;
|
||||
width: 100%;
|
||||
object-fit: contain;
|
||||
transition: opacity $transition-time-default;
|
||||
&-container {
|
||||
height: fit-content;
|
||||
max-height: 100%;
|
||||
@@ -47,8 +45,6 @@ $cardWidth: 18%;
|
||||
&-logo {
|
||||
max-width: 34rem;
|
||||
max-height: 10rem;
|
||||
opacity: 0;
|
||||
transition: opacity $transition-time-default;
|
||||
object-position: bottom;
|
||||
margin-bottom: 2em;
|
||||
}
|
||||
@@ -74,11 +70,9 @@ $cardWidth: 18%;
|
||||
height: 100vh;
|
||||
object-fit: cover;
|
||||
object-position: top;
|
||||
opacity: 0;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
transition: opacity $transition-time-default;
|
||||
&-container {
|
||||
filter: brightness(0.8);
|
||||
position: absolute;
|
||||
|
||||
@@ -1,10 +1,24 @@
|
||||
import { CircularProgress } from "@mui/material";
|
||||
import { useRouterState } from "@tanstack/react-router";
|
||||
import React from "react";
|
||||
import React, { useEffect, useState } from "react";
|
||||
|
||||
/** Only show the full-screen loader for genuinely slow navigations. */
|
||||
const SHOW_DELAY_MS = 250;
|
||||
|
||||
export default function RouterLoading() {
|
||||
const routeLoading = useRouterState().isLoading;
|
||||
if (!routeLoading) return null;
|
||||
const [visible, setVisible] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!routeLoading) {
|
||||
setVisible(false);
|
||||
return;
|
||||
}
|
||||
const timer = setTimeout(() => setVisible(true), SHOW_DELAY_MS);
|
||||
return () => clearTimeout(timer);
|
||||
}, [routeLoading]);
|
||||
|
||||
if (!visible) return null;
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ const router = createRouter({
|
||||
},
|
||||
defaultPreload: false,
|
||||
defaultPreloadStaleTime: 0,
|
||||
defaultViewTransition: true,
|
||||
defaultViewTransition: false,
|
||||
scrollRestoration: true,
|
||||
scrollRestorationBehavior: "auto",
|
||||
});
|
||||
|
||||
@@ -57,7 +57,22 @@
|
||||
object-fit: cover;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
transition: opacity 0.5s;
|
||||
|
||||
// Poster-only item: never stretch/crop a 2:3 poster across 16:9.
|
||||
// Blur it into an ambient background and show the sharp poster on top.
|
||||
&.is-poster {
|
||||
filter: blur(36px) saturate(1.6) brightness(0.65);
|
||||
transform: scale(1.25);
|
||||
}
|
||||
}
|
||||
|
||||
&-blurhash {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
width: 100% !important;
|
||||
height: 100% !important;
|
||||
z-index: 0;
|
||||
filter: blur(30px) saturate(1.4);
|
||||
}
|
||||
|
||||
&-icon-container {
|
||||
@@ -101,6 +116,20 @@
|
||||
}
|
||||
}
|
||||
|
||||
&-poster {
|
||||
position: absolute;
|
||||
z-index: 3;
|
||||
right: 7%;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
height: 66%;
|
||||
max-width: 26%;
|
||||
object-fit: contain;
|
||||
border-radius: 14px;
|
||||
box-shadow: 0 24px 60px rgb(0 0 0 / 0.65), 0 0 0 1px rgb(255 255 255 / 0.08);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
&-overview {
|
||||
overflow: hidden;
|
||||
margin-bottom: 0.5em;
|
||||
@@ -152,6 +181,10 @@
|
||||
min-height: 430px;
|
||||
}
|
||||
.hero-carousel {
|
||||
&-poster {
|
||||
display: none;
|
||||
}
|
||||
|
||||
&-detail {
|
||||
width: 100%;
|
||||
padding: 3rem;
|
||||
|
||||
@@ -142,19 +142,20 @@ function HomeContent({ api, user }: { api: Api; user: UserDto }) {
|
||||
|
||||
const setBackdropForItem = useCallback(
|
||||
(item: BaseItemDto) => {
|
||||
if (item?.ParentBackdropImageTags) {
|
||||
setBackdrop(
|
||||
item.ImageBlurHashes?.Backdrop?.[item.ParentBackdropImageTags[0]],
|
||||
);
|
||||
} else {
|
||||
if (!item?.BackdropImageTags) {
|
||||
setBackdrop(undefined);
|
||||
// Use the wide artwork when present, otherwise the poster's BlurHash as
|
||||
// an ambient background (poster-only items would otherwise leave it dark).
|
||||
const backdropTag =
|
||||
item.ParentBackdropImageTags?.[0] ?? item.BackdropImageTags?.[0];
|
||||
if (backdropTag) {
|
||||
setBackdrop(item.ImageBlurHashes?.Backdrop?.[backdropTag] ?? undefined);
|
||||
return;
|
||||
}
|
||||
const primaryTag = item.ImageTags?.Primary;
|
||||
setBackdrop(
|
||||
item.ImageBlurHashes?.Backdrop?.[item.BackdropImageTags[0]],
|
||||
primaryTag
|
||||
? (item.ImageBlurHashes?.Primary?.[primaryTag] ?? undefined)
|
||||
: undefined,
|
||||
);
|
||||
}
|
||||
},
|
||||
[setBackdrop],
|
||||
);
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
import type { Api } from "@jellyfin/sdk";
|
||||
import type {
|
||||
BaseItemDto,
|
||||
ImageInfo,
|
||||
ImageType,
|
||||
} from "@jellyfin/sdk/lib/generated-client";
|
||||
import { getImageApi } from "@jellyfin/sdk/lib/utils/api/image-api";
|
||||
import { queryOptions } from "@tanstack/react-query";
|
||||
|
||||
export type HeroArtwork = {
|
||||
url: string;
|
||||
/** Primary (poster) is portrait; it must not be cropped into a 16:9 hero. */
|
||||
isPortrait: boolean;
|
||||
/** BlurHash for the chosen image, used as an instant placeholder. */
|
||||
blurhash?: string;
|
||||
};
|
||||
|
||||
/** All images Jellyfin actually stores for an item (with real resolutions). */
|
||||
export const getItemImagesQueryOptions = (
|
||||
api: Api | null | undefined,
|
||||
itemId: string | undefined | null,
|
||||
) =>
|
||||
queryOptions({
|
||||
queryKey: ["item", "images", itemId],
|
||||
queryFn: async () => {
|
||||
if (!api || !itemId) return [];
|
||||
const result = await getImageApi(api).getItemImageInfos({ itemId });
|
||||
return result.data;
|
||||
},
|
||||
enabled: Boolean(api && itemId),
|
||||
staleTime: 30 * 60_000,
|
||||
});
|
||||
|
||||
/** Prefer the biggest wide image Jellyfin has; Backdrop wins ties over Thumb. */
|
||||
const pickWideImage = (images: ImageInfo[]): ImageInfo | undefined => {
|
||||
const wide = images.filter((image) => {
|
||||
if (image.ImageType !== "Backdrop" && image.ImageType !== "Thumb") {
|
||||
return false;
|
||||
}
|
||||
const width = image.Width ?? 0;
|
||||
const height = image.Height ?? 0;
|
||||
return height > 0 && width / height >= 1.3;
|
||||
});
|
||||
wide.sort((a, b) => {
|
||||
const area = (i: ImageInfo) => (i.Width ?? 0) * (i.Height ?? 0);
|
||||
const diff = area(b) - area(a);
|
||||
if (diff !== 0) return diff;
|
||||
return a.ImageType === "Backdrop" ? -1 : 1;
|
||||
});
|
||||
return wide[0];
|
||||
};
|
||||
|
||||
const imageUrl = (
|
||||
api: Api,
|
||||
itemId: string,
|
||||
type: ImageType,
|
||||
tag: string | null | undefined,
|
||||
params: { maxWidth?: number; maxHeight?: number },
|
||||
) => {
|
||||
const query = new URLSearchParams();
|
||||
if (tag) query.set("tag", tag);
|
||||
if (params.maxWidth) query.set("maxWidth", String(params.maxWidth));
|
||||
if (params.maxHeight) query.set("maxHeight", String(params.maxHeight));
|
||||
query.set("quality", "90");
|
||||
return `${api.basePath}/Items/${itemId}/Images/${type}?${query.toString()}`;
|
||||
};
|
||||
|
||||
const blurhashFor = (
|
||||
item: BaseItemDto,
|
||||
type: ImageType,
|
||||
tag: string | null | undefined,
|
||||
) => (tag ? item.ImageBlurHashes?.[type]?.[tag] ?? undefined : undefined);
|
||||
|
||||
/**
|
||||
* Best artwork for the home hero (a wide 16:9 area).
|
||||
*
|
||||
* Jellyfin usually stores several images per item; the player/hero should use
|
||||
* a wide one: Backdrop, then Thumb (often a 4K still). A Primary poster is 2:3,
|
||||
* so it is only used when nothing wide exists, and the caller renders it as a
|
||||
* poster on a blurred background instead of stretching it.
|
||||
*/
|
||||
export const resolveHeroArtwork = (
|
||||
api: Api | undefined,
|
||||
item: BaseItemDto | undefined | null,
|
||||
images: ImageInfo[] | undefined,
|
||||
): HeroArtwork | undefined => {
|
||||
if (!api || !item?.Id) return undefined;
|
||||
|
||||
const wide = images?.length ? pickWideImage(images) : undefined;
|
||||
if (wide) {
|
||||
return {
|
||||
url: imageUrl(api, item.Id, wide.ImageType as ImageType, wide.ImageTag, {
|
||||
maxWidth: 1920,
|
||||
}),
|
||||
isPortrait: false,
|
||||
blurhash: blurhashFor(item, wide.ImageType as ImageType, wide.ImageTag),
|
||||
};
|
||||
}
|
||||
|
||||
// Fall back to tags while /Images is still loading (or for servers that
|
||||
// don't return image infos).
|
||||
if (item.BackdropImageTags?.length) {
|
||||
return {
|
||||
url: imageUrl(api, item.Id, "Backdrop", item.BackdropImageTags[0], {
|
||||
maxWidth: 1920,
|
||||
}),
|
||||
isPortrait: false,
|
||||
blurhash: blurhashFor(item, "Backdrop", item.BackdropImageTags[0]),
|
||||
};
|
||||
}
|
||||
if (item.ImageTags?.Thumb) {
|
||||
return {
|
||||
url: imageUrl(api, item.Id, "Thumb", item.ImageTags.Thumb, {
|
||||
maxWidth: 1920,
|
||||
}),
|
||||
isPortrait: false,
|
||||
blurhash: blurhashFor(item, "Thumb", item.ImageTags.Thumb),
|
||||
};
|
||||
}
|
||||
if (item.ImageTags?.Primary) {
|
||||
return {
|
||||
url: imageUrl(api, item.Id, "Primary", item.ImageTags.Primary, {
|
||||
maxHeight: 1400,
|
||||
}),
|
||||
isPortrait: true,
|
||||
blurhash: blurhashFor(item, "Primary", item.ImageTags.Primary),
|
||||
};
|
||||
}
|
||||
if (item.ParentBackdropItemId && item.ParentBackdropImageTags?.length) {
|
||||
return {
|
||||
url: imageUrl(
|
||||
api,
|
||||
item.ParentBackdropItemId,
|
||||
"Backdrop",
|
||||
item.ParentBackdropImageTags[0],
|
||||
{ maxWidth: 1920 },
|
||||
),
|
||||
isPortrait: false,
|
||||
blurhash: blurhashFor(
|
||||
item,
|
||||
"Backdrop",
|
||||
item.ParentBackdropImageTags[0],
|
||||
),
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
/** Sharp poster URL for the poster-on-blurred-background hero treatment. */
|
||||
export const getHeroPosterUrl = (
|
||||
api: Api | undefined,
|
||||
item: BaseItemDto | undefined | null,
|
||||
) => {
|
||||
if (!api || !item?.Id || !item.ImageTags?.Primary) return undefined;
|
||||
return imageUrl(api, item.Id, "Primary", item.ImageTags.Primary, {
|
||||
maxHeight: 900,
|
||||
});
|
||||
};
|
||||
Reference in new issue
Block a user