diff --git a/app/(site)/components/Trending/index.tsx b/app/(site)/components/Trending/index.tsx
index 4965827..802f680 100644
--- a/app/(site)/components/Trending/index.tsx
+++ b/app/(site)/components/Trending/index.tsx
@@ -1,22 +1,43 @@
'use client';
-import { FC } from 'react';
+import { FC, useState } from 'react';
import Marquee from '@/components/Marquee';
-import { Badge } from '@/components/ui/badge';
+import Nav from '@/components/ui/nav';
import useTrending from './useTrending';
-const Trending: FC<{ label: string; type: 'trending' | 'streaming' | 'theater' | 'rent' }> = ({ label, type }) => {
+const tabs = [
+ {
+ title: 'Trending',
+ type: 'trending'
+ },
+ {
+ title: 'Streaming',
+ type: 'streaming'
+ },
+ {
+ title: 'In theaters',
+ type: 'theater'
+ }
+];
+
+const Trending: FC = () => {
+ const [active, setActive] = useState(tabs[0]);
const isMobile = typeof window === 'undefined' ? true : matchMedia('(max-width: 600px)').matches;
- const { data: movies, isFetched } = useTrending({ type, enabled: !isMobile });
+
+ const { data: trending, isFetched } = useTrending({ type: 'trending', enabled: !isMobile });
+ const { data: streaming } = useTrending({ type: 'streaming', enabled: !isMobile });
+ const { data: theater } = useTrending({ type: 'theater', enabled: !isMobile });
+
+ const movies = { trending, streaming, theater }[active.type] || [];
return (
isFetched && (
- <>
- {label}
-
- >
+
+
)
);
};
diff --git a/app/(site)/container.tsx b/app/(site)/container.tsx
index c13edbf..7165cde 100644
--- a/app/(site)/container.tsx
+++ b/app/(site)/container.tsx
@@ -26,18 +26,9 @@ export default function Container() {
-
);
diff --git a/components/Header/components/Navigation/index.tsx b/components/Header/components/Navigation/index.tsx
index 5ef690c..f40d65b 100644
--- a/components/Header/components/Navigation/index.tsx
+++ b/components/Header/components/Navigation/index.tsx
@@ -8,7 +8,7 @@ import { usePathname } from 'next/navigation';
import { Button } from '@/components/ui/button';
import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
-import { cn } from '@/lib/utils';
+import Nav from '@/components/ui/nav';
const paths = [
{ path: '/', title: 'Random' },
@@ -47,39 +47,16 @@ export function MobileNavigation() {
}
export function DesktopNavigation() {
- const [position, setPosition] = useState({ left: 0, width: 0, opacity: 0 });
- const currentRef = useRef(null);
const currentPath = usePathname();
-
- useEffect(() => {
- const link = currentRef.current;
-
- setPosition({ width: link?.clientWidth || 0, left: link?.offsetLeft || 0, opacity: link ? 1 : 0 });
- }, [currentPath]);
+ const active = paths.find(({ path }) => path === currentPath);
return (
-
- {paths.map(({ path, title }) => (
- -
-
-
{title}
-
-
- ))}
-
-
+
);
}
-
-const Cursor: FC<{ options: { left: number; width: number; opacity: number } }> = ({ options }) => {
- return (
-
- );
-};
diff --git a/components/Marquee/index.tsx b/components/Marquee/index.tsx
index 880445f..3d09b67 100644
--- a/components/Marquee/index.tsx
+++ b/components/Marquee/index.tsx
@@ -7,16 +7,14 @@ interface Props {
movies: Movie[];
}
-const Marquee: FC = ({ movies }) => {
- return (
-
- {movies.map((movie) => (
- -
- showPreviewModal({ movie })} />
-
- ))}
-
- );
-};
+const Marquee: FC = ({ movies }) => (
+
+ {movies.map((movie) => (
+ -
+ showPreviewModal({ movie })} />
+
+ ))}
+
+);
export default Marquee;
diff --git a/components/ui/nav.tsx b/components/ui/nav.tsx
new file mode 100644
index 0000000..bf31f28
--- /dev/null
+++ b/components/ui/nav.tsx
@@ -0,0 +1,60 @@
+import { FC, ReactNode, useLayoutEffect, useRef, useState } from 'react';
+
+import { cn } from '@/lib/utils';
+
+type Tab = { title: string };
+
+type CursorProps = { left: number; width: number; opacity: number };
+
+const Cursor: FC = ({ width, left, opacity }) => (
+
+);
+
+export type NavProps = {
+ tabs: T[];
+ className?: string;
+ active: T;
+ onChange?: (tab: T) => void;
+ children?: (tab: T) => ReactNode;
+};
+
+function Nav({ tabs, active, className, children, onChange }: NavProps) {
+ const [cursor, setCursor] = useState({ left: 0, width: 0, opacity: 0 });
+ const currentRef = useRef(null);
+
+ useLayoutEffect(() => {
+ const link = currentRef.current;
+
+ setCursor({ width: link?.clientWidth || 0, left: link?.offsetLeft || 0, opacity: link ? 1 : 0 });
+ }, [active?.title]);
+
+ return (
+
+ {tabs.map((tab) => {
+ const { title } = tab;
+
+ const isActive = title === active.title;
+
+ return (
+ - onChange?.(tab)}
+ className={cn(
+ 'mix-blend-difference text-white z-10 px-2.5 py-0.5 font-normal cursor-default',
+ !isActive && 'cursor-pointer'
+ )}
+ >
+ {children?.(tab) ||
{title}
}
+
+ );
+ })}
+
+
+ );
+}
+
+export default Nav;