fix: home page carousel causing scroll on item change and fix other performance issues

This commit is contained in:
--remove-section committed 2026-01-28 21:07:11 +05:30
1 parent 4ade92bccc
commit 7804ab2b86
5 files changed
+64 -38

No files matched your search

-12
View File
@@ -54,7 +54,6 @@ const CardContent = ({
}) => { }) => {
const api = useApiInContext((s) => s.api); const api = useApiInContext((s) => s.api);
const navigate = useNavigate(); const navigate = useNavigate();
const [isHovered, setIsHovered] = useState(false);
const defaultOnClick = useCallback(() => { const defaultOnClick = useCallback(() => {
if (item?.Id) { if (item?.Id) {
@@ -87,18 +86,11 @@ const CardContent = ({
} }
}, [item?.Id, item?.Type, navigate]); }, [item?.Id, item?.Type, navigate]);
const handleInteractionStart = useCallback(() => setIsHovered(true), []);
const handleInteractionEnd = useCallback(() => setIsHovered(false), []);
return ( return (
<div <div
className="card" className="card"
ref={forwardedRef} ref={forwardedRef}
onClick={onClick || defaultOnClick} onClick={onClick || defaultOnClick}
onMouseEnter={handleInteractionStart}
onMouseLeave={handleInteractionEnd}
onFocus={handleInteractionStart}
onBlur={handleInteractionEnd}
> >
<div className={`card-image-container ${cardType}`}> <div className={`card-image-container ${cardType}`}>
<ErrorBoundary fallback={<></>}> <ErrorBoundary fallback={<></>}>
@@ -168,8 +160,6 @@ const CardContent = ({
)} )}
{inView && !disableOverlay && ( {inView && !disableOverlay && (
<div className="card-overlay"> <div className="card-overlay">
{isHovered && (
<>
<PlayButton <PlayButton
item={item} item={item}
userId={userId} userId={userId}
@@ -199,8 +189,6 @@ const CardContent = ({
queryKey={queryKey} queryKey={queryKey}
userId={userId} userId={userId}
/> />
</>
)}
</div> </div>
)} )}
{(item.UserData?.PlaybackPositionTicks ?? -1) > 0 && ( {(item.UserData?.PlaybackPositionTicks ?? -1) > 0 && (
+5
View File
@@ -11,6 +11,7 @@
&-sidebar { &-sidebar {
overflow-y: auto; overflow-y: auto;
height: 100%; height: 100%;
position: relative;
@include glass-effect($bg-color: rgba(10, 10, 14, 0.4)); @include glass-effect($bg-color: rgba(10, 10, 14, 0.4));
border-radius: 24px; border-radius: 24px;
grid-area: sidebar; grid-area: sidebar;
@@ -171,3 +172,7 @@
} }
} }
} }
.carousel-ticker-wrapper {
scroll-margin-block: 24px;
}
+33 -8
View File
@@ -26,19 +26,43 @@ const Carousel = ({
const [isPaused, setIsPaused] = useState(false); const [isPaused, setIsPaused] = useState(false);
const sidebarRef = React.useRef<HTMLDivElement>(null); const sidebarRef = React.useRef<HTMLDivElement>(null);
const tickerRefs = React.useRef<(HTMLDivElement | null)[]>([]); const tickerRefs = React.useRef<(HTMLDivElement | null)[]>([]);
const currentSlideRef = React.useRef(currentSlide);
const [setDirection] = useCarouselStore((state) => [state.setDirection]); const [setDirection] = useCarouselStore((state) => [state.setDirection]);
useEffect(() => {
currentSlideRef.current = currentSlide;
}, [currentSlide]);
useEffect(() => { useEffect(() => {
onChange(currentSlide); onChange(currentSlide);
// Auto-scroll sidebar to keep active item in view // Auto-scroll sidebar to keep active item in view
if (tickerRefs.current[currentSlide]) { const activeTicker = tickerRefs.current[currentSlide];
tickerRefs.current[currentSlide]?.scrollIntoView({ const sidebar = sidebarRef.current;
if (activeTicker && sidebar) {
const sidebarTop = sidebar.scrollTop;
const sidebarBottom = sidebarTop + sidebar.clientHeight;
const activeTickerTop = activeTicker.offsetTop;
const activeTickerBottom =
activeTicker.offsetTop + activeTicker.offsetHeight;
// If element is below the visible area
if (activeTickerBottom > sidebarBottom) {
sidebar.scrollTo({
top: activeTickerBottom - sidebar.clientHeight + 24, // 24px padding
behavior: "smooth", behavior: "smooth",
block: "nearest",
}); });
} }
// If element is above the visible area
else if (activeTickerTop < sidebarTop) {
sidebar.scrollTo({
top: activeTickerTop - 24, // 24px padding
behavior: "smooth",
});
}
}
}, [currentSlide, content, onChange]); }, [currentSlide, content, onChange]);
// Autoplay functionality // Autoplay functionality
@@ -57,11 +81,11 @@ const Carousel = ({
const handleTickerClick = useCallback( const handleTickerClick = useCallback(
(index: number) => { (index: number) => {
if (index === currentSlide) return; if (index === currentSlideRef.current) return;
setDirection(index > currentSlide ? "right" : "left"); setDirection(index > currentSlideRef.current ? "right" : "left");
setCurrentSlide(index); setCurrentSlide(index);
}, },
[currentSlide, setDirection], [setDirection],
); );
if (!api) return null; if (!api) return null;
@@ -85,7 +109,7 @@ const Carousel = ({
ref={(el) => { ref={(el) => {
tickerRefs.current[index] = el; tickerRefs.current[index] = el;
}} }}
style={{ scrollMarginBlock: "24px" }} className="carousel-ticker-wrapper"
> >
<CarouselTickers <CarouselTickers
imageUrl={ imageUrl={
@@ -105,7 +129,8 @@ const Carousel = ({
? `${item.ProductionYear ?? ""} - ${new Date(item.EndDate).getFullYear().toString()}` ? `${item.ProductionYear ?? ""} - ${new Date(item.EndDate).getFullYear().toString()}`
: (item.ProductionYear?.toString() ?? "") : (item.ProductionYear?.toString() ?? "")
} }
onClick={() => handleTickerClick(index)} onTickerClick={handleTickerClick}
index={index}
/> />
</div> </div>
))} ))}
+13 -5
View File
@@ -5,21 +5,28 @@ type CarouselTickersProps = {
imageUrl?: string; imageUrl?: string;
itemName: string; itemName: string;
itemYear: string; itemYear: string;
onClick: () => void; onTickerClick: (index: number) => void;
index: number;
isActive: boolean; isActive: boolean;
}; };
const CarouselTickers = ({ const CarouselTickers = React.memo(
({
imageUrl, imageUrl,
itemName, itemName,
itemYear, itemYear,
onClick, onTickerClick,
index,
isActive, isActive,
}: CarouselTickersProps) => { }: CarouselTickersProps) => {
const handleClick = React.useCallback(() => {
onTickerClick(index);
}, [index, onTickerClick]);
return ( return (
<div <div
className={`carousel-ticker${isActive ? " active" : ""}`} className={`carousel-ticker${isActive ? " active" : ""}`}
onClick={onClick} onClick={handleClick}
> >
<img <img
src={imageUrl} src={imageUrl}
@@ -37,5 +44,6 @@ const CarouselTickers = ({
</div> </div>
</div> </div>
); );
}; },
);
export default CarouselTickers; export default CarouselTickers;
+13 -13
View File
@@ -201,10 +201,10 @@ export interface FileRoutesByFullPath {
'/setup/server/add': typeof SetupServerAddRoute '/setup/server/add': typeof SetupServerAddRoute
'/setup/server/error': typeof SetupServerErrorRoute '/setup/server/error': typeof SetupServerErrorRoute
'/setup/server/list': typeof SetupServerListRoute '/setup/server/list': typeof SetupServerListRoute
'/favorite': typeof ApiFavoriteIndexRoute '/favorite/': typeof ApiFavoriteIndexRoute
'/home': typeof ApiHomeIndexRoute '/home/': typeof ApiHomeIndexRoute
'/player': typeof ApiPlayerIndexRoute '/player/': typeof ApiPlayerIndexRoute
'/search': typeof ApiSearchIndexRoute '/search/': typeof ApiSearchIndexRoute
'/login/$userId/$userName': typeof ApiLoginUserIdUserNameRoute '/login/$userId/$userName': typeof ApiLoginUserIdUserNameRoute
} }
export interface FileRoutesByTo { export interface FileRoutesByTo {
@@ -292,10 +292,10 @@ export interface FileRouteTypes {
| '/setup/server/add' | '/setup/server/add'
| '/setup/server/error' | '/setup/server/error'
| '/setup/server/list' | '/setup/server/list'
| '/favorite' | '/favorite/'
| '/home' | '/home/'
| '/player' | '/player/'
| '/search' | '/search/'
| '/login/$userId/$userName' | '/login/$userId/$userName'
fileRoutesByTo: FileRoutesByTo fileRoutesByTo: FileRoutesByTo
to: to:
@@ -372,7 +372,7 @@ declare module '@tanstack/react-router' {
'/_api': { '/_api': {
id: '/_api' id: '/_api'
path: '' path: ''
fullPath: '' fullPath: '/'
preLoaderRoute: typeof ApiRouteImport preLoaderRoute: typeof ApiRouteImport
parentRoute: typeof rootRouteImport parentRoute: typeof rootRouteImport
} }
@@ -407,28 +407,28 @@ declare module '@tanstack/react-router' {
'/_api/search/': { '/_api/search/': {
id: '/_api/search/' id: '/_api/search/'
path: '/search' path: '/search'
fullPath: '/search' fullPath: '/search/'
preLoaderRoute: typeof ApiSearchIndexRouteImport preLoaderRoute: typeof ApiSearchIndexRouteImport
parentRoute: typeof ApiRoute parentRoute: typeof ApiRoute
} }
'/_api/player/': { '/_api/player/': {
id: '/_api/player/' id: '/_api/player/'
path: '/player' path: '/player'
fullPath: '/player' fullPath: '/player/'
preLoaderRoute: typeof ApiPlayerIndexRouteImport preLoaderRoute: typeof ApiPlayerIndexRouteImport
parentRoute: typeof ApiRoute parentRoute: typeof ApiRoute
} }
'/_api/home/': { '/_api/home/': {
id: '/_api/home/' id: '/_api/home/'
path: '/home' path: '/home'
fullPath: '/home' fullPath: '/home/'
preLoaderRoute: typeof ApiHomeIndexRouteImport preLoaderRoute: typeof ApiHomeIndexRouteImport
parentRoute: typeof ApiRoute parentRoute: typeof ApiRoute
} }
'/_api/favorite/': { '/_api/favorite/': {
id: '/_api/favorite/' id: '/_api/favorite/'
path: '/favorite' path: '/favorite'
fullPath: '/favorite' fullPath: '/favorite/'
preLoaderRoute: typeof ApiFavoriteIndexRouteImport preLoaderRoute: typeof ApiFavoriteIndexRouteImport
parentRoute: typeof ApiRoute parentRoute: typeof ApiRoute
} }