fix: home page carousel causing scroll on item change and fix other performance issues
This commit is contained in:
5 files changed
+119
-93
No files matched your search
@@ -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,39 +160,35 @@ const CardContent = ({
|
|||||||
)}
|
)}
|
||||||
{inView && !disableOverlay && (
|
{inView && !disableOverlay && (
|
||||||
<div className="card-overlay">
|
<div className="card-overlay">
|
||||||
{isHovered && (
|
<PlayButton
|
||||||
<>
|
item={item}
|
||||||
<PlayButton
|
userId={userId}
|
||||||
item={item}
|
itemType={item.Type ?? "Movie"}
|
||||||
userId={userId}
|
className="card-play-button"
|
||||||
itemType={item.Type ?? "Movie"}
|
iconOnly
|
||||||
className="card-play-button"
|
audio={
|
||||||
iconOnly
|
item.Type === BaseItemKind.MusicAlbum ||
|
||||||
audio={
|
item.Type === BaseItemKind.Audio ||
|
||||||
item.Type === BaseItemKind.MusicAlbum ||
|
item.Type === BaseItemKind.AudioBook ||
|
||||||
item.Type === BaseItemKind.Audio ||
|
item.Type === BaseItemKind.Playlist
|
||||||
item.Type === BaseItemKind.AudioBook ||
|
}
|
||||||
item.Type === BaseItemKind.Playlist
|
playlistItem={item.Type === BaseItemKind.Playlist}
|
||||||
}
|
playlistItemId={item.Id}
|
||||||
playlistItem={item.Type === BaseItemKind.Playlist}
|
/>
|
||||||
playlistItemId={item.Id}
|
<LikeButton
|
||||||
/>
|
itemId={item.Id}
|
||||||
<LikeButton
|
itemName={item.Name ?? ""}
|
||||||
itemId={item.Id}
|
isFavorite={item.UserData?.IsFavorite}
|
||||||
itemName={item.Name ?? ""}
|
queryKey={queryKey}
|
||||||
isFavorite={item.UserData?.IsFavorite}
|
userId={userId}
|
||||||
queryKey={queryKey}
|
/>
|
||||||
userId={userId}
|
<MarkPlayedButton
|
||||||
/>
|
itemId={item.Id}
|
||||||
<MarkPlayedButton
|
itemName={item.Name ?? ""}
|
||||||
itemId={item.Id}
|
isPlayed={item.UserData?.Played}
|
||||||
itemName={item.Name ?? ""}
|
queryKey={queryKey}
|
||||||
isPlayed={item.UserData?.Played}
|
userId={userId}
|
||||||
queryKey={queryKey}
|
/>
|
||||||
userId={userId}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{(item.UserData?.PlaybackPositionTicks ?? -1) > 0 && (
|
{(item.UserData?.PlaybackPositionTicks ?? -1) > 0 && (
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -26,18 +26,42 @@ 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;
|
||||||
behavior: "smooth",
|
|
||||||
block: "nearest",
|
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]);
|
}, [currentSlide, content, onChange]);
|
||||||
|
|
||||||
@@ -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>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -5,37 +5,45 @@ 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,
|
({
|
||||||
itemName,
|
imageUrl,
|
||||||
itemYear,
|
itemName,
|
||||||
onClick,
|
itemYear,
|
||||||
isActive,
|
onTickerClick,
|
||||||
}: CarouselTickersProps) => {
|
index,
|
||||||
return (
|
isActive,
|
||||||
<div
|
}: CarouselTickersProps) => {
|
||||||
className={`carousel-ticker${isActive ? " active" : ""}`}
|
const handleClick = React.useCallback(() => {
|
||||||
onClick={onClick}
|
onTickerClick(index);
|
||||||
>
|
}, [index, onTickerClick]);
|
||||||
<img
|
|
||||||
src={imageUrl}
|
return (
|
||||||
alt={itemName}
|
<div
|
||||||
className="carousel-ticker-image"
|
className={`carousel-ticker${isActive ? " active" : ""}`}
|
||||||
// style={{ width: "5em", height: "100%", objectFit: "cover" }}
|
onClick={handleClick}
|
||||||
/>
|
>
|
||||||
<div>
|
<img
|
||||||
<Typography variant="subtitle1" className="carousel-ticker-title">
|
src={imageUrl}
|
||||||
{itemName}
|
alt={itemName}
|
||||||
</Typography>
|
className="carousel-ticker-image"
|
||||||
<Typography variant="caption" className="carousel-ticker-year">
|
// style={{ width: "5em", height: "100%", objectFit: "cover" }}
|
||||||
{itemYear}
|
/>
|
||||||
</Typography>
|
<div>
|
||||||
|
<Typography variant="subtitle1" className="carousel-ticker-title">
|
||||||
|
{itemName}
|
||||||
|
</Typography>
|
||||||
|
<Typography variant="caption" className="carousel-ticker-year">
|
||||||
|
{itemYear}
|
||||||
|
</Typography>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
);
|
||||||
);
|
},
|
||||||
};
|
);
|
||||||
export default CarouselTickers;
|
export default CarouselTickers;
|
||||||
+13
-13
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user