diff --git a/src/components/backdrop/index.tsx b/src/components/backdrop/index.tsx index dcf53f5..26cf5fd 100644 --- a/src/components/backdrop/index.tsx +++ b/src/components/backdrop/index.tsx @@ -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(undefined); + if (backdropHash) lastHash.current = backdropHash; + const hash = backdropHash || lastHash.current; + + if (!hash) { return null; } @@ -22,16 +27,16 @@ export default function Backdrop() { ); -} \ No newline at end of file +} diff --git a/src/components/card/card.scss b/src/components/card/card.scss index 109601e..802f3d5 100644 --- a/src/components/card/card.scss +++ b/src/components/card/card.scss @@ -18,7 +18,6 @@ width: 100%; height: 100%; object-fit: cover; - transition: all $transition-time-fast; position: absolute; z-index: 1; top: 0; diff --git a/src/components/card/card.tsx b/src/components/card/card.tsx index 294f556..acf9121 100644 --- a/src/components/card/card.tsx +++ b/src/components/card/card.tsx @@ -107,7 +107,7 @@ const CardContent = ({ ? getTypeIcon(overrideIcon) : getTypeIcon(item.Type ?? "universal")} - {inView && image && ( + {image && ( {item.Name { - e.currentTarget.style.opacity = "1"; - }} className="card-image" /> )} diff --git a/src/components/itemBackdrop/index.tsx b/src/components/itemBackdrop/index.tsx index 6c4619c..d9e18d0 100644 --- a/src/components/itemBackdrop/index.tsx +++ b/src/components/itemBackdrop/index.tsx @@ -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); diff --git a/src/components/itemDetail/itemDetail.scss b/src/components/itemDetail/itemDetail.scss index b3ccad2..2b226c2 100644 --- a/src/components/itemDetail/itemDetail.scss +++ b/src/components/itemDetail/itemDetail.scss @@ -101,8 +101,6 @@ width: 100%; height: 100%; object-fit: cover; - opacity: 0; - transition: opacity $transition-time-default; position: absolute; top: 0; left: 0; diff --git a/src/components/itemHeader/index.tsx b/src/components/itemHeader/index.tsx index ce0ae83..b4b5090 100644 --- a/src/components/itemHeader/index.tsx +++ b/src/components/itemHeader/index.tsx @@ -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" /> diff --git a/src/components/itemHeader/itemHeader.scss b/src/components/itemHeader/itemHeader.scss index 7a91d21..f7b16fb 100644 --- a/src/components/itemHeader/itemHeader.scss +++ b/src/components/itemHeader/itemHeader.scss @@ -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; diff --git a/src/components/routerLoading/index.tsx b/src/components/routerLoading/index.tsx index 7460d6c..260dcb8 100644 --- a/src/components/routerLoading/index.tsx +++ b/src/components/routerLoading/index.tsx @@ -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 (
); -} \ No newline at end of file +} diff --git a/src/main.tsx b/src/main.tsx index 814c794..68b7c1b 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -43,7 +43,7 @@ const router = createRouter({ }, defaultPreload: false, defaultPreloadStaleTime: 0, - defaultViewTransition: true, + defaultViewTransition: false, scrollRestoration: true, scrollRestorationBehavior: "auto", }); diff --git a/src/routes/_api/home/index.tsx b/src/routes/_api/home/index.tsx index b3e3ce7..37b38ab 100644 --- a/src/routes/_api/home/index.tsx +++ b/src/routes/_api/home/index.tsx @@ -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); - return; - } - setBackdrop( - item.ImageBlurHashes?.Backdrop?.[item.BackdropImageTags[0]], - ); + // 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( + primaryTag + ? (item.ImageBlurHashes?.Primary?.[primaryTag] ?? undefined) + : undefined, + ); }, [setBackdrop], );