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
+120 -94

No files matched your search

+29 -41
View File
@@ -54,7 +54,6 @@ const CardContent = ({
}) => {
const api = useApiInContext((s) => s.api);
const navigate = useNavigate();
const [isHovered, setIsHovered] = useState(false);
const defaultOnClick = useCallback(() => {
if (item?.Id) {
@@ -87,18 +86,11 @@ const CardContent = ({
}
}, [item?.Id, item?.Type, navigate]);
const handleInteractionStart = useCallback(() => setIsHovered(true), []);
const handleInteractionEnd = useCallback(() => setIsHovered(false), []);
return (
<div
className="card"
ref={forwardedRef}
onClick={onClick || defaultOnClick}
onMouseEnter={handleInteractionStart}
onMouseLeave={handleInteractionEnd}
onFocus={handleInteractionStart}
onBlur={handleInteractionEnd}
>
<div className={`card-image-container ${cardType}`}>
<ErrorBoundary fallback={<></>}>
@@ -168,39 +160,35 @@ const CardContent = ({
)}
{inView && !disableOverlay && (
<div className="card-overlay">
{isHovered && (
<>
<PlayButton
item={item}
userId={userId}
itemType={item.Type ?? "Movie"}
className="card-play-button"
iconOnly
audio={
item.Type === BaseItemKind.MusicAlbum ||
item.Type === BaseItemKind.Audio ||
item.Type === BaseItemKind.AudioBook ||
item.Type === BaseItemKind.Playlist
}
playlistItem={item.Type === BaseItemKind.Playlist}
playlistItemId={item.Id}
/>
<LikeButton
itemId={item.Id}
itemName={item.Name ?? ""}
isFavorite={item.UserData?.IsFavorite}
queryKey={queryKey}
userId={userId}
/>
<MarkPlayedButton
itemId={item.Id}
itemName={item.Name ?? ""}
isPlayed={item.UserData?.Played}
queryKey={queryKey}
userId={userId}
/>
</>
)}
<PlayButton
item={item}
userId={userId}
itemType={item.Type ?? "Movie"}
className="card-play-button"
iconOnly
audio={
item.Type === BaseItemKind.MusicAlbum ||
item.Type === BaseItemKind.Audio ||
item.Type === BaseItemKind.AudioBook ||
item.Type === BaseItemKind.Playlist
}
playlistItem={item.Type === BaseItemKind.Playlist}
playlistItemId={item.Id}
/>
<LikeButton
itemId={item.Id}
itemName={item.Name ?? ""}
isFavorite={item.UserData?.IsFavorite}
queryKey={queryKey}
userId={userId}
/>
<MarkPlayedButton
itemId={item.Id}
itemName={item.Name ?? ""}
isPlayed={item.UserData?.Played}
queryKey={queryKey}
userId={userId}
/>
</div>
)}
{(item.UserData?.PlaybackPositionTicks ?? -1) > 0 && (
+6 -1
View File
@@ -11,6 +11,7 @@
&-sidebar {
overflow-y: auto;
height: 100%;
position: relative;
@include glass-effect($bg-color: rgba(10, 10, 14, 0.4));
border-radius: 24px;
grid-area: sidebar;
@@ -170,4 +171,8 @@
}
}
}
}
}
.carousel-ticker-wrapper {
scroll-margin-block: 24px;
}
+35 -10
View File
@@ -26,18 +26,42 @@ const Carousel = ({
const [isPaused, setIsPaused] = useState(false);
const sidebarRef = React.useRef<HTMLDivElement>(null);
const tickerRefs = React.useRef<(HTMLDivElement | null)[]>([]);
const currentSlideRef = React.useRef(currentSlide);
const [setDirection] = useCarouselStore((state) => [state.setDirection]);
useEffect(() => {
currentSlideRef.current = currentSlide;
}, [currentSlide]);
useEffect(() => {
onChange(currentSlide);
// Auto-scroll sidebar to keep active item in view
if (tickerRefs.current[currentSlide]) {
tickerRefs.current[currentSlide]?.scrollIntoView({
behavior: "smooth",
block: "nearest",
});
const activeTicker = tickerRefs.current[currentSlide];
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",
});
}
// If element is above the visible area
else if (activeTickerTop < sidebarTop) {
sidebar.scrollTo({
top: activeTickerTop - 24, // 24px padding
behavior: "smooth",
});
}
}
}, [currentSlide, content, onChange]);
@@ -57,11 +81,11 @@ const Carousel = ({
const handleTickerClick = useCallback(
(index: number) => {
if (index === currentSlide) return;
setDirection(index > currentSlide ? "right" : "left");
if (index === currentSlideRef.current) return;
setDirection(index > currentSlideRef.current ? "right" : "left");
setCurrentSlide(index);
},
[currentSlide, setDirection],
[setDirection],
);
if (!api) return null;
@@ -85,7 +109,7 @@ const Carousel = ({
ref={(el) => {
tickerRefs.current[index] = el;
}}
style={{ scrollMarginBlock: "24px" }}
className="carousel-ticker-wrapper"
>
<CarouselTickers
imageUrl={
@@ -105,7 +129,8 @@ const Carousel = ({
? `${item.ProductionYear ?? ""} - ${new Date(item.EndDate).getFullYear().toString()}`
: (item.ProductionYear?.toString() ?? "")
}
onClick={() => handleTickerClick(index)}
onTickerClick={handleTickerClick}
index={index}
/>
</div>
))}
+37 -29
View File
@@ -5,37 +5,45 @@ type CarouselTickersProps = {
imageUrl?: string;
itemName: string;
itemYear: string;
onClick: () => void;
onTickerClick: (index: number) => void;
index: number;
isActive: boolean;
};
const CarouselTickers = ({
imageUrl,
itemName,
itemYear,
onClick,
isActive,
}: CarouselTickersProps) => {
return (
<div
className={`carousel-ticker${isActive ? " active" : ""}`}
onClick={onClick}
>
<img
src={imageUrl}
alt={itemName}
className="carousel-ticker-image"
// style={{ width: "5em", height: "100%", objectFit: "cover" }}
/>
<div>
<Typography variant="subtitle1" className="carousel-ticker-title">
{itemName}
</Typography>
<Typography variant="caption" className="carousel-ticker-year">
{itemYear}
</Typography>
const CarouselTickers = React.memo(
({
imageUrl,
itemName,
itemYear,
onTickerClick,
index,
isActive,
}: CarouselTickersProps) => {
const handleClick = React.useCallback(() => {
onTickerClick(index);
}, [index, onTickerClick]);
return (
<div
className={`carousel-ticker${isActive ? " active" : ""}`}
onClick={handleClick}
>
<img
src={imageUrl}
alt={itemName}
className="carousel-ticker-image"
// style={{ width: "5em", height: "100%", objectFit: "cover" }}
/>
<div>
<Typography variant="subtitle1" className="carousel-ticker-title">
{itemName}
</Typography>
<Typography variant="caption" className="carousel-ticker-year">
{itemYear}
</Typography>
</div>
</div>
</div>
);
};
);
},
);
export default CarouselTickers;
+13 -13
View File
@@ -201,10 +201,10 @@ export interface FileRoutesByFullPath {
'/setup/server/add': typeof SetupServerAddRoute
'/setup/server/error': typeof SetupServerErrorRoute
'/setup/server/list': typeof SetupServerListRoute
'/favorite': typeof ApiFavoriteIndexRoute
'/home': typeof ApiHomeIndexRoute
'/player': typeof ApiPlayerIndexRoute
'/search': typeof ApiSearchIndexRoute
'/favorite/': typeof ApiFavoriteIndexRoute
'/home/': typeof ApiHomeIndexRoute
'/player/': typeof ApiPlayerIndexRoute
'/search/': typeof ApiSearchIndexRoute
'/login/$userId/$userName': typeof ApiLoginUserIdUserNameRoute
}
export interface FileRoutesByTo {
@@ -292,10 +292,10 @@ export interface FileRouteTypes {
| '/setup/server/add'
| '/setup/server/error'
| '/setup/server/list'
| '/favorite'
| '/home'
| '/player'
| '/search'
| '/favorite/'
| '/home/'
| '/player/'
| '/search/'
| '/login/$userId/$userName'
fileRoutesByTo: FileRoutesByTo
to:
@@ -372,7 +372,7 @@ declare module '@tanstack/react-router' {
'/_api': {
id: '/_api'
path: ''
fullPath: ''
fullPath: '/'
preLoaderRoute: typeof ApiRouteImport
parentRoute: typeof rootRouteImport
}
@@ -407,28 +407,28 @@ declare module '@tanstack/react-router' {
'/_api/search/': {
id: '/_api/search/'
path: '/search'
fullPath: '/search'
fullPath: '/search/'
preLoaderRoute: typeof ApiSearchIndexRouteImport
parentRoute: typeof ApiRoute
}
'/_api/player/': {
id: '/_api/player/'
path: '/player'
fullPath: '/player'
fullPath: '/player/'
preLoaderRoute: typeof ApiPlayerIndexRouteImport
parentRoute: typeof ApiRoute
}
'/_api/home/': {
id: '/_api/home/'
path: '/home'
fullPath: '/home'
fullPath: '/home/'
preLoaderRoute: typeof ApiHomeIndexRouteImport
parentRoute: typeof ApiRoute
}
'/_api/favorite/': {
id: '/_api/favorite/'
path: '/favorite'
fullPath: '/favorite'
fullPath: '/favorite/'
preLoaderRoute: typeof ApiFavoriteIndexRouteImport
parentRoute: typeof ApiRoute
}