refactor: clean code and remove unnecessary dependencies
This commit is contained in:
1 parent
eceae6fec7
commit
ebf599eed6
92 files changed
+1152
-2842
No files matched your search
@@ -0,0 +1,6 @@
|
||||
export const paths = [
|
||||
{ path: '/', title: 'Random' },
|
||||
{ path: '/popular', title: 'Popular' },
|
||||
{ path: '/top', title: 'Top rated' },
|
||||
{ path: '/favorites', title: 'Favorites' }
|
||||
];
|
||||
@@ -1,6 +1,5 @@
|
||||
'use client';
|
||||
|
||||
import { FC, useEffect, useRef, useState } from 'react';
|
||||
import { DropdownMenuItem } from '@radix-ui/react-dropdown-menu';
|
||||
import { Menu } from 'lucide-react';
|
||||
import Link from 'next/link';
|
||||
@@ -10,14 +9,9 @@ import { Button } from '@/components/ui/button';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||
import Nav from '@/components/ui/nav';
|
||||
|
||||
const paths = [
|
||||
{ path: '/', title: 'Random' },
|
||||
{ path: '/popular', title: 'Popular' },
|
||||
{ path: '/top', title: 'Top rated' },
|
||||
{ path: '/favorites', title: 'Favorites' }
|
||||
];
|
||||
import { paths } from './constants';
|
||||
|
||||
export function MobileNavigation() {
|
||||
export const MobileNavigation = () => {
|
||||
const currentPath = usePathname();
|
||||
|
||||
return (
|
||||
@@ -44,9 +38,9 @@ export function MobileNavigation() {
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export function DesktopNavigation() {
|
||||
export const DesktopNavigation = () => {
|
||||
const currentPath = usePathname();
|
||||
const active = paths.find(({ path }) => path === currentPath);
|
||||
|
||||
@@ -59,4 +53,4 @@ export function DesktopNavigation() {
|
||||
)}
|
||||
</Nav>
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -1,16 +0,0 @@
|
||||
import client from '@/network';
|
||||
|
||||
const API = {
|
||||
search: {
|
||||
byTitle({ query, page }: { query: string; page: number }): Promise<MovieDBResponse> {
|
||||
return client.get('/search', {
|
||||
params: {
|
||||
query,
|
||||
page
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default API;
|
||||
@@ -4,54 +4,40 @@ import { ChangeEvent, MutableRefObject, useRef, useState } from 'react';
|
||||
import { create } from 'react-modal-promise';
|
||||
import { Search as SearchIcon, XCircle } from 'lucide-react';
|
||||
|
||||
import List from '@/components/Movie/List';
|
||||
import List from '@/components/List';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Modal } from '@/components/ui/dialog';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
import useDistinctUntilChanged from '@/hooks/useDistinctUntilChanged';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
import useSearch from './useSearch';
|
||||
|
||||
export const showSearchModal = create(({ onResolve }) => {
|
||||
const [title, setTitle] = useState('');
|
||||
const [query, setQuery] = useState('');
|
||||
const scrollRef = useRef<HTMLDivElement>(null) as MutableRefObject<HTMLDivElement>;
|
||||
const timeout = useRef<NodeJS.Timeout>();
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
const {
|
||||
data: movies,
|
||||
hasNextPage: hasNextMoviesPage,
|
||||
fetchNextPage: fetchNextMoviesPage
|
||||
} = useSearch({ query, type: 'movie' });
|
||||
const query = useDistinctUntilChanged(title);
|
||||
|
||||
const {
|
||||
data: series,
|
||||
hasNextPage: hasNextSeriesPage,
|
||||
fetchNextPage: fetchNextSeriesPage
|
||||
} = useSearch({ query, type: 'tv' });
|
||||
const movies = useSearch({ query, type: 'movie' });
|
||||
const series = useSearch({ query, type: 'tv' });
|
||||
|
||||
const handleChangeTitle = ({ target: { value } }: ChangeEvent<HTMLInputElement>) => {
|
||||
setTitle(value);
|
||||
|
||||
clearTimeout(timeout.current);
|
||||
timeout.current = setTimeout(() => setQuery(value.trim()), 500);
|
||||
};
|
||||
const handleChangeTitle = ({ target: { value } }: ChangeEvent<HTMLInputElement>) => setTitle(value);
|
||||
|
||||
const handleReset = () => {
|
||||
setQuery('');
|
||||
setTitle('');
|
||||
inputRef.current?.focus();
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
handleReset();
|
||||
return onResolve();
|
||||
};
|
||||
const tabs = [
|
||||
{ title: 'Movies', data: movies, type: 'movie' as const },
|
||||
{ title: 'Series', data: series, type: 'tv' as const }
|
||||
].filter(({ data: { shows } }) => shows.length);
|
||||
|
||||
return (
|
||||
<Modal className='block p-0 max-w-[932px]' onClose={handleClose} scrollRef={scrollRef}>
|
||||
<Modal className='block p-0 max-w-[932px]' onClose={onResolve} scrollRef={scrollRef}>
|
||||
<div className='relative p-2'>
|
||||
<Input
|
||||
autoFocus
|
||||
@@ -66,53 +52,51 @@ export const showSearchModal = create(({ onResolve }) => {
|
||||
type='button'
|
||||
size='icon'
|
||||
onClick={handleReset}
|
||||
disabled={!query.length}
|
||||
disabled={!title.length}
|
||||
className='absolute right-2 top-2'
|
||||
>
|
||||
<XCircle />
|
||||
</Button>
|
||||
</div>
|
||||
<Tabs
|
||||
defaultValue='movies'
|
||||
className={cn('w-full px-2', !(movies?.pages.length && series?.pages?.length) && 'hidden')}
|
||||
>
|
||||
<TabsList className='grid w-full grid-cols-2'>
|
||||
<TabsTrigger value='movies'>Movies</TabsTrigger>
|
||||
<TabsTrigger value='series'>Series</TabsTrigger>
|
||||
</TabsList>
|
||||
<TabsContent value='movies'>
|
||||
{Boolean(movies?.pages.length && movies?.pages?.[0]?.results?.length) && (
|
||||
<List
|
||||
customScrollParent={scrollRef.current}
|
||||
pages={movies!.pages as unknown as MovieDBResponse[]}
|
||||
fetchNextPage={fetchNextMoviesPage}
|
||||
hasNextPage={hasNextMoviesPage}
|
||||
onPreviewClose={handleClose}
|
||||
type='movie'
|
||||
/>
|
||||
)}
|
||||
</TabsContent>
|
||||
<TabsContent value='series'>
|
||||
{Boolean(series?.pages.length && series?.pages?.[0]?.results?.length) && (
|
||||
<List
|
||||
customScrollParent={scrollRef.current}
|
||||
pages={series!.pages as unknown as MovieDBResponse[]}
|
||||
fetchNextPage={fetchNextSeriesPage}
|
||||
hasNextPage={hasNextSeriesPage}
|
||||
onPreviewClose={handleClose}
|
||||
type='tv'
|
||||
/>
|
||||
)}
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
{tabs.length > 1 ? (
|
||||
<Tabs defaultValue='movie' className={cn('w-full px-2')}>
|
||||
<TabsList className='grid w-full grid-cols-2'>
|
||||
{tabs.map(({ type, title }) => (
|
||||
<TabsTrigger key={type} value={type}>
|
||||
{title}
|
||||
</TabsTrigger>
|
||||
))}
|
||||
</TabsList>
|
||||
{tabs.map(({ data: { shows, fetchNextPage }, type }) => (
|
||||
<TabsContent value={type} key={type}>
|
||||
<List
|
||||
shows={shows}
|
||||
customScrollParent={scrollRef.current}
|
||||
fetchNextPage={fetchNextPage}
|
||||
onPreviewClose={onResolve}
|
||||
/>
|
||||
</TabsContent>
|
||||
))}
|
||||
</Tabs>
|
||||
) : (
|
||||
tabs.map(({ data: { shows, fetchNextPage }, type }) => (
|
||||
<List
|
||||
key={type}
|
||||
shows={shows}
|
||||
customScrollParent={scrollRef.current}
|
||||
fetchNextPage={fetchNextPage}
|
||||
onPreviewClose={onResolve}
|
||||
/>
|
||||
))
|
||||
)}
|
||||
</Modal>
|
||||
);
|
||||
});
|
||||
|
||||
export default function ToggleSearch() {
|
||||
return (
|
||||
<Button variant='ghost' size='icon' onClick={() => showSearchModal()}>
|
||||
<SearchIcon size={19} />
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
const ToggleSearch = () => (
|
||||
<Button variant='ghost' size='icon' onClick={() => showSearchModal()}>
|
||||
<SearchIcon size={19} />
|
||||
</Button>
|
||||
);
|
||||
|
||||
export default ToggleSearch;
|
||||
@@ -1,20 +1,11 @@
|
||||
import { useInfiniteQuery } from '@tanstack/react-query';
|
||||
import { search } from '@/api';
|
||||
import useInfiniteList from '@/hooks/useInfiniteList';
|
||||
|
||||
import { search } from '@/lib/api';
|
||||
|
||||
const useSearch = ({ query, type }: { query: string; type: ShowType }) => {
|
||||
return useInfiniteQuery({
|
||||
const useSearch = ({ query, type }: { query: string; type: Show['type'] }) =>
|
||||
useInfiniteList({
|
||||
queryKey: ['search', query, type],
|
||||
queryFn: ({ pageParam: page }) => search({ query, page, type }),
|
||||
enabled: Boolean(query),
|
||||
getNextPageParam(lastPage) {
|
||||
const { page, total_pages } = lastPage as { page: number; total_pages: number };
|
||||
if (page === total_pages) return undefined;
|
||||
|
||||
return page + 1;
|
||||
},
|
||||
initialPageParam: 1
|
||||
queryFn: ({ page }) => search({ query, page, type }),
|
||||
enabled: Boolean(query)
|
||||
});
|
||||
};
|
||||
|
||||
export default useSearch;
|
||||
@@ -3,13 +3,16 @@
|
||||
import { Moon, Sun } from 'lucide-react';
|
||||
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useTheme } from '@/hooks/useTheme';
|
||||
import useTheme from '@/hooks/useTheme';
|
||||
|
||||
export default function ThemeToggle() {
|
||||
const ThemeToggle = () => {
|
||||
const [theme, setTheme] = useTheme();
|
||||
|
||||
return (
|
||||
<Button variant='ghost' size='icon' onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}>
|
||||
{theme === 'light' ? <Moon size={19} /> : <Sun size={19} />}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default ThemeToggle;
|
||||
@@ -9,14 +9,13 @@ import ToggleTheme from './components/ThemeToggle';
|
||||
|
||||
const Header: FC = () => (
|
||||
<header className='flex justify-center bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60 py-2'>
|
||||
<div className='max-w-[1240px] w-full px-2'>
|
||||
<div className='container'>
|
||||
<div className='flex items-center justify-between gap-2 xs:flex-nowrap'>
|
||||
<Link href='/' shallow legacyBehavior>
|
||||
<Link shallow href='/'>
|
||||
<Badge className='whitespace-nowrap cursor-pointer font-normal'>Movie advisor</Badge>
|
||||
</Link>
|
||||
<DesktopNavigation />
|
||||
<div className='flex items-center gap-2'>
|
||||
<div id='actions' className='empty:hidden' />
|
||||
<ToggleTheme />
|
||||
<ToggleSearch />
|
||||
<MobileNavigation />
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import { FC } from 'react';
|
||||
import { VirtuosoGrid, VirtuosoGridProps } from 'react-virtuoso';
|
||||
|
||||
import { showPreviewModal } from '@/components/Preview';
|
||||
import Card from '@/components/Show';
|
||||
|
||||
interface Props {
|
||||
shows: Show[];
|
||||
customScrollParent?: HTMLElement;
|
||||
fetchNextPage?: () => void;
|
||||
onPreviewClose?: () => void;
|
||||
}
|
||||
|
||||
const components: VirtuosoGridProps<Movie, { shows: Show[]; onClick: (show: Show) => void }>['components'] = {
|
||||
Item: ({ context, 'data-index': index }) => {
|
||||
const { shows, onClick } = context!;
|
||||
const show = shows?.[index];
|
||||
|
||||
if (!show) return null;
|
||||
|
||||
return <Card show={show} onClick={() => onClick?.(show)} />;
|
||||
}
|
||||
};
|
||||
|
||||
const List: FC<Props> = ({ shows, fetchNextPage, onPreviewClose, customScrollParent }) => {
|
||||
if (!shows.length) return null;
|
||||
|
||||
const context = {
|
||||
shows,
|
||||
onClick: (show: Show) => showPreviewModal({ show, onClose: onPreviewClose })
|
||||
};
|
||||
|
||||
const handleFetchMore = () => fetchNextPage?.();
|
||||
|
||||
return (
|
||||
<>
|
||||
<VirtuosoGrid
|
||||
useWindowScroll
|
||||
initialItemCount={20}
|
||||
overscan={10}
|
||||
data={shows}
|
||||
context={context}
|
||||
components={components}
|
||||
listClassName='flex gap-2 flex-wrap justify-center grow empty:hidden opacity-0 animate-fade-in-slide-in'
|
||||
customScrollParent={customScrollParent}
|
||||
endReached={handleFetchMore}
|
||||
/>
|
||||
<div className='h-2 w-full' />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default List;
|
||||
@@ -1,20 +0,0 @@
|
||||
import { FC } from 'react';
|
||||
|
||||
import Card from '../Movie/Card';
|
||||
import { showPreviewModal } from '../Movie/Preview';
|
||||
|
||||
interface Props {
|
||||
movies: Movie[];
|
||||
}
|
||||
|
||||
const Marquee: FC<Props> = ({ movies }) => (
|
||||
<ul className='flex overflow-auto gap-2 rounded-lg snap-mandatory snap-x no-scrollbar opacity-0 animate-fade-aside-slide-in'>
|
||||
{movies.map((movie) => (
|
||||
<li key={movie.id} className='snap-start'>
|
||||
<Card className='!h-[350px] !w-[230px] text-sm' movie={movie} onClick={() => showPreviewModal({ movie })} />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
|
||||
export default Marquee;
|
||||
@@ -1,66 +0,0 @@
|
||||
import { FC, useMemo } from 'react';
|
||||
import { VirtuosoGrid, VirtuosoGridProps } from 'react-virtuoso';
|
||||
|
||||
import Card from '@/components/Movie/Card';
|
||||
import { showPreviewModal } from '@/components/Movie/Preview';
|
||||
import filterUnknownMovies from '@/lib/filterUnknownMovies';
|
||||
|
||||
interface Props {
|
||||
type?: ShowType;
|
||||
pages: Array<MovieDBResponse>;
|
||||
hasNextPage?: boolean;
|
||||
customScrollParent?: HTMLElement;
|
||||
fetchNextPage?: () => void;
|
||||
onPreviewClose?: () => void;
|
||||
}
|
||||
|
||||
const components: VirtuosoGridProps<Movie, { shows: Movie[]; onClick: (movie: Movie) => void }>['components'] = {
|
||||
Item: ({ context, 'data-index': index }) => {
|
||||
const { shows, onClick } = context || {};
|
||||
const movie = shows?.[index];
|
||||
|
||||
return <Card movie={movie} onClick={() => onClick?.(movie!)} />;
|
||||
}
|
||||
};
|
||||
|
||||
const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage, onPreviewClose, type = 'movie', customScrollParent }) => {
|
||||
const shows = useMemo(
|
||||
() =>
|
||||
pages?.reduce((shows, page) => {
|
||||
shows.push(...filterUnknownMovies(page.results));
|
||||
return shows;
|
||||
}, [] as Movie[]) || [],
|
||||
[pages]
|
||||
);
|
||||
|
||||
if (!shows.length) return null;
|
||||
|
||||
const context = {
|
||||
shows,
|
||||
onClick: (movie: Movie) => showPreviewModal({ movie, onClose: onPreviewClose, type })
|
||||
};
|
||||
|
||||
const handleFetchMore = () => {
|
||||
if (!hasNextPage) return;
|
||||
fetchNextPage?.();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<VirtuosoGrid
|
||||
useWindowScroll
|
||||
initialItemCount={20}
|
||||
overscan={10}
|
||||
data={shows}
|
||||
context={context}
|
||||
components={components}
|
||||
listClassName='flex gap-2 flex-wrap justify-center grow empty:hidden opacity-0 animate-fade-in-slide-in'
|
||||
customScrollParent={customScrollParent}
|
||||
endReached={handleFetchMore}
|
||||
/>
|
||||
<div className='h-2 w-full' />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default List;
|
||||
@@ -1,48 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import Link from 'next/link';
|
||||
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
import { showTorrentsModal } from '../../components/Torrents';
|
||||
import ToggleTrailer from '../../components/Trailer';
|
||||
|
||||
interface Props {
|
||||
movie: Movie;
|
||||
onClose?: () => void;
|
||||
type?: ShowType;
|
||||
}
|
||||
|
||||
export default function Actions({ onClose, movie, type }: Props) {
|
||||
return (
|
||||
<>
|
||||
<ToggleTrailer type={type} movieId={movie?.id}>
|
||||
{({ onPlay, disabled }) => (
|
||||
<Button className='h-8 flex-grow w-[50%]' onClick={onPlay} disabled={disabled}>
|
||||
Trailer
|
||||
</Button>
|
||||
)}
|
||||
</ToggleTrailer>
|
||||
<Button
|
||||
className='h-8 flex-grow w-[50%]'
|
||||
onClick={() =>
|
||||
showTorrentsModal({
|
||||
id: movie.id,
|
||||
type: type as ShowType,
|
||||
title: movie?.name || movie.title,
|
||||
year: new Date(movie.first_air_date || movie.release_date).getFullYear()
|
||||
})
|
||||
}
|
||||
>
|
||||
Torrents
|
||||
</Button>
|
||||
<Link
|
||||
className='flex w-[50%]'
|
||||
href={`/similar?movieId=${movie.id}&title=${encodeURIComponent(movie?.name || movie.title)}&type=${type}`}
|
||||
onClick={onClose}
|
||||
>
|
||||
<Button className='h-8 flex-grow'>Similar</Button>
|
||||
</Link>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { FC, ReactNode } from 'react';
|
||||
import { create, InstanceProps } from 'react-modal-promise';
|
||||
import { Play } from 'lucide-react';
|
||||
|
||||
import useTrailer from '@/app/(site)/useTrailer';
|
||||
import { Modal } from '@/components/ui/dialog';
|
||||
|
||||
interface Props {
|
||||
movieId?: number;
|
||||
children?: ({ onPlay, disabled }: { onPlay: () => void; disabled: boolean }) => ReactNode;
|
||||
type?: ShowType;
|
||||
}
|
||||
|
||||
const Trailer: FC<{ trailerKey?: string } & InstanceProps<void>> = ({ trailerKey, onResolve }) => {
|
||||
if (!trailerKey) return;
|
||||
|
||||
return (
|
||||
<Modal className='block p-0 max-w-[930px] border-none bg-black' style={{ aspectRatio: '16/9' }} onClose={onResolve}>
|
||||
<iframe
|
||||
allow='autoplay'
|
||||
className='border-none rounded-lg'
|
||||
width='100%'
|
||||
height='100%'
|
||||
src={`//www.youtube.com/embed/${trailerKey}?autoplay=1`}
|
||||
allowFullScreen
|
||||
/>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export const showTrailerModal = create(Trailer);
|
||||
|
||||
export default function ToggleTrailer({ movieId, type = 'movie', children }: Props) {
|
||||
const { data: trailer, isFetched } = useTrailer({ movieId, type });
|
||||
|
||||
return children
|
||||
? children({ onPlay: () => showTrailerModal({ trailerKey: trailer?.key }), disabled: isFetched && !trailer })
|
||||
: trailer && (
|
||||
<div
|
||||
onClick={() => showTrailerModal({ trailerKey: trailer?.key })}
|
||||
title='Play trailer'
|
||||
className='absolute w-full h-full left-0 top-0 bg-black cursor-pointer overflow-hidden rounded-lg transition-opacity opacity-0 hover:opacity-70 flex items-center justify-center'
|
||||
>
|
||||
<Play size={100} className='fill-white' />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
const NoResults = () => (
|
||||
<div className='h-40 w-full flex items-center justify-center text-xl text-muted-foreground'>Nothing was found</div>
|
||||
);
|
||||
|
||||
export default NoResults;
|
||||
@@ -0,0 +1,46 @@
|
||||
'use client';
|
||||
|
||||
import Link from 'next/link';
|
||||
|
||||
import showTorrentsModal from '@/components/Show/components/Torrents';
|
||||
import ToggleTrailer from '@/components/Show/components/Trailer';
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
interface Props {
|
||||
show: Show;
|
||||
onClose?: () => void;
|
||||
}
|
||||
|
||||
const Actions = ({ onClose, show }: Props) => (
|
||||
<>
|
||||
<ToggleTrailer showType={show.type} showId={show.id}>
|
||||
{({ onPlay, disabled }) => (
|
||||
<Button className='h-8 flex-grow w-[50%]' onClick={onPlay} disabled={disabled}>
|
||||
Trailer
|
||||
</Button>
|
||||
)}
|
||||
</ToggleTrailer>
|
||||
<Button
|
||||
className='h-8 flex-grow w-[50%]'
|
||||
onClick={() =>
|
||||
showTorrentsModal({
|
||||
showId: show.id,
|
||||
showType: show.type,
|
||||
title: show.title,
|
||||
year: new Date(show.release).getFullYear()
|
||||
})
|
||||
}
|
||||
>
|
||||
Torrents
|
||||
</Button>
|
||||
<Link
|
||||
className='flex w-[50%]'
|
||||
href={`/similar?id=${show.id}&title=${encodeURIComponent(show.title)}&type=${show.type}`}
|
||||
onClick={onClose}
|
||||
>
|
||||
<Button className='h-8 flex-grow'>Similar</Button>
|
||||
</Link>
|
||||
</>
|
||||
);
|
||||
|
||||
export default Actions;
|
||||
@@ -3,52 +3,49 @@
|
||||
import { FC, ReactNode } from 'react';
|
||||
import { create, InstanceProps } from 'react-modal-promise';
|
||||
|
||||
import Credits from '@/components/Movie/components/Credits';
|
||||
import Card from '@/components/Show';
|
||||
import Credits from '@/components/Show/components/Credits';
|
||||
import { Modal } from '@/components/ui/dialog';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
import Card from '../Card';
|
||||
|
||||
import Actions from './components/Actions';
|
||||
|
||||
interface Props {
|
||||
movie?: Movie;
|
||||
show?: Show;
|
||||
className?: string;
|
||||
onClose?: () => void;
|
||||
children?: ReactNode;
|
||||
card?: ReactNode;
|
||||
type?: ShowType;
|
||||
}
|
||||
|
||||
const Preview: FC<Props> = ({ movie, className, onClose, children, card, type = 'movie' }) => {
|
||||
if (!movie) return null;
|
||||
const Preview: FC<Props> = ({ show, className, onClose, children, card }) => {
|
||||
if (!show) return null;
|
||||
|
||||
return (
|
||||
<div className={cn('flex flex-col md:flex-row gap-2 rounded-xl', { 'p-2': Boolean(onClose) }, className)}>
|
||||
{card || <Card className='mx-auto' movie={movie} />}
|
||||
{card || <Card className='mx-auto' show={show} />}
|
||||
<div className='flex flex-col grow'>
|
||||
{children && <div className='flex hover-none:hidden w-full max-sm:mb-0 mb-2 gap-2'>{children}</div>}
|
||||
<div className='flex w-full gap-2'>
|
||||
<Actions type={type} movie={movie} onClose={onClose} />
|
||||
<Actions show={show} onClose={onClose} />
|
||||
</div>
|
||||
<Separator className='my-2' />
|
||||
<p key={movie.id} className='leading-7 mb-3'>
|
||||
{movie.overview}
|
||||
<p key={show.id} className='leading-7 mb-3'>
|
||||
{show.overview}
|
||||
</p>
|
||||
<div className='mt-auto grid grid-cols-1 rounded-lg'>
|
||||
<Credits type={type} movieId={movie.id} onPersonClick={onClose} />
|
||||
<Credits showType={show.type} showId={show.id} onPersonClick={onClose} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const showPreviewModal = create(({ onResolve, onClose, movie, type = 'movie' }: Props & InstanceProps<void>) => (
|
||||
export const showPreviewModal = create(({ onResolve, onClose, show }: Props & InstanceProps<void>) => (
|
||||
<Modal className='block p-0' onClose={onResolve}>
|
||||
<Preview
|
||||
type={type}
|
||||
movie={movie}
|
||||
show={show}
|
||||
className='border-none'
|
||||
onClose={() => {
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
@@ -0,0 +1,99 @@
|
||||
'use client';
|
||||
|
||||
import { FC, forwardRef, useEffect, useLayoutEffect, useRef } from 'react';
|
||||
import { Virtuoso, VirtuosoHandle, VirtuosoProps } from 'react-virtuoso';
|
||||
|
||||
import Card from '@/components/Show';
|
||||
|
||||
const components: VirtuosoProps<Show, (index: number) => void>['components'] = {
|
||||
Item: ({ item, children, context: onIndexChange, ...props }) => {
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
const index = props['data-index'];
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const container = ref.current;
|
||||
|
||||
if (!container) return;
|
||||
|
||||
const observer = new IntersectionObserver(
|
||||
(entries) =>
|
||||
entries.forEach((entry) => {
|
||||
if (!entry.isIntersecting) return;
|
||||
|
||||
onIndexChange?.(index);
|
||||
}),
|
||||
{
|
||||
threshold: 0.7
|
||||
}
|
||||
);
|
||||
|
||||
observer.observe(container);
|
||||
|
||||
return () => observer.disconnect();
|
||||
}, [onIndexChange, index]);
|
||||
|
||||
return (
|
||||
<div {...props} ref={ref} className='snap-start'>
|
||||
<Card show={item} />
|
||||
</div>
|
||||
);
|
||||
},
|
||||
List: forwardRef(function List({ context, ...props }, ref) {
|
||||
return <div {...props} ref={ref} style={{ ...props.style, display: 'flex' }} className='gap-2' />;
|
||||
}),
|
||||
Scroller: forwardRef(function Scroller({ context, ...props }, ref) {
|
||||
return (
|
||||
<div {...props} ref={ref} className='overflow-hidden no-scrollbar snap-mandatory snap-x rounded-lg h-full' />
|
||||
);
|
||||
})
|
||||
};
|
||||
|
||||
interface Props {
|
||||
index: number;
|
||||
shows?: Show[];
|
||||
onIndexChange: (index: number) => void;
|
||||
onEndReached?: () => void;
|
||||
}
|
||||
|
||||
const Carousel: FC<Props> = ({ index, shows, onIndexChange, onEndReached }) => {
|
||||
const ref = useRef<VirtuosoHandle>(null);
|
||||
const initialIndex = useRef(index);
|
||||
|
||||
useEffect(() => {
|
||||
const scrollTo = ({ key }: globalThis.KeyboardEvent) => {
|
||||
if (key === 'ArrowLeft') {
|
||||
if (index <= 0) return;
|
||||
ref.current?.scrollIntoView({ index: index - 1, behavior: 'smooth' });
|
||||
}
|
||||
|
||||
if (key === 'ArrowRight') {
|
||||
if (index >= (shows?.length || 0) - 1) return;
|
||||
ref.current?.scrollIntoView({ index: index + 1, behavior: 'smooth' });
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener('keydown', scrollTo);
|
||||
|
||||
return () => {
|
||||
document.removeEventListener('keydown', scrollTo);
|
||||
};
|
||||
}, [index, shows?.length]);
|
||||
|
||||
return (
|
||||
<div className='card-aspect-ratio mx-auto'>
|
||||
<Virtuoso
|
||||
ref={ref}
|
||||
data={shows}
|
||||
context={onIndexChange}
|
||||
endReached={onEndReached}
|
||||
initialTopMostItemIndex={initialIndex.current}
|
||||
components={components}
|
||||
horizontalDirection
|
||||
skipAnimationFrameInResizeObserver
|
||||
increaseViewportBy={1000}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Carousel;
|
||||
@@ -0,0 +1,20 @@
|
||||
'use client';
|
||||
|
||||
import Preview from '../Preview';
|
||||
|
||||
import Carousel from './components/Carousel';
|
||||
import useRandomMovie from './useRandomMovie';
|
||||
|
||||
const Random = () => {
|
||||
const { movies, movie, index, onIndexChange, fetchNextPage } = useRandomMovie();
|
||||
|
||||
return (
|
||||
<Preview
|
||||
show={movie}
|
||||
className='bg-background rounded-md'
|
||||
card={<Carousel index={index} shows={movies} onIndexChange={onIndexChange} onEndReached={fetchNextPage} />}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default Random;
|
||||
@@ -0,0 +1,38 @@
|
||||
'use client';
|
||||
|
||||
import { startTransition, useCallback, useState } from 'react';
|
||||
|
||||
import { randomMovies } from '@/api';
|
||||
import useInfiniteList from '@/hooks/useInfiniteList';
|
||||
import useSessionRef from '@/hooks/useSessionRef';
|
||||
|
||||
const useRandomMovie = () => {
|
||||
const [indexRef, setIndexRef] = useSessionRef('random-movie-index', 0);
|
||||
const [index, setIndex] = useState(indexRef.current);
|
||||
|
||||
const { shows: movies, fetchNextPage } = useInfiniteList({
|
||||
queryKey: ['random-movie'],
|
||||
queryFn: () => randomMovies()
|
||||
});
|
||||
|
||||
if (movies.length && !movies[index]) {
|
||||
setIndex(0);
|
||||
setIndexRef(0);
|
||||
}
|
||||
|
||||
return {
|
||||
index,
|
||||
movies,
|
||||
movie: movies[index],
|
||||
fetchNextPage,
|
||||
onIndexChange: useCallback(
|
||||
(index: number) => {
|
||||
setIndexRef(index);
|
||||
startTransition(() => setIndex(index));
|
||||
},
|
||||
[setIndexRef]
|
||||
)
|
||||
};
|
||||
};
|
||||
|
||||
export default useRandomMovie;
|
||||
+6
-6
@@ -5,16 +5,16 @@ import { User2 } from 'lucide-react';
|
||||
import Image from 'next/image';
|
||||
import Link from 'next/link';
|
||||
|
||||
import useCredits from '@/app/(site)/useCredits';
|
||||
import useCredits from './useCredits';
|
||||
|
||||
interface Props {
|
||||
type?: ShowType;
|
||||
movieId: number;
|
||||
showId: Show['id'];
|
||||
showType?: Show['type'];
|
||||
onPersonClick?: (id: string) => void;
|
||||
}
|
||||
|
||||
const Credits: FC<Props> = ({ movieId, onPersonClick, type = 'movie' }) => {
|
||||
const { data: credits } = useCredits({ movieId, type });
|
||||
const Credits: FC<Props> = ({ showId, showType = 'movie', onPersonClick }) => {
|
||||
const { data: credits } = useCredits({ showId, showType });
|
||||
|
||||
return (
|
||||
Boolean(credits?.length) && (
|
||||
@@ -44,7 +44,7 @@ const Credits: FC<Props> = ({ movieId, onPersonClick, type = 'movie' }) => {
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className='text-white text-sm absolute w-full h-full top-0 left-0 rounded-md flex flex-col justify-between p-2 py-1 card-gradient'>
|
||||
<div className='text-white text-sm absolute w-full h-full top-0 left-0 rounded-md flex flex-col justify-between p-2 py-1 bg-vignette'>
|
||||
<p className=' overflow-ellipsis whitespace-nowrap overflow-hidden'>{actor.name}</p>
|
||||
{Boolean(actor.character) && (
|
||||
<p className='overflow-ellipsis whitespace-nowrap overflow-hidden'>{actor.character}</p>
|
||||
@@ -0,0 +1,18 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { credits } from '@/api';
|
||||
|
||||
interface Props {
|
||||
showId: Show['id'];
|
||||
showType?: Show['type'];
|
||||
}
|
||||
|
||||
const useCredits = ({ showId, showType }: Props) => {
|
||||
return useQuery({
|
||||
queryKey: ['credits', showId, showType],
|
||||
queryFn: () => credits({ showId, showType }),
|
||||
enabled: Boolean(showId)
|
||||
});
|
||||
};
|
||||
|
||||
export default useCredits;
|
||||
+3
-3
@@ -7,11 +7,11 @@ import { useFavoriteToggle } from '@/app/(site)/favorites/useFavorites';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface Props {
|
||||
movie: Movie;
|
||||
show: Show;
|
||||
}
|
||||
|
||||
const Favorite: FC<Props> = ({ movie }) => {
|
||||
const { isFavorite, toggle } = useFavoriteToggle(movie);
|
||||
const Favorite: FC<Props> = ({ show }) => {
|
||||
const { isFavorite, toggle } = useFavoriteToggle(show);
|
||||
|
||||
return (
|
||||
<span onClick={toggle} className='cursor-pointer' title={isFavorite ? 'Remove from favorites' : 'Add to favorite'}>
|
||||
+3
-3
@@ -5,12 +5,12 @@ import { FC } from 'react';
|
||||
import { useFavoriteToggle } from '@/app/(site)/favorites/useFavorites';
|
||||
|
||||
interface Props {
|
||||
movie: Movie;
|
||||
show: Show;
|
||||
onClick?: () => void;
|
||||
}
|
||||
|
||||
const Handlers: FC<Props> = ({ onClick, movie }) => {
|
||||
const { toggle } = useFavoriteToggle(movie);
|
||||
const Handlers: FC<Props> = ({ onClick, show }) => {
|
||||
const { toggle } = useFavoriteToggle(show);
|
||||
|
||||
return <div onClick={onClick} onDoubleClick={toggle} className='absolute top-0 left-0 w-full h-full' />;
|
||||
};
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,31 @@
|
||||
import { FC } from 'react';
|
||||
import { CaretSortIcon } from '@radix-ui/react-icons';
|
||||
import { ArrowDownIcon } from 'lucide-react';
|
||||
|
||||
import { Sort } from '@/api/parsers';
|
||||
import { TableHead } from '@/components/ui/table';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface Props {
|
||||
title: string;
|
||||
sort: Sort;
|
||||
value: Sort;
|
||||
sortable: boolean;
|
||||
onChange: (sort: Sort) => void;
|
||||
}
|
||||
|
||||
const TableHeadSortable: FC<Props> = ({ title, sort, value, sortable, onChange }) => {
|
||||
const handleSort = !sortable ? undefined : () => onChange(value === Sort.seeds ? Sort.size : Sort.seeds);
|
||||
|
||||
return (
|
||||
<TableHead onClick={handleSort} className={cn('select-none px-2', sortable && 'cursor-pointer')}>
|
||||
<div className='flex gap-1 items-center'>
|
||||
<span>{title}</span>
|
||||
{sortable &&
|
||||
(sort === value ? <ArrowDownIcon className='ml-2 h-4 w-4' /> : <CaretSortIcon className='ml-2 h-4 w-4' />)}
|
||||
</div>
|
||||
</TableHead>
|
||||
);
|
||||
};
|
||||
|
||||
export default TableHeadSortable;
|
||||
@@ -0,0 +1,6 @@
|
||||
import { TPBTorrents, YTSTorrents } from '@/api';
|
||||
|
||||
export const providers = {
|
||||
yts: { label: 'YTS', key: 'yts', queryFn: YTSTorrents, sortable: false },
|
||||
tpb: { label: 'The Pirate Bay', key: 'tpb', queryFn: TPBTorrents, sortable: true }
|
||||
};
|
||||
+20
-50
@@ -1,61 +1,34 @@
|
||||
import React, { Dispatch, FC, Fragment, SetStateAction, useState } from 'react';
|
||||
import React, { Fragment, useState } from 'react';
|
||||
import { create, InstanceProps } from 'react-modal-promise';
|
||||
import { ArrowDownIcon, CaretSortIcon } from '@radix-ui/react-icons';
|
||||
import { Cast, Copy, Loader, Magnet } from 'lucide-react';
|
||||
|
||||
import useTorrents from '@/app/(site)/useTorrents';
|
||||
import { Sort } from '@/api/parsers';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Modal } from '@/components/ui/dialog';
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
|
||||
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
import { Toggle } from '@/components/ui/toggle';
|
||||
import { useCastMagnet, usePrefix } from '@/hooks/useMagnetHosts';
|
||||
import { TPBTorrents, YTSTorrents } from '@/lib/api';
|
||||
import { Sort } from '@/lib/api/parsers';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
import TableHeadSortable from './components/TableHeadSortable';
|
||||
import { providers } from './constants';
|
||||
import showHostManagerModal from './HostManager';
|
||||
import useTorrents from './useTorrents';
|
||||
|
||||
interface Props extends InstanceProps<void> {
|
||||
id: number;
|
||||
type: ShowType;
|
||||
showId: Show['id'];
|
||||
showType: Show['type'];
|
||||
title: string;
|
||||
year: number;
|
||||
}
|
||||
|
||||
const TableHeadSortable: FC<{
|
||||
title: string;
|
||||
sort: Sort;
|
||||
value: Sort;
|
||||
sortable: boolean;
|
||||
onChange: Dispatch<SetStateAction<Sort>>;
|
||||
}> = ({ title, sort, value, onChange, sortable }) => {
|
||||
return (
|
||||
<TableHead
|
||||
onClick={!sortable ? undefined : () => onChange((sort) => (sort === Sort.seeds ? Sort.size : Sort.seeds))}
|
||||
className={cn('select-none px-2', sortable && 'cursor-pointer')}
|
||||
>
|
||||
<div className='flex gap-1 items-center'>
|
||||
<span>{title}</span>
|
||||
{sortable &&
|
||||
(sort === value ? <ArrowDownIcon className='ml-2 h-4 w-4' /> : <CaretSortIcon className='ml-2 h-4 w-4' />)}
|
||||
</div>
|
||||
</TableHead>
|
||||
);
|
||||
};
|
||||
|
||||
const providers = [
|
||||
{ label: 'YTS', key: 'yts', queryFn: YTSTorrents, sortable: false },
|
||||
{ label: 'The Pirate Bay', key: 'tpb', queryFn: TPBTorrents, sortable: true }
|
||||
];
|
||||
|
||||
const Torrents: FC<Props> = ({ title, year, type, id, onResolve }) => {
|
||||
const showTorrentsModal = create(({ title, year, showType, showId, onResolve }: Props) => {
|
||||
const isMobile = matchMedia('(max-width: 600px)').matches;
|
||||
const prefix = usePrefix();
|
||||
const [sort, setSort] = useState<Sort>(Sort.seeds);
|
||||
const [withYear, setWithYear] = useState(true);
|
||||
const [{ key, queryFn, sortable }, setProvider] = useState(providers[0]);
|
||||
const [{ key, queryFn, sortable }, setProvider] = useState(providers.yts);
|
||||
|
||||
const query = key === 'yts' ? title : withYear ? `${title} ${year || ''}` : title;
|
||||
const query = key === providers.yts.key ? title : withYear ? `${title} ${year || ''}` : title;
|
||||
|
||||
const {
|
||||
data: torrents,
|
||||
@@ -64,8 +37,8 @@ const Torrents: FC<Props> = ({ title, year, type, id, onResolve }) => {
|
||||
} = useTorrents({
|
||||
query,
|
||||
sort,
|
||||
id,
|
||||
type,
|
||||
showId,
|
||||
showType,
|
||||
key,
|
||||
queryFn
|
||||
});
|
||||
@@ -80,14 +53,13 @@ const Torrents: FC<Props> = ({ title, year, type, id, onResolve }) => {
|
||||
<TableHead className='px-2' colSpan={4}>
|
||||
<div className='grid grid-cols-[1fr_auto] items-center gap-3'>
|
||||
<span className='overflow-ellipsis overflow-hidden text-base whitespace-nowrap'>{title}</span>
|
||||
<Toggle
|
||||
size='sm'
|
||||
className='p-2 h-7'
|
||||
pressed={withYear}
|
||||
<Button
|
||||
className='h-6 p-2'
|
||||
variant={withYear ? 'default' : 'ghost'}
|
||||
onClick={() => setWithYear((withYear) => !withYear)}
|
||||
>
|
||||
{year}
|
||||
</Toggle>
|
||||
</Button>
|
||||
</div>
|
||||
</TableHead>
|
||||
</TableRow>
|
||||
@@ -95,7 +67,7 @@ const Torrents: FC<Props> = ({ title, year, type, id, onResolve }) => {
|
||||
<th colSpan={5}>
|
||||
<Tabs defaultValue={key} value={key} className='w-full rounded-none'>
|
||||
<TabsList className='grid w-full grid-cols-2'>
|
||||
{providers.map((provider) => (
|
||||
{Object.values(providers).map((provider) => (
|
||||
<TabsTrigger key={provider.key} value={provider.key} onClick={() => setProvider(provider)}>
|
||||
{provider.label}
|
||||
</TabsTrigger>
|
||||
@@ -173,8 +145,6 @@ const Torrents: FC<Props> = ({ title, year, type, id, onResolve }) => {
|
||||
</Table>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
});
|
||||
|
||||
export const showTorrentsModal = create(Torrents);
|
||||
|
||||
export default Torrents;
|
||||
export default showTorrentsModal;
|
||||
@@ -0,0 +1,27 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { Sort } from '@/api/parsers';
|
||||
|
||||
const useTorrents = ({
|
||||
query,
|
||||
sort,
|
||||
showId,
|
||||
showType,
|
||||
key,
|
||||
queryFn
|
||||
}: {
|
||||
showId: Show['id'];
|
||||
showType: Show['type'];
|
||||
key: string;
|
||||
query: string;
|
||||
sort: Sort;
|
||||
queryFn: (params: { query: string; sort: Sort; showId: Show['id']; showType: Show['type'] }) => Promise<Torrent[]>;
|
||||
}) => {
|
||||
return useQuery({
|
||||
enabled: Boolean(query),
|
||||
queryKey: [key, query, sort, showId, showType],
|
||||
queryFn: () => queryFn({ query, sort, showId, showType })
|
||||
});
|
||||
};
|
||||
|
||||
export default useTorrents;
|
||||
@@ -0,0 +1,39 @@
|
||||
'use client';
|
||||
|
||||
import { ReactNode } from 'react';
|
||||
import { create, InstanceProps } from 'react-modal-promise';
|
||||
|
||||
import { Modal } from '@/components/ui/dialog';
|
||||
|
||||
import useTrailer from './useTrailer';
|
||||
|
||||
interface Props {
|
||||
showId: Show['id'];
|
||||
showType?: Show['type'];
|
||||
children: ({ onPlay, disabled }: { onPlay: () => void; disabled: boolean }) => ReactNode;
|
||||
}
|
||||
|
||||
const showTrailerModal = create(({ trailerKey, onResolve }: { trailerKey?: string } & InstanceProps<void>) => {
|
||||
if (!trailerKey) return;
|
||||
|
||||
return (
|
||||
<Modal className='block p-0 max-w-[930px] border-none bg-black' style={{ aspectRatio: '16/9' }} onClose={onResolve}>
|
||||
<iframe
|
||||
allowFullScreen
|
||||
allow='autoplay'
|
||||
className='border-none rounded-lg'
|
||||
width='100%'
|
||||
height='100%'
|
||||
src={`//www.youtube.com/embed/${trailerKey}?autoplay=1`}
|
||||
/>
|
||||
</Modal>
|
||||
);
|
||||
});
|
||||
|
||||
const ToggleTrailer = ({ showId, showType = 'movie', children }: Props) => {
|
||||
const { data: trailer, isFetched } = useTrailer({ showId, showType });
|
||||
|
||||
return children({ onPlay: () => showTrailerModal({ trailerKey: trailer?.key }), disabled: isFetched && !trailer });
|
||||
};
|
||||
|
||||
export default ToggleTrailer;
|
||||
@@ -0,0 +1,21 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { trailers } from '@/api';
|
||||
|
||||
interface Props {
|
||||
showId: Show['id'];
|
||||
showType: Show['type'];
|
||||
}
|
||||
|
||||
const useTrailer = ({ showId, showType = 'movie' }: Props) =>
|
||||
useQuery({
|
||||
enabled: Boolean(showId),
|
||||
queryKey: ['trailers', showId, showType],
|
||||
queryFn: () => trailers({ showId, showType }),
|
||||
select(trailers) {
|
||||
const trailer = trailers[0];
|
||||
return trailer?.site === 'YouTube' ? trailer : null;
|
||||
}
|
||||
});
|
||||
|
||||
export default useTrailer;
|
||||
@@ -1,21 +1,21 @@
|
||||
import { FC } from 'react';
|
||||
import { DetailedHTMLProps, FC, HTMLAttributes } from 'react';
|
||||
|
||||
import Poster from '@/components/Movie/components/Poster';
|
||||
import Rating from '@/components/Movie/components/Rating';
|
||||
import Poster from '@/components/Show/components/Poster';
|
||||
import Rating from '@/components/Show/components/Rating';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
import Favorite from './components/Favorite';
|
||||
import Handlers from './components/Handlers';
|
||||
|
||||
interface Props {
|
||||
movie?: Movie;
|
||||
show?: Show;
|
||||
onClick?: () => void;
|
||||
className?: string;
|
||||
containerProps?: unknown;
|
||||
containerProps?: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
|
||||
}
|
||||
|
||||
const Card: FC<Props> = ({ movie, onClick, className, containerProps }) => {
|
||||
if (!movie) return null;
|
||||
const Show: FC<Props> = ({ show, onClick, className, containerProps }) => {
|
||||
if (!show) return null;
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -26,18 +26,18 @@ const Card: FC<Props> = ({ movie, onClick, className, containerProps }) => {
|
||||
)}
|
||||
>
|
||||
<div className='flex w-full h-full'>
|
||||
<Poster title={movie.name || movie.title} poster={movie.poster_path} />
|
||||
<Poster title={show.title} poster={show.poster} />
|
||||
</div>
|
||||
<div className='text-white absolute w-full h-full top-0 left-0 rounded-md flex flex-col justify-between p-2 card-gradient'>
|
||||
<Handlers movie={movie} onClick={onClick} />
|
||||
<div className='text-white absolute w-full h-full top-0 left-0 rounded-md flex flex-col justify-between p-2 bg-vignette'>
|
||||
<Handlers show={show} onClick={onClick} />
|
||||
<div className='grid grid-cols-[1fr_auto] opacity-75 gap-2'>
|
||||
<span className='overflow-ellipsis overflow-hidden whitespace-nowrap'>{movie.name || movie.title}</span>
|
||||
{Boolean(movie.release_date) && <span>{new Date(movie.release_date).getFullYear()}</span>}
|
||||
<span className='overflow-ellipsis overflow-hidden whitespace-nowrap'>{show.title}</span>
|
||||
{Boolean(show.release) && <span>{new Date(show.release).getFullYear()}</span>}
|
||||
</div>
|
||||
<div className='opacity-75 mb-[-5px]'>
|
||||
<span className='select-none flex w-full items-center ml-auto gap-1 mt-[-8px] justify-between z-[1]'>
|
||||
<Favorite movie={movie} />
|
||||
<Rating rating={movie.vote_average} />
|
||||
<Favorite show={show} />
|
||||
<Rating rating={show.rating} />
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -45,4 +45,4 @@ const Card: FC<Props> = ({ movie, onClick, className, containerProps }) => {
|
||||
);
|
||||
};
|
||||
|
||||
export default Card;
|
||||
export default Show;
|
||||
@@ -0,0 +1,20 @@
|
||||
import { FC } from 'react';
|
||||
|
||||
import { showPreviewModal } from '@/components/Preview';
|
||||
import Card from '@/components/Show';
|
||||
|
||||
interface Props {
|
||||
shows: Show[];
|
||||
}
|
||||
|
||||
const Marquee: FC<Props> = ({ shows }) => (
|
||||
<ul className='flex overflow-auto gap-2 rounded-lg snap-mandatory snap-x no-scrollbar opacity-0 animate-fade-aside-slide-in'>
|
||||
{shows.map((show) => (
|
||||
<li key={show.id} className='snap-start'>
|
||||
<Card className='!h-[350px] !w-[230px] text-sm' show={show} onClick={() => showPreviewModal({ show })} />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
|
||||
export default Marquee;
|
||||
@@ -0,0 +1,14 @@
|
||||
export const tabs = [
|
||||
{
|
||||
title: 'Trending',
|
||||
type: 'trending'
|
||||
},
|
||||
{
|
||||
title: 'Streaming',
|
||||
type: 'streaming'
|
||||
},
|
||||
{
|
||||
title: 'In theaters',
|
||||
type: 'theater'
|
||||
}
|
||||
];
|
||||
@@ -0,0 +1,31 @@
|
||||
'use client';
|
||||
|
||||
import { FC, useState } from 'react';
|
||||
|
||||
import Nav from '@/components/ui/nav';
|
||||
|
||||
import Marquee from './components/Marquee';
|
||||
import { tabs } from './constants';
|
||||
import useTrending from './useTrending';
|
||||
|
||||
const Trending: FC = () => {
|
||||
const [active, setActive] = useState(tabs[0]);
|
||||
const isMobile = typeof window === 'undefined' ? true : matchMedia('(max-width: 600px)').matches;
|
||||
|
||||
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 shows = { trending, streaming, theater }[active.type] || [];
|
||||
|
||||
return (
|
||||
isFetched && (
|
||||
<div>
|
||||
<Nav tabs={tabs} active={active} onChange={(active) => setActive(active)} className='mb-3' />
|
||||
<Marquee key={active.type} shows={shows} />
|
||||
</div>
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
export default Trending;
|
||||
@@ -0,0 +1,13 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { popularByType, trendingMovies } from '@/api';
|
||||
|
||||
const useTrending = ({ type, enabled }: { enabled?: boolean; type: 'trending' | 'streaming' | 'theater' | 'rent' }) => {
|
||||
return useQuery({
|
||||
enabled,
|
||||
queryKey: ['trending', type],
|
||||
queryFn: () => (type === 'trending' ? trendingMovies() : popularByType({ type }))
|
||||
});
|
||||
};
|
||||
|
||||
export default useTrending;
|
||||
@@ -1,79 +0,0 @@
|
||||
import * as React from 'react'
|
||||
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
const Card = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'rounded-lg border bg-card text-card-foreground shadow-sm',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
Card.displayName = 'Card'
|
||||
|
||||
const CardHeader = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn('flex flex-col space-y-1.5 p-6', className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
CardHeader.displayName = 'CardHeader'
|
||||
|
||||
const CardTitle = React.forwardRef<
|
||||
HTMLParagraphElement,
|
||||
React.HTMLAttributes<HTMLHeadingElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<h3
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'text-2xl font-semibold leading-none tracking-tight',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
CardTitle.displayName = 'CardTitle'
|
||||
|
||||
const CardDescription = React.forwardRef<
|
||||
HTMLParagraphElement,
|
||||
React.HTMLAttributes<HTMLParagraphElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<p
|
||||
ref={ref}
|
||||
className={cn('text-sm text-muted-foreground', className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
CardDescription.displayName = 'CardDescription'
|
||||
|
||||
const CardContent = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div ref={ref} className={cn('p-6 pt-0', className)} {...props} />
|
||||
))
|
||||
CardContent.displayName = 'CardContent'
|
||||
|
||||
const CardFooter = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn(' flex items-center p-6 pt-0', className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
CardFooter.displayName = 'CardFooter'
|
||||
|
||||
export { Card, CardContent,CardDescription, CardFooter, CardHeader, CardTitle }
|
||||
@@ -1,89 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import * as React from 'react';
|
||||
import { Drawer as DrawerPrimitive } from 'vaul';
|
||||
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
const Drawer = ({ shouldScaleBackground = true, ...props }: React.ComponentProps<typeof DrawerPrimitive.Root>) => (
|
||||
<DrawerPrimitive.Root shouldScaleBackground={shouldScaleBackground} {...props} />
|
||||
);
|
||||
Drawer.displayName = 'Drawer';
|
||||
|
||||
const DrawerTrigger = DrawerPrimitive.Trigger;
|
||||
|
||||
const DrawerPortal = DrawerPrimitive.Portal;
|
||||
|
||||
const DrawerClose = DrawerPrimitive.Close;
|
||||
|
||||
const DrawerOverlay = React.forwardRef<
|
||||
React.ElementRef<typeof DrawerPrimitive.Overlay>,
|
||||
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Overlay>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DrawerPrimitive.Overlay ref={ref} className={cn('fixed inset-0 z-50 bg-black/80', className)} {...props} />
|
||||
));
|
||||
DrawerOverlay.displayName = DrawerPrimitive.Overlay.displayName;
|
||||
|
||||
const DrawerContent = React.forwardRef<
|
||||
React.ElementRef<typeof DrawerPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Content>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<DrawerPortal>
|
||||
<DrawerOverlay />
|
||||
<DrawerPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'fixed inset-x-0 bottom-0 z-50 mt-24 flex h-auto flex-col rounded-t-[10px] border bg-background',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<div className='mx-auto mt-4 h-2 w-[100px] rounded-full bg-muted' />
|
||||
{children}
|
||||
</DrawerPrimitive.Content>
|
||||
</DrawerPortal>
|
||||
));
|
||||
DrawerContent.displayName = 'DrawerContent';
|
||||
|
||||
const DrawerHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div className={cn('grid gap-1.5 p-4 text-center sm:text-left', className)} {...props} />
|
||||
);
|
||||
DrawerHeader.displayName = 'DrawerHeader';
|
||||
|
||||
const DrawerFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div className={cn('mt-auto flex flex-col gap-2 p-4', className)} {...props} />
|
||||
);
|
||||
DrawerFooter.displayName = 'DrawerFooter';
|
||||
|
||||
const DrawerTitle = React.forwardRef<
|
||||
React.ElementRef<typeof DrawerPrimitive.Title>,
|
||||
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Title>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DrawerPrimitive.Title
|
||||
ref={ref}
|
||||
className={cn('text-lg font-semibold leading-none tracking-tight', className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
DrawerTitle.displayName = DrawerPrimitive.Title.displayName;
|
||||
|
||||
const DrawerDescription = React.forwardRef<
|
||||
React.ElementRef<typeof DrawerPrimitive.Description>,
|
||||
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Description>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DrawerPrimitive.Description ref={ref} className={cn('text-sm text-muted-foreground', className)} {...props} />
|
||||
));
|
||||
DrawerDescription.displayName = DrawerPrimitive.Description.displayName;
|
||||
|
||||
export {
|
||||
Drawer,
|
||||
DrawerClose,
|
||||
DrawerContent,
|
||||
DrawerDescription,
|
||||
DrawerFooter,
|
||||
DrawerHeader,
|
||||
DrawerOverlay,
|
||||
DrawerPortal,
|
||||
DrawerTitle,
|
||||
DrawerTrigger
|
||||
};
|
||||
@@ -1,32 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import * as React from 'react';
|
||||
import * as SliderPrimitive from '@radix-ui/react-slider';
|
||||
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
const Slider = React.forwardRef<
|
||||
React.ElementRef<typeof SliderPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof SliderPrimitive.Root>
|
||||
>(({ className, ...props }, ref) => {
|
||||
return (
|
||||
<SliderPrimitive.Root
|
||||
ref={ref}
|
||||
className={cn('relative flex w-full touch-none select-none items-center', className)}
|
||||
{...props}
|
||||
>
|
||||
<SliderPrimitive.Track className='relative h-2 w-full grow overflow-hidden rounded-full bg-secondary'>
|
||||
<SliderPrimitive.Range className='absolute h-full bg-primary' />
|
||||
</SliderPrimitive.Track>
|
||||
<SliderPrimitive.Thumb className='block px-1 rounded-full border-2 border-primary bg-background ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50'>
|
||||
{props.value?.[0]}
|
||||
</SliderPrimitive.Thumb>
|
||||
<SliderPrimitive.Thumb className='block px-1 rounded-full border-2 border-primary bg-background ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50'>
|
||||
{props.value?.[1]}
|
||||
</SliderPrimitive.Thumb>
|
||||
</SliderPrimitive.Root>
|
||||
);
|
||||
});
|
||||
Slider.displayName = SliderPrimitive.Root.displayName;
|
||||
|
||||
export { Slider };
|
||||
@@ -1,39 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import * as React from 'react';
|
||||
import * as TogglePrimitive from '@radix-ui/react-toggle';
|
||||
import { cva, type VariantProps } from 'class-variance-authority';
|
||||
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
const toggleVariants = cva(
|
||||
'inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground',
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: 'bg-transparent',
|
||||
outline: 'border border-input bg-transparent hover:bg-accent hover:text-accent-foreground'
|
||||
},
|
||||
size: {
|
||||
default: 'h-10 px-3',
|
||||
sm: 'h-9 px-2.5',
|
||||
lg: 'h-11 px-5'
|
||||
}
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: 'default',
|
||||
size: 'default'
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const Toggle = React.forwardRef<
|
||||
React.ElementRef<typeof TogglePrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof TogglePrimitive.Root> & VariantProps<typeof toggleVariants>
|
||||
>(({ className, variant, size, ...props }, ref) => (
|
||||
<TogglePrimitive.Root ref={ref} className={cn(toggleVariants({ variant, size, className }))} {...props} />
|
||||
));
|
||||
|
||||
Toggle.displayName = TogglePrimitive.Root.displayName;
|
||||
|
||||
export { Toggle, toggleVariants };
|
||||
Reference in new issue
Block a user