diff --git a/src/pages/discover/components/LazyMediaCarousel.tsx b/src/pages/discover/components/LazyMediaCarousel.tsx index d41c8a06..023eaf28 100644 --- a/src/pages/discover/components/LazyMediaCarousel.tsx +++ b/src/pages/discover/components/LazyMediaCarousel.tsx @@ -52,6 +52,7 @@ export function LazyMediaCarousel({ }, [media, preloadedMedia]); const categoryName = title || category?.name || genre?.name || ""; + const categorySlug = categoryName.toLowerCase().replace(/[^a-z0-9]+/g, "-"); // Test intersection observer // useEffect(() => { @@ -73,12 +74,14 @@ export function LazyMediaCarousel({ /> ) : (
-

- {categoryName} {mediaType === "tv" ? "Shows" : "Movies"} -

-
-
- {isLoading ? "Loading..." : ""} +
+

+ {categoryName} {mediaType === "tv" ? "Shows" : "Movies"} +

+
+
+ {isLoading ? "Loading..." : ""} +
diff --git a/src/pages/discover/components/MediaCarousel.tsx b/src/pages/discover/components/MediaCarousel.tsx index 2e8b3374..ff5e9c32 100644 --- a/src/pages/discover/components/MediaCarousel.tsx +++ b/src/pages/discover/components/MediaCarousel.tsx @@ -31,7 +31,7 @@ export function MediaCarousel({ isMobile, carouselRefs, }: MediaCarouselProps) { - const categorySlug = `${category.toLowerCase().replace(/ /g, "-")}`; + const categorySlug = category.toLowerCase().replace(/[^a-z0-9]+/g, "-"); const browser = !!window.chrome; let isScrolling = false; diff --git a/src/pages/discover/discoverContent.tsx b/src/pages/discover/discoverContent.tsx index 194c607c..71e51e16 100644 --- a/src/pages/discover/discoverContent.tsx +++ b/src/pages/discover/discoverContent.tsx @@ -287,6 +287,18 @@ export function DiscoverContent() { } }; + const handleCategoryClick = (id: string, name: string) => { + const categorySlug = name.toLowerCase().replace(/[^a-z0-9]+/g, "-"); + const element = document.getElementById(`carousel-${categorySlug}`); + + if (element) { + element.scrollIntoView({ + behavior: "smooth", + block: "center", + }); + } + }; + // Render Editor Picks content const renderEditorPicksContent = () => { return ( @@ -444,18 +456,7 @@ export function DiscoverContent() { ? [...categories, ...genres] : [...tvCategories, ...tvGenres] } - onCategoryClick={(id, name) => { - const element = document.getElementById( - `carousel-${name.toLowerCase().replace(/ /g, "-")}`, - ); - if (element) { - element.scrollIntoView({ - behavior: "smooth", - block: "center", - inline: "center", - }); - } - }} + onCategoryClick={handleCategoryClick} categoryType="movies" isMobile={isMobile} showAlwaysScroll