refactor: clean code and remove unnecessary dependencies
This commit is contained in:
1 parent
eceae6fec7
commit
ebf599eed6
92 files changed
+1122
-2812
No files matched your search
@@ -1,23 +1,28 @@
|
||||
class Server {
|
||||
get<T>(url: string, { params }: { params?: Record<string, unknown> } = {}): Promise<T> {
|
||||
const base = 'https://api.themoviedb.org/3';
|
||||
class Http {
|
||||
base = 'https://api.themoviedb.org/3';
|
||||
|
||||
get<T>(url: string, { params }: { params?: Record<string, unknown> } = {}): Promise<T> {
|
||||
const serializedParams = Object.entries(params || {}).reduce((params, [key, value]) => {
|
||||
if (!['', undefined, null].includes(value as string)) {
|
||||
params.set(key, value as string);
|
||||
}
|
||||
|
||||
return params;
|
||||
}, new URLSearchParams());
|
||||
|
||||
return fetch(`${base}${url}?${serializedParams}`, {
|
||||
next: { revalidate: 3600 },
|
||||
return fetch(`${this.base}${url}?${serializedParams}`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${process.env.MOVIE_DB_TOKEN}`
|
||||
}
|
||||
}).then((response) => response.json());
|
||||
},
|
||||
next: { revalidate: 3600 }
|
||||
}).then((response) => {
|
||||
if (!response.ok) return Promise.reject(response);
|
||||
|
||||
return response.json();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const server = new Server();
|
||||
const http = new Http();
|
||||
|
||||
export default server;
|
||||
export default http;
|
||||
@@ -0,0 +1,23 @@
|
||||
const mapMoviesSeriesResponseToShows = (
|
||||
{ total_pages, page, results }: TMDBPagination<Movie> | TMDBPagination<Series>,
|
||||
type: Show['type'] = 'movie'
|
||||
): Pagination<Show> => ({
|
||||
page,
|
||||
total: total_pages,
|
||||
results: results
|
||||
.map(({ id, overview, backdrop_path, poster_path, vote_average, vote_count, ...item }) => ({
|
||||
id,
|
||||
type,
|
||||
overview,
|
||||
backdrop: backdrop_path,
|
||||
poster: poster_path,
|
||||
rating: vote_average,
|
||||
votes: vote_count,
|
||||
release: 'release_date' in item ? item.release_date : item.first_air_date,
|
||||
title: 'release_date' in item ? item.title : item.name,
|
||||
genres: []
|
||||
}))
|
||||
.filter((show) => show.votes && show.release)
|
||||
});
|
||||
|
||||
export default mapMoviesSeriesResponseToShows;
|
||||
+219
@@ -0,0 +1,219 @@
|
||||
'use server';
|
||||
|
||||
import { createUniqueRandomGenerator } from '../lib/utils';
|
||||
|
||||
import mapMoviesSeriesResponseToShows from './dto/Show';
|
||||
import pirateBay from './parsers/pirate-bay';
|
||||
import yts from './parsers/yts';
|
||||
import http from './Http';
|
||||
import { Sort } from './parsers';
|
||||
|
||||
export const search = async ({
|
||||
query,
|
||||
page,
|
||||
type = 'movie'
|
||||
}: {
|
||||
query: string;
|
||||
page: string;
|
||||
type: Show['type'];
|
||||
}): Promise<Pagination<Show>> => {
|
||||
return http
|
||||
.get<TMDBPagination<Movie>>(`/search/${type}`, {
|
||||
params: {
|
||||
query,
|
||||
page
|
||||
}
|
||||
})
|
||||
.then((response) => mapMoviesSeriesResponseToShows(response, type));
|
||||
};
|
||||
|
||||
const generatePage = createUniqueRandomGenerator(500);
|
||||
|
||||
export const randomMovies = async (): Promise<Pagination<Show>> => {
|
||||
return http
|
||||
.get<TMDBPagination<Movie>>('/discover/movie', {
|
||||
params: {
|
||||
sort_by: 'popularity.desc',
|
||||
with_origin_country: 'UA|GB|JP|AU|US|IT|DE|FR',
|
||||
page: generatePage()
|
||||
}
|
||||
})
|
||||
.then(mapMoviesSeriesResponseToShows);
|
||||
};
|
||||
|
||||
export const popularByType = async ({ type }: { type: 'streaming' | 'theater' | 'rent' }): Promise<Show[]> => {
|
||||
const params =
|
||||
type === 'theater'
|
||||
? { with_release_type: 3 }
|
||||
: { with_watch_monetization_types: type === 'streaming' ? 'flatrate' : 'rent' };
|
||||
|
||||
return http
|
||||
.get<TMDBPagination<Movie>>('/discover/movie', {
|
||||
params: {
|
||||
...params,
|
||||
watch_region: 'US'
|
||||
}
|
||||
})
|
||||
.then((response) => {
|
||||
const data = mapMoviesSeriesResponseToShows(response);
|
||||
|
||||
return data.results;
|
||||
});
|
||||
};
|
||||
|
||||
export const popularMovies = async ({ page }: { page?: string } = {}): Promise<Pagination<Show>> => {
|
||||
return http
|
||||
.get<TMDBPagination<Movie>>('/discover/movie', {
|
||||
params: {
|
||||
page,
|
||||
sort_by: 'popularity.desc',
|
||||
'vote_count.gte': 0,
|
||||
'vote_average.lte': 10,
|
||||
'vote_average.gte': 0,
|
||||
'with_runtime.gte': 0,
|
||||
'with_runtime.lte': 400
|
||||
}
|
||||
})
|
||||
.then(mapMoviesSeriesResponseToShows);
|
||||
};
|
||||
|
||||
export const trendingMovies = async ({ page }: { page?: string } = {}): Promise<Show[]> => {
|
||||
return http
|
||||
.get<TMDBPagination<Movie>>('/trending/movie/day', {
|
||||
params: {
|
||||
page
|
||||
}
|
||||
})
|
||||
.then((response) => {
|
||||
const data = mapMoviesSeriesResponseToShows(response);
|
||||
|
||||
return data.results;
|
||||
});
|
||||
};
|
||||
|
||||
export const topMovies = async ({ page, starring }: { page?: string; starring?: string } = {}): Promise<
|
||||
Pagination<Show>
|
||||
> => {
|
||||
return http
|
||||
.get<TMDBPagination<Movie>>('/discover/movie', {
|
||||
params: {
|
||||
page,
|
||||
with_cast: starring,
|
||||
with_people: starring,
|
||||
sort_by: 'vote_average.desc',
|
||||
'vote_count.gte': 300,
|
||||
'vote_average.lte': 10,
|
||||
'vote_average.gte': 0
|
||||
}
|
||||
})
|
||||
.then(mapMoviesSeriesResponseToShows);
|
||||
};
|
||||
|
||||
export const similarShows = async ({
|
||||
page,
|
||||
showId,
|
||||
showType = 'movie'
|
||||
}: {
|
||||
page?: string;
|
||||
showId: string;
|
||||
showType: Show['type'];
|
||||
}): Promise<Pagination<Show>> => {
|
||||
return http
|
||||
.get<TMDBPagination<Movie> | TMDBPagination<Series>>(`/${showType}/${showId}/recommendations`, {
|
||||
params: {
|
||||
page
|
||||
}
|
||||
})
|
||||
.then((response) => mapMoviesSeriesResponseToShows(response, showType));
|
||||
};
|
||||
|
||||
export const externalIDs = async ({
|
||||
showId,
|
||||
showType = 'movie'
|
||||
}: {
|
||||
showType: Show['type'];
|
||||
showId: Show['id'];
|
||||
}): Promise<string> => {
|
||||
return http.get<ExternalIDS>(`/${showType}/${showId}/external_ids`).then(({ imdb_id }) => imdb_id);
|
||||
};
|
||||
|
||||
export const credits = async ({
|
||||
showId,
|
||||
showType = 'movie'
|
||||
}: {
|
||||
showId: Show['id'];
|
||||
showType?: Show['type'];
|
||||
}): Promise<Array<Actor>> => {
|
||||
return http
|
||||
.get<{ cast: Array<unknown> }>(`/${showType}/${showId}/${showType === 'tv' ? 'aggregate_credits' : 'credits'}`)
|
||||
.then((data) => {
|
||||
if (showType === 'tv') {
|
||||
return data.cast.map((item) => {
|
||||
const actor = item as AggregatedActor;
|
||||
const [role] = actor.roles || [{}];
|
||||
return { ...actor, ...role } as unknown as Actor;
|
||||
});
|
||||
}
|
||||
return data.cast as Array<Actor>;
|
||||
});
|
||||
};
|
||||
|
||||
export const trailers = async ({
|
||||
showId,
|
||||
showType
|
||||
}: {
|
||||
showId: Show['id'];
|
||||
showType?: Show['type'];
|
||||
}): Promise<Trailer[]> => {
|
||||
return http
|
||||
.get<{ id: number; results: Trailer[] }>(`/${showType}/${showId}/videos`, {
|
||||
params: {
|
||||
language: 'en-US'
|
||||
}
|
||||
})
|
||||
.then((data) => data.results);
|
||||
};
|
||||
|
||||
export const YTSTorrents = async ({
|
||||
query,
|
||||
sort,
|
||||
showType,
|
||||
showId
|
||||
}: {
|
||||
query: string;
|
||||
sort: Sort;
|
||||
showId: Show['id'];
|
||||
showType: Show['type'];
|
||||
}) => {
|
||||
try {
|
||||
const imdbID = await externalIDs({ showType, showId });
|
||||
const torrents = await yts.search({
|
||||
imdbID,
|
||||
query,
|
||||
sort
|
||||
});
|
||||
return torrents;
|
||||
} catch (error) {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export const TPBTorrents = async ({
|
||||
query,
|
||||
sort
|
||||
}: {
|
||||
query: string;
|
||||
sort: Sort;
|
||||
showId: Show['id'];
|
||||
showType: Show['type'];
|
||||
}) => {
|
||||
try {
|
||||
const torrents = await pirateBay.search({
|
||||
query,
|
||||
sort
|
||||
});
|
||||
return torrents;
|
||||
} catch (error) {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,85 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { Dispatch, SetStateAction, useRef, useState } from 'react';
|
||||
|
||||
import useFilters from '@/app/(site)/useFilters';
|
||||
import { Card } from '@/components/ui/card';
|
||||
import { Slider } from '@/components/ui/slider';
|
||||
import { Toggle } from '@/components/ui/toggle';
|
||||
import useUrlToMagnet from '@/hooks/useUrlToMagnet';
|
||||
|
||||
import useGenres from './useGenres';
|
||||
|
||||
export default function Filter() {
|
||||
useUrlToMagnet();
|
||||
|
||||
const { filters, setFilters } = useFilters();
|
||||
const { data: genres, isFetched } = useGenres();
|
||||
|
||||
const [years, setYears] = useState(filters.year || ['1990', new Date().getFullYear().toString()]);
|
||||
const [scores, setScores] = useState(filters.score || ['0', '10']);
|
||||
|
||||
const timeout = useRef<NodeJS.Timeout>();
|
||||
|
||||
const handleChangeGenre = (id: number) => () => {
|
||||
const genreId = id.toString();
|
||||
|
||||
setFilters({
|
||||
name: 'genres',
|
||||
value: filters.genres?.includes(genreId)
|
||||
? filters.genres.filter((id) => id !== genreId)
|
||||
: [...(filters.genres || []), genreId]
|
||||
});
|
||||
};
|
||||
|
||||
const handleDebouncedChange =
|
||||
(setter: Dispatch<SetStateAction<Array<string>>>, key: keyof Filters) => (value: Array<number>) => {
|
||||
clearTimeout(timeout.current);
|
||||
|
||||
timeout.current = setTimeout(() => setFilters({ name: key, value: value.map((value) => value.toString()) }), 300);
|
||||
|
||||
setter(value.map((value) => value.toString()));
|
||||
};
|
||||
|
||||
if (!isFetched) return;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Card className='mb-2'>
|
||||
<ul className='flex gap-2 overflow-auto no-scrollbar'>
|
||||
{genres?.map((genre) => (
|
||||
<li key={genre.id}>
|
||||
<Toggle
|
||||
data-state={filters.genres?.includes(genre.id.toString()) ? 'on' : 'off'}
|
||||
onClick={handleChangeGenre(genre.id)}
|
||||
className='whitespace-nowrap'
|
||||
>
|
||||
{genre.name}
|
||||
</Toggle>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</Card>
|
||||
<div className='flex w-full my-4 gap-6 flex-wrap'>
|
||||
<div className='grow flex items-center basis-[250px]'>
|
||||
<Slider
|
||||
onValueChange={handleDebouncedChange(setYears, 'year')}
|
||||
value={years.map((value) => parseInt(value))}
|
||||
min={1960}
|
||||
max={new Date().getFullYear()}
|
||||
step={1}
|
||||
/>
|
||||
</div>
|
||||
<div className='grow flex items-center basis-[250px]'>
|
||||
<Slider
|
||||
onValueChange={handleDebouncedChange(setScores, 'score')}
|
||||
value={scores.map((value) => parseInt(value))}
|
||||
min={0}
|
||||
max={10}
|
||||
step={1}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { useAtom } from 'jotai';
|
||||
import { atomWithStorage } from 'jotai/utils';
|
||||
import { SlidersHorizontal } from 'lucide-react';
|
||||
|
||||
import { Button } from '@/components/ui/button';
|
||||
import useMounted from '@/hooks/useMounted';
|
||||
import { genres } from '@/lib/api';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
|
||||
import Filter from './Filter';
|
||||
|
||||
const isShowFilterAtom = atomWithStorage('is-show-filters', false);
|
||||
|
||||
export default function FilterToggle() {
|
||||
const [isShowFilter, setIsShowFilter] = useAtom(isShowFilterAtom);
|
||||
const isMounted = useMounted();
|
||||
|
||||
useEffect(() => {
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
queryClient.prefetchQuery({ queryKey: ['genres'], queryFn: () => genres() });
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
{isShowFilter && <Filter />}
|
||||
{isMounted &&
|
||||
createPortal(
|
||||
<Button
|
||||
className='p-2'
|
||||
onClick={() => setIsShowFilter((isShow) => !isShow)}
|
||||
title={isShowFilter ? 'Hide filters' : 'Show filters'}
|
||||
variant='ghost'
|
||||
>
|
||||
<SlidersHorizontal size={19} />
|
||||
</Button>,
|
||||
document.getElementById('actions')!
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { genres } from '@/lib/api';
|
||||
|
||||
const useGenres = () => {
|
||||
return useQuery({
|
||||
queryKey: ['genres'],
|
||||
queryFn: () => genres()
|
||||
});
|
||||
};
|
||||
|
||||
export default useGenres;
|
||||
@@ -1,35 +1,17 @@
|
||||
'use client';
|
||||
import Random from '@/components/Random';
|
||||
import Trending from '@/components/Trending';
|
||||
|
||||
import Preview from '@/components/Movie/Preview';
|
||||
|
||||
import Carousel from './components/Carousel';
|
||||
import Trending from './components/Trending';
|
||||
import useRandomMovie from './useRandomMovie';
|
||||
|
||||
const Random = () => {
|
||||
const { movies, movie, index, onIndexChange, fetchNextPage } = useRandomMovie();
|
||||
|
||||
return (
|
||||
<Preview
|
||||
movie={movie}
|
||||
className='bg-background rounded-md'
|
||||
card={<Carousel index={index} movies={movies} onIndexChange={onIndexChange} onEndReached={fetchNextPage} />}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default function Container() {
|
||||
return (
|
||||
const Container = () => (
|
||||
<div className='flex flex-col flex-1'>
|
||||
<div className='xs:mb-4'>
|
||||
<Random />
|
||||
<div className='w-full h-2' />
|
||||
</div>
|
||||
|
||||
<div className='xs:block hidden w-full rounded-lg'>
|
||||
<Trending />
|
||||
<div className='w-full h-2' />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
export default Container;
|
||||
@@ -1,19 +1,22 @@
|
||||
'use client';
|
||||
|
||||
import useFavorites from '@/app/(site)/favorites/useFavorites';
|
||||
import List from '@/components/Movie/List';
|
||||
import List from '@/components/List';
|
||||
import useMounted from '@/hooks/useMounted';
|
||||
|
||||
import useFavorites from './useFavorites';
|
||||
|
||||
export default function Container() {
|
||||
const { pages } = useFavorites();
|
||||
const { shows } = useFavorites();
|
||||
const isMounted = useMounted();
|
||||
|
||||
if (isMounted && !pages[0]?.results?.length)
|
||||
if (!isMounted) return null;
|
||||
|
||||
if (!shows.length)
|
||||
return (
|
||||
<div className='h-40 w-full flex items-center text-center justify-center text-xl text-muted-foreground'>
|
||||
There are no items in your favorites list
|
||||
</div>
|
||||
);
|
||||
|
||||
return <List pages={pages} />;
|
||||
return <List shows={shows} />;
|
||||
}
|
||||
@@ -8,8 +8,8 @@ export const metadata: Metadata = {
|
||||
'View your favorite shows on Movie Advisor. Keep track of films you’ve added and revisit your top picks anytime.'
|
||||
};
|
||||
|
||||
export const revalidate = 3600;
|
||||
|
||||
export default function Favorites() {
|
||||
const Favorites = () => {
|
||||
return <Container />;
|
||||
}
|
||||
};
|
||||
|
||||
export default Favorites;
|
||||
@@ -1,41 +1,30 @@
|
||||
import { atom, useAtomValue, useSetAtom } from 'jotai';
|
||||
import { atomWithStorage } from 'jotai/utils';
|
||||
|
||||
const favoritesAtom = atomWithStorage<Array<MovieDBResponse>>('favorite', [
|
||||
{ page: 1, results: [], total_pages: 1, total_results: 0 }
|
||||
]);
|
||||
const favoritesAtom = atomWithStorage<Show[]>('favorite', [], undefined, {
|
||||
unstable_getOnInit: true
|
||||
});
|
||||
const favoritesMapAtom = atom((get) => {
|
||||
const map = new Map();
|
||||
const favorites = get(favoritesAtom);
|
||||
|
||||
favorites[0].results.forEach((movie) => map.set(movie.id, movie));
|
||||
favorites.forEach((show) => map.set(show.id, show));
|
||||
|
||||
return map as Map<number, Movie>;
|
||||
return map as Map<Show['id'], Show>;
|
||||
});
|
||||
|
||||
const useFavorites = () => {
|
||||
return {
|
||||
pages: useAtomValue(favoritesAtom),
|
||||
shows: useAtomValue(favoritesAtom),
|
||||
map: useAtomValue(favoritesMapAtom)
|
||||
};
|
||||
};
|
||||
|
||||
export const useFavoritesMutation = () => {
|
||||
const setFavorites = useSetAtom(favoritesAtom);
|
||||
const add = (movie: Movie) => {
|
||||
setFavorites((favorites) => {
|
||||
favorites[0].results = [movie, ...favorites[0].results];
|
||||
favorites[0].total_results = favorites[0].results.length;
|
||||
return [...favorites];
|
||||
});
|
||||
};
|
||||
|
||||
const remove = (movieId: number) => {
|
||||
setFavorites((favorites) => {
|
||||
favorites[0].results = favorites[0].results.filter((movie) => movie.id !== movieId);
|
||||
favorites[0].total_results = favorites[0].results.length;
|
||||
return [...favorites];
|
||||
});
|
||||
};
|
||||
const add = (show: Show) => setFavorites((favorites) => [show, ...favorites]);
|
||||
const remove = (showId: number) => setFavorites((favorites) => favorites.filter(({ id }) => id !== showId));
|
||||
|
||||
return {
|
||||
add,
|
||||
@@ -43,13 +32,13 @@ export const useFavoritesMutation = () => {
|
||||
};
|
||||
};
|
||||
|
||||
export const useFavoriteToggle = (movie: Movie) => {
|
||||
export const useFavoriteToggle = (show: Show) => {
|
||||
const { add, remove } = useFavoritesMutation();
|
||||
const { map } = useFavorites();
|
||||
|
||||
const isFavorite = map.has(movie.id);
|
||||
const isFavorite = map.has(show.id);
|
||||
|
||||
const toggle = () => (isFavorite ? remove(movie.id) : add(movie));
|
||||
const toggle = () => (isFavorite ? remove(show.id) : add(show));
|
||||
|
||||
return { isFavorite, toggle };
|
||||
};
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Loader } from 'lucide-react';
|
||||
|
||||
export default function Loading() {
|
||||
return (
|
||||
const Loading = () => (
|
||||
<div className='w-full min-h-[70vh] flex items-center justify-center'>
|
||||
<div className='animate-spin'>
|
||||
<Loader />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
export default Loading;
|
||||
+5
-3
@@ -1,11 +1,11 @@
|
||||
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||
|
||||
import { randomMovies } from '@/lib/api';
|
||||
import { randomMovies } from '@/api';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
|
||||
import Container from './container';
|
||||
|
||||
export default async function Random() {
|
||||
const Random = async () => {
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
await queryClient.prefetchInfiniteQuery({
|
||||
@@ -19,4 +19,6 @@ export default async function Random() {
|
||||
<Container />
|
||||
</HydrationBoundary>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default Random;
|
||||
@@ -1,20 +1,16 @@
|
||||
'use client';
|
||||
|
||||
import List from '@/components/Movie/List';
|
||||
import List from '@/components/List';
|
||||
import NoResults from '@/components/NoResults';
|
||||
|
||||
import usePopular from './usePopular';
|
||||
|
||||
export default function Container() {
|
||||
const { data: top, hasNextPage, fetchNextPage, isFetched } = usePopular();
|
||||
const Container = () => {
|
||||
const { shows, fetchNextPage, isFetched } = usePopular();
|
||||
|
||||
return (
|
||||
<>
|
||||
<List pages={top?.pages || []} fetchNextPage={fetchNextPage} hasNextPage={hasNextPage} />
|
||||
{isFetched && !top?.pages?.[0]?.results?.length && (
|
||||
<div className='h-40 w-full flex items-center justify-center text-xl text-muted-foreground'>
|
||||
Nothing was found
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
if (isFetched && !shows.length) return <NoResults />;
|
||||
|
||||
return <List shows={shows} fetchNextPage={fetchNextPage} />;
|
||||
};
|
||||
|
||||
export default Container;
|
||||
@@ -1,7 +1,7 @@
|
||||
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||
import { Metadata } from 'next';
|
||||
|
||||
import { popularMovies } from '@/lib/api';
|
||||
import { popularMovies } from '@/api';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
|
||||
import Container from './container';
|
||||
@@ -12,9 +12,7 @@ export const metadata: Metadata = {
|
||||
'Check out the most popular movies right now on Movie Advisor. See what’s trending and don’t miss out on the latest hits.'
|
||||
};
|
||||
|
||||
export const revalidate = 3600;
|
||||
|
||||
export default async function Popular() {
|
||||
const Popular = async () => {
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
await queryClient.prefetchInfiniteQuery({
|
||||
@@ -28,4 +26,6 @@ export default async function Popular() {
|
||||
<Container />
|
||||
</HydrationBoundary>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default Popular;
|
||||
@@ -1,23 +1,8 @@
|
||||
'use client';
|
||||
|
||||
import { useInfiniteQuery } from '@tanstack/react-query';
|
||||
import { popularMovies } from '@/api';
|
||||
import useInfiniteList from '@/hooks/useInfiniteList';
|
||||
|
||||
import { popularMovies } from '@/lib/api';
|
||||
|
||||
const usePopular = () => {
|
||||
return useInfiniteQuery({
|
||||
queryKey: ['popular'],
|
||||
queryFn: ({ pageParam }) => {
|
||||
return popularMovies({ page: pageParam as string });
|
||||
},
|
||||
getNextPageParam(lastPage) {
|
||||
const { page, total_pages } = lastPage as { page: number; total_pages: number };
|
||||
if (page === total_pages) return undefined;
|
||||
|
||||
return `${page + 1}`;
|
||||
},
|
||||
initialPageParam: '1'
|
||||
});
|
||||
};
|
||||
const usePopular = () => useInfiniteList({ queryKey: ['popular'], queryFn: popularMovies });
|
||||
|
||||
export default usePopular;
|
||||
@@ -2,32 +2,31 @@
|
||||
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
|
||||
import List from '@/components/Movie/List';
|
||||
import List from '@/components/List';
|
||||
import NoResults from '@/components/NoResults';
|
||||
|
||||
import useSimilar from './useSimilar';
|
||||
|
||||
export default function Container() {
|
||||
const Container = () => {
|
||||
const params = useSearchParams();
|
||||
|
||||
const title = params.get('title');
|
||||
const type = params.get('type');
|
||||
const movieId = params.get('movieId') || undefined;
|
||||
const title = params.get('title') as string;
|
||||
const showId = params.get('id') as string;
|
||||
const showType = params.get('type') as Show['type'];
|
||||
|
||||
const { data: top, hasNextPage, fetchNextPage, isFetched } = useSimilar({ movieId, type: type as ShowType });
|
||||
const { shows, fetchNextPage, isFetched } = useSimilar({ showId, showType });
|
||||
|
||||
return (
|
||||
<>
|
||||
{Boolean(title) && (
|
||||
<span className='inline-flex w-full h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground mb-2'>
|
||||
Similar: {decodeURIComponent(title || '')}
|
||||
Similar: {decodeURIComponent(title)}
|
||||
</span>
|
||||
)}
|
||||
<List type={type as ShowType} pages={top?.pages || []} fetchNextPage={fetchNextPage} hasNextPage={hasNextPage} />
|
||||
{isFetched && !top?.pages?.[0]?.results?.length && (
|
||||
<div className='h-40 w-full flex items-center justify-center text-xl text-muted-foreground'>
|
||||
Nothing was found
|
||||
</div>
|
||||
)}
|
||||
<List shows={shows} fetchNextPage={fetchNextPage} />
|
||||
{isFetched && !shows.length && <NoResults />}
|
||||
</>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default Container;
|
||||
@@ -1,18 +1,18 @@
|
||||
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||
|
||||
import { similarMovies } from '@/lib/api';
|
||||
import { similarShows } from '@/api';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
|
||||
import Container from './container';
|
||||
|
||||
export default async function Similar({ searchParams }: { searchParams: Record<string, string> }) {
|
||||
const Similar = async ({ searchParams }: { searchParams: Record<string, string> }) => {
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
const { movieId, type } = searchParams || {};
|
||||
const { id, type } = searchParams || {};
|
||||
|
||||
await queryClient.prefetchInfiniteQuery({
|
||||
queryKey: ['similar', movieId, type],
|
||||
queryFn: () => similarMovies({ movieId, type: type as ShowType }),
|
||||
queryKey: ['similar', id, type],
|
||||
queryFn: () => similarShows({ showId: id, showType: type as Show['type'] }),
|
||||
initialPageParam: '1'
|
||||
});
|
||||
|
||||
@@ -21,6 +21,6 @@ export default async function Similar({ searchParams }: { searchParams: Record<s
|
||||
<Container />
|
||||
</HydrationBoundary>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export const revalidate = 3600;
|
||||
export default Similar;
|
||||
@@ -1,24 +1,18 @@
|
||||
'use client';
|
||||
|
||||
import { useInfiniteQuery } from '@tanstack/react-query';
|
||||
import { similarShows } from '@/api';
|
||||
import useInfiniteList from '@/hooks/useInfiniteList';
|
||||
|
||||
import { similarMovies } from '@/lib/api';
|
||||
interface Props {
|
||||
showId: string;
|
||||
showType: Show['type'];
|
||||
}
|
||||
|
||||
const useSimilar = ({ movieId, type = 'movie' }: { movieId?: string; type?: ShowType }) => {
|
||||
return useInfiniteQuery({
|
||||
queryKey: ['similar', movieId, type],
|
||||
enabled: Boolean(movieId),
|
||||
queryFn: ({ pageParam }) => {
|
||||
return similarMovies({ page: pageParam as string, movieId, type });
|
||||
},
|
||||
getNextPageParam(lastPage) {
|
||||
const { page, total_pages } = lastPage as { page: number; total_pages: number };
|
||||
if (page === total_pages) return undefined;
|
||||
|
||||
return `${page + 1}`;
|
||||
},
|
||||
initialPageParam: '1'
|
||||
const useSimilar = ({ showId, showType = 'movie' }: Props) =>
|
||||
useInfiniteList({
|
||||
enabled: Boolean(showId),
|
||||
queryKey: ['similar', showId, showType],
|
||||
queryFn: ({ page }) => similarShows({ page, showId, showType })
|
||||
});
|
||||
};
|
||||
|
||||
export default useSimilar;
|
||||
@@ -2,17 +2,18 @@
|
||||
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
|
||||
import List from '@/components/Movie/List';
|
||||
import List from '@/components/List';
|
||||
import NoResults from '@/components/NoResults';
|
||||
|
||||
import useStarring from './useStarring';
|
||||
|
||||
export default function Container() {
|
||||
const Container = () => {
|
||||
const params = useSearchParams();
|
||||
|
||||
const title = params.get('title');
|
||||
const actorId = params.get('actorId') || undefined;
|
||||
const title = params.get('title') as string;
|
||||
const actorId = params.get('actorId') as string;
|
||||
|
||||
const { data: top, hasNextPage, fetchNextPage, isFetched } = useStarring({ actorId });
|
||||
const { shows, fetchNextPage, isFetched } = useStarring({ actorId });
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -21,12 +22,10 @@ export default function Container() {
|
||||
Starring: {decodeURIComponent(title || '')}
|
||||
</span>
|
||||
)}
|
||||
<List pages={top?.pages || []} fetchNextPage={fetchNextPage} hasNextPage={hasNextPage} />
|
||||
{isFetched && !top?.pages?.[0]?.results?.length && (
|
||||
<div className='h-40 w-full flex items-center justify-center text-xl text-muted-foreground'>
|
||||
Nothing was found
|
||||
</div>
|
||||
)}
|
||||
<List shows={shows} fetchNextPage={fetchNextPage} />
|
||||
{isFetched && !shows.length && <NoResults />}
|
||||
</>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default Container;
|
||||
@@ -1,6 +1,6 @@
|
||||
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||
|
||||
import { topMovies } from '@/lib/api';
|
||||
import { topMovies } from '@/api';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
|
||||
import Container from './container';
|
||||
|
||||
@@ -1,24 +1,15 @@
|
||||
'use client';
|
||||
|
||||
import { useInfiniteQuery } from '@tanstack/react-query';
|
||||
import { topMovies } from '@/api';
|
||||
import useInfiniteList from '@/hooks/useInfiniteList';
|
||||
|
||||
import { topMovies } from '@/lib/api';
|
||||
|
||||
const useStarring = ({ actorId }: { actorId?: string }) => {
|
||||
return useInfiniteQuery({
|
||||
const useStarring = ({ actorId }: { actorId?: string }) =>
|
||||
useInfiniteList({
|
||||
queryKey: ['starring', actorId],
|
||||
enabled: Boolean(actorId),
|
||||
queryFn: ({ pageParam }) => {
|
||||
return topMovies({ page: pageParam as string, starring: actorId });
|
||||
},
|
||||
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 }) => {
|
||||
return topMovies({ page, starring: actorId });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export default useStarring;
|
||||
@@ -1,20 +1,16 @@
|
||||
'use client';
|
||||
|
||||
import List from '@/components/Movie/List';
|
||||
import List from '@/components/List';
|
||||
import NoResults from '@/components/NoResults';
|
||||
|
||||
import useTop from './useTop';
|
||||
|
||||
export default function Container() {
|
||||
const { data: top, hasNextPage, fetchNextPage, isFetched } = useTop();
|
||||
const Container = () => {
|
||||
const { shows, fetchNextPage, isFetched } = useTop();
|
||||
|
||||
return (
|
||||
<>
|
||||
<List pages={top?.pages || []} fetchNextPage={fetchNextPage} hasNextPage={hasNextPage} />
|
||||
{isFetched && !top?.pages?.[0]?.results?.length && (
|
||||
<div className='h-40 w-full flex items-center justify-center text-xl text-muted-foreground'>
|
||||
Nothing was found
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
if (isFetched && !shows.length) return <NoResults />;
|
||||
|
||||
return <List shows={shows} fetchNextPage={fetchNextPage} />;
|
||||
};
|
||||
|
||||
export default Container;
|
||||
@@ -1,7 +1,7 @@
|
||||
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||
import { Metadata } from 'next';
|
||||
|
||||
import { topMovies } from '@/lib/api';
|
||||
import { topMovies } from '@/api';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
|
||||
import Container from './container';
|
||||
@@ -12,9 +12,7 @@ export const metadata: Metadata = {
|
||||
'Discover the top-rated movies on Movie Advisor. Find the highest-rated films and make informed viewing choices.'
|
||||
};
|
||||
|
||||
export const revalidate = 3600;
|
||||
|
||||
export default async function Top() {
|
||||
const Top = async () => {
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
await queryClient.prefetchInfiniteQuery({
|
||||
@@ -28,4 +26,6 @@ export default async function Top() {
|
||||
<Container />
|
||||
</HydrationBoundary>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default Top;
|
||||
@@ -1,23 +1,8 @@
|
||||
'use client';
|
||||
|
||||
import { useInfiniteQuery } from '@tanstack/react-query';
|
||||
import { topMovies } from '@/api';
|
||||
import useInfiniteList from '@/hooks/useInfiniteList';
|
||||
|
||||
import { topMovies } from '@/lib/api';
|
||||
|
||||
const useTop = () => {
|
||||
return useInfiniteQuery({
|
||||
queryKey: ['top'],
|
||||
queryFn: ({ pageParam }) => {
|
||||
return topMovies({ page: pageParam as string });
|
||||
},
|
||||
getNextPageParam(lastPage) {
|
||||
const { page, total_pages } = lastPage as { page: number; total_pages: number };
|
||||
if (page === total_pages) return undefined;
|
||||
|
||||
return `${page + 1}`;
|
||||
},
|
||||
initialPageParam: '1'
|
||||
});
|
||||
};
|
||||
const useTop = () => useInfiniteList({ queryKey: ['top'], queryFn: topMovies });
|
||||
|
||||
export default useTop;
|
||||
@@ -1,13 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { credits } from '@/lib/api';
|
||||
|
||||
const useCredits = ({ movieId, type }: { movieId?: Movie['id']; type?: ShowType }) => {
|
||||
return useQuery({
|
||||
queryKey: ['credits', movieId, type],
|
||||
queryFn: () => credits({ movieId: movieId!, type }),
|
||||
enabled: Boolean(movieId)
|
||||
});
|
||||
};
|
||||
|
||||
export default useCredits;
|
||||
@@ -1,28 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { useMemo } from 'react';
|
||||
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
||||
|
||||
import { mapFilters } from '@/lib/utils';
|
||||
|
||||
const useFilters = () => {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
const filters = useMemo(() => Object.fromEntries(searchParams.entries()), [searchParams]);
|
||||
const setFilters = ({ name, value }: { name: string; value: string[] }) => {
|
||||
const search = Object.entries({ ...filters, [name]: value })
|
||||
.filter(([_, value]) => value?.length)
|
||||
.map(([key, value]) => `${key}=${value}`)
|
||||
.join('&');
|
||||
|
||||
router.replace(`${pathname}?${search}`);
|
||||
};
|
||||
|
||||
return {
|
||||
filters: useMemo(() => mapFilters(filters), [filters]),
|
||||
setFilters
|
||||
};
|
||||
};
|
||||
|
||||
export default useFilters;
|
||||
@@ -1,27 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { Sort } from '@/lib/api/parsers';
|
||||
|
||||
const useTorrents = ({
|
||||
query,
|
||||
sort,
|
||||
id,
|
||||
type,
|
||||
key,
|
||||
queryFn
|
||||
}: {
|
||||
type: ShowType;
|
||||
key: string;
|
||||
id: number;
|
||||
query: string;
|
||||
sort: Sort;
|
||||
queryFn: (params: { query: string; sort: Sort; id: number; type: ShowType }) => Promise<Torrent[]>;
|
||||
}) => {
|
||||
return useQuery({
|
||||
enabled: Boolean(query),
|
||||
queryKey: [key, query, sort, id, type],
|
||||
queryFn: () => queryFn({ query, sort, id, type })
|
||||
});
|
||||
};
|
||||
|
||||
export default useTorrents;
|
||||
@@ -1,17 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { trailers } from '@/lib/api';
|
||||
|
||||
const useTrailer = ({ movieId, type = 'movie' }: { movieId?: number; type?: ShowType }) => {
|
||||
return useQuery({
|
||||
enabled: Boolean(movieId),
|
||||
queryKey: ['trailers', movieId, type],
|
||||
queryFn: () => trailers({ movieId: movieId!, type }),
|
||||
select(trailers) {
|
||||
const trailer = trailers[0];
|
||||
return trailer?.site === 'YouTube' ? trailer : null;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export default useTrailer;
|
||||
+6
-4
@@ -24,7 +24,7 @@ export const viewport: Viewport = {
|
||||
userScalable: false
|
||||
};
|
||||
|
||||
export default function RootLayout({ children }: { children: ReactNode }) {
|
||||
const RootLayout = ({ children }: { children: ReactNode }) => {
|
||||
const theme = cookies().get('theme')?.value as Theme;
|
||||
|
||||
return (
|
||||
@@ -34,12 +34,14 @@ export default function RootLayout({ children }: { children: ReactNode }) {
|
||||
</head>
|
||||
<body style={poppins.style}>
|
||||
<Providers theme={theme}>
|
||||
<div className='fixed w-full left-0 top-0 z-20'>
|
||||
<div className='sticky top-0 z-20'>
|
||||
<Header />
|
||||
</div>
|
||||
<main className='px-2 mx-auto flex flex-col flex-1 w-full max-w-[1240px] mt-[56px]'>{children}</main>
|
||||
<main className='container'>{children}</main>
|
||||
</Providers>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default RootLayout;
|
||||
@@ -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')}
|
||||
>
|
||||
{tabs.length > 1 ? (
|
||||
<Tabs defaultValue='movie' className={cn('w-full px-2')}>
|
||||
<TabsList className='grid w-full grid-cols-2'>
|
||||
<TabsTrigger value='movies'>Movies</TabsTrigger>
|
||||
<TabsTrigger value='series'>Series</TabsTrigger>
|
||||
{tabs.map(({ type, title }) => (
|
||||
<TabsTrigger key={type} value={type}>
|
||||
{title}
|
||||
</TabsTrigger>
|
||||
))}
|
||||
</TabsList>
|
||||
<TabsContent value='movies'>
|
||||
{Boolean(movies?.pages.length && movies?.pages?.[0]?.results?.length) && (
|
||||
{tabs.map(({ data: { shows, fetchNextPage }, type }) => (
|
||||
<TabsContent value={type} key={type}>
|
||||
<List
|
||||
shows={shows}
|
||||
customScrollParent={scrollRef.current}
|
||||
pages={movies!.pages as unknown as MovieDBResponse[]}
|
||||
fetchNextPage={fetchNextMoviesPage}
|
||||
hasNextPage={hasNextMoviesPage}
|
||||
onPreviewClose={handleClose}
|
||||
type='movie'
|
||||
fetchNextPage={fetchNextPage}
|
||||
onPreviewClose={onResolve}
|
||||
/>
|
||||
)}
|
||||
</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.map(({ data: { shows, fetchNextPage }, type }) => (
|
||||
<List
|
||||
key={type}
|
||||
shows={shows}
|
||||
customScrollParent={scrollRef.current}
|
||||
fetchNextPage={fetchNextPage}
|
||||
onPreviewClose={onResolve}
|
||||
/>
|
||||
))
|
||||
)}
|
||||
</Modal>
|
||||
);
|
||||
});
|
||||
|
||||
export default function ToggleSearch() {
|
||||
return (
|
||||
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' });
|
||||
+52
-55
@@ -1,62 +1,11 @@
|
||||
'use client';
|
||||
|
||||
import { forwardRef, useEffect, useLayoutEffect, useRef } from 'react';
|
||||
import { FC, forwardRef, useEffect, useLayoutEffect, useRef } from 'react';
|
||||
import { Virtuoso, VirtuosoHandle, VirtuosoProps } from 'react-virtuoso';
|
||||
|
||||
import Card from '@/components/Movie/Card';
|
||||
import Card from '@/components/Show';
|
||||
|
||||
const Carousel = ({
|
||||
index,
|
||||
movies,
|
||||
onIndexChange,
|
||||
onEndReached
|
||||
}: {
|
||||
index: number;
|
||||
movies?: Movie[];
|
||||
onIndexChange: (index: number) => void;
|
||||
onEndReached: () => void;
|
||||
}) => {
|
||||
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 >= (movies?.length || 0) - 1) return;
|
||||
ref.current?.scrollIntoView({ index: index + 1, behavior: 'smooth' });
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener('keydown', scrollTo);
|
||||
|
||||
return () => {
|
||||
document.removeEventListener('keydown', scrollTo);
|
||||
};
|
||||
}, [index, movies?.length]);
|
||||
|
||||
return (
|
||||
<div className='card-aspect-ratio mx-auto'>
|
||||
<Virtuoso
|
||||
ref={ref}
|
||||
data={movies}
|
||||
context={onIndexChange}
|
||||
endReached={onEndReached}
|
||||
initialTopMostItemIndex={initialIndex.current}
|
||||
components={components}
|
||||
horizontalDirection
|
||||
skipAnimationFrameInResizeObserver
|
||||
increaseViewportBy={1000}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const components: VirtuosoProps<Movie, (index: number) => void>['components'] = {
|
||||
const components: VirtuosoProps<Show, (index: number) => void>['components'] = {
|
||||
Item: ({ item, children, context: onIndexChange, ...props }) => {
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
const index = props['data-index'];
|
||||
@@ -85,7 +34,7 @@ const components: VirtuosoProps<Movie, (index: number) => void>['components'] =
|
||||
|
||||
return (
|
||||
<div {...props} ref={ref} className='snap-start'>
|
||||
<Card movie={item} />
|
||||
<Card show={item} />
|
||||
</div>
|
||||
);
|
||||
},
|
||||
@@ -99,4 +48,52 @@ const components: VirtuosoProps<Movie, (index: number) => void>['components'] =
|
||||
})
|
||||
};
|
||||
|
||||
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;
|
||||
@@ -1,32 +1,21 @@
|
||||
'use client';
|
||||
|
||||
import { startTransition, useCallback, useMemo, useState } from 'react';
|
||||
import { useInfiniteQuery } from '@tanstack/react-query';
|
||||
import { startTransition, useCallback, useState } from 'react';
|
||||
|
||||
import { randomMovies } from '@/api';
|
||||
import useInfiniteList from '@/hooks/useInfiniteList';
|
||||
import useSessionRef from '@/hooks/useSessionRef';
|
||||
import { randomMovies } from '@/lib/api';
|
||||
|
||||
const useRandomMovie = () => {
|
||||
const [indexRef, setIndexRef] = useSessionRef('random-movie-index', 0);
|
||||
const [index, setIndex] = useState(indexRef.current);
|
||||
|
||||
const { data, fetchNextPage } = useInfiniteQuery({
|
||||
const { shows: movies, fetchNextPage } = useInfiniteList({
|
||||
queryKey: ['random-movie'],
|
||||
queryFn: () => randomMovies(),
|
||||
getNextPageParam: () => '',
|
||||
initialPageParam: ''
|
||||
queryFn: () => randomMovies()
|
||||
});
|
||||
|
||||
const movies = useMemo(
|
||||
() =>
|
||||
data?.pages.reduce((movies, page) => {
|
||||
movies.push(...page);
|
||||
return movies;
|
||||
}, []),
|
||||
[data]
|
||||
);
|
||||
|
||||
if (movies?.length && !movies[index]) {
|
||||
if (movies.length && !movies[index]) {
|
||||
setIndex(0);
|
||||
setIndexRef(0);
|
||||
}
|
||||
@@ -34,7 +23,7 @@ const useRandomMovie = () => {
|
||||
return {
|
||||
index,
|
||||
movies,
|
||||
movie: movies?.[index],
|
||||
movie: movies[index],
|
||||
fetchNextPage,
|
||||
onIndexChange: useCallback(
|
||||
(index: number) => {
|
||||
+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'
|
||||
}
|
||||
];
|
||||
@@ -2,26 +2,12 @@
|
||||
|
||||
import { FC, useState } from 'react';
|
||||
|
||||
import Marquee from '@/components/Marquee';
|
||||
import Nav from '@/components/ui/nav';
|
||||
|
||||
import Marquee from './components/Marquee';
|
||||
import { tabs } from './constants';
|
||||
import useTrending from './useTrending';
|
||||
|
||||
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;
|
||||
@@ -30,13 +16,13 @@ const Trending: FC = () => {
|
||||
const { data: streaming } = useTrending({ type: 'streaming', enabled: !isMobile });
|
||||
const { data: theater } = useTrending({ type: 'theater', enabled: !isMobile });
|
||||
|
||||
const movies = { trending, streaming, theater }[active.type] || [];
|
||||
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} movies={movies} />
|
||||
<Marquee key={active.type} shows={shows} />
|
||||
</div>
|
||||
)
|
||||
);
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { popularByType, trendingMovies } from '@/lib/api';
|
||||
import { popularByType, trendingMovies } from '@/api';
|
||||
|
||||
const useTrending = ({ type, enabled }: { enabled?: boolean; type: 'trending' | 'streaming' | 'theater' | 'rent' }) => {
|
||||
return useQuery({
|
||||
@@ -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 };
|
||||
@@ -0,0 +1,25 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
|
||||
function useDistinctUntilChanged<T>(value: T, delayMS: number = 500): T {
|
||||
const [distinctValue, setDistinctValue] = useState(value);
|
||||
const previousValueRef = useRef(value);
|
||||
const timeoutRef = useRef<NodeJS.Timeout>();
|
||||
|
||||
useEffect(() => {
|
||||
const clear = () => clearTimeout(timeoutRef.current);
|
||||
|
||||
if (previousValueRef.current === value) return clear;
|
||||
|
||||
previousValueRef.current = value;
|
||||
|
||||
clearTimeout(timeoutRef.current);
|
||||
|
||||
timeoutRef.current = setTimeout(() => setDistinctValue(value), delayMS);
|
||||
|
||||
return clear;
|
||||
}, [value, delayMS]);
|
||||
|
||||
return distinctValue;
|
||||
}
|
||||
|
||||
export default useDistinctUntilChanged;
|
||||
@@ -0,0 +1,35 @@
|
||||
import { useMemo } from 'react';
|
||||
import { QueryKey, useInfiniteQuery } from '@tanstack/react-query';
|
||||
|
||||
interface Props {
|
||||
queryKey: QueryKey;
|
||||
enabled?: boolean;
|
||||
queryFn: ({ page }: { page: string }) => Promise<Pagination<Show>>;
|
||||
}
|
||||
|
||||
const useInfiniteList = ({ queryKey, queryFn, enabled }: Props) => {
|
||||
const { data, hasNextPage, fetchNextPage, isFetched, isLoading } = useInfiniteQuery({
|
||||
enabled,
|
||||
queryKey,
|
||||
queryFn: ({ pageParam }) => queryFn({ page: pageParam }),
|
||||
getNextPageParam(pagination) {
|
||||
if (!pagination || pagination.page === pagination.total) return undefined;
|
||||
|
||||
return `${pagination.page + 1}`;
|
||||
},
|
||||
initialPageParam: '1'
|
||||
});
|
||||
|
||||
const shows = useMemo(() => {
|
||||
return (
|
||||
data?.pages.reduce<Show[]>((shows, page) => {
|
||||
shows.push(...page.results);
|
||||
return shows;
|
||||
}, []) || []
|
||||
);
|
||||
}, [data?.pages]);
|
||||
|
||||
return { shows, fetchNextPage: hasNextPage ? fetchNextPage : undefined, isFetched, isLoading };
|
||||
};
|
||||
|
||||
export default useInfiniteList;
|
||||
@@ -2,7 +2,7 @@ import { useCallback } from 'react';
|
||||
import { useAtomValue, useSetAtom } from 'jotai';
|
||||
import { atomWithStorage } from 'jotai/utils';
|
||||
|
||||
import showHostManagerModal from '@/components/Movie/components/Torrents/HostManager';
|
||||
import showHostManagerModal from '@/components/Show/components/Torrents/HostManager';
|
||||
|
||||
const magnetPrefixAtom = atomWithStorage<string>('magnet-prefix', 'http://{host}:65220/playuri?uri=', undefined, {
|
||||
unstable_getOnInit: true
|
||||
|
||||
+4
-2
@@ -1,6 +1,6 @@
|
||||
import { useLayoutEffect, useState } from 'react';
|
||||
|
||||
export default function useMounted() {
|
||||
const useMounted = () => {
|
||||
const [isMounted, setIsMounted] = useState(false);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
@@ -8,4 +8,6 @@ export default function useMounted() {
|
||||
}, []);
|
||||
|
||||
return isMounted;
|
||||
}
|
||||
};
|
||||
|
||||
export default useMounted;
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useCallback, useRef } from 'react';
|
||||
|
||||
export default function useScrollDelta() {
|
||||
const useScrollDelta = () => {
|
||||
const lastKnownScrollPosition = useRef(0);
|
||||
const deltaY = useRef(0);
|
||||
|
||||
@@ -24,4 +24,6 @@ export default function useScrollDelta() {
|
||||
}
|
||||
}, [])
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export default useScrollDelta;
|
||||
+3
-1
@@ -4,4 +4,6 @@ import { useContext } from 'react';
|
||||
|
||||
import { ThemeContext } from '@/providers/Theme';
|
||||
|
||||
export const useTheme = () => useContext(ThemeContext);
|
||||
const useTheme = () => useContext(ThemeContext);
|
||||
|
||||
export default useTheme;
|
||||
@@ -1,21 +0,0 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
|
||||
import { useCastMagnet } from './useMagnetHosts';
|
||||
|
||||
const useUrlToMagnet = () => {
|
||||
const router = useRouter();
|
||||
const encodedUrl = useSearchParams().toString();
|
||||
|
||||
const cast = useCastMagnet();
|
||||
|
||||
useEffect(() => {
|
||||
if (!encodedUrl.includes('magnet')) return;
|
||||
|
||||
const url = decodeURIComponent(encodedUrl);
|
||||
|
||||
return void cast(url).finally(() => router.replace('/'));
|
||||
}, [encodedUrl]);
|
||||
};
|
||||
|
||||
export default useUrlToMagnet;
|
||||
@@ -1,193 +0,0 @@
|
||||
'use server';
|
||||
|
||||
import server from '@/network/server';
|
||||
|
||||
import filterUnknownMovies from '../filterUnknownMovies';
|
||||
import { createUniqueRandomGenerator } from '../utils';
|
||||
|
||||
import pirateBay from './parsers/pirate-bay';
|
||||
import yts from './parsers/yts';
|
||||
import { Sort } from './parsers';
|
||||
|
||||
export const search = async ({
|
||||
query,
|
||||
page,
|
||||
type = 'movie'
|
||||
}: {
|
||||
query: string;
|
||||
page: number;
|
||||
type: ShowType;
|
||||
}): Promise<MovieDBResponse> => {
|
||||
return server.get(`/search/${type}`, {
|
||||
params: {
|
||||
query,
|
||||
page
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const generatePage = createUniqueRandomGenerator(500);
|
||||
|
||||
export const randomMovies = async ({ filters }: { filters: Partial<Filters> } = { filters: {} }): Promise<Movie[]> => {
|
||||
return server
|
||||
.get<MovieDBResponse>('/discover/movie', {
|
||||
params: {
|
||||
sort_by: 'popularity.desc',
|
||||
with_origin_country: 'UA|GB|JP|AU|US|IT|DE|FR',
|
||||
page: generatePage(),
|
||||
with_genres: filters.genres?.join('|'),
|
||||
'vote_average.gte': filters.score?.[0],
|
||||
'vote_average.lte': filters.score?.[1],
|
||||
'release_date.gte': filters.year?.[0],
|
||||
'release_date.lte': filters.year?.[1]
|
||||
}
|
||||
})
|
||||
.then((data) => filterUnknownMovies(data.results));
|
||||
};
|
||||
|
||||
export const popularByType = async ({ type }: { type: 'streaming' | 'theater' | 'rent' }): Promise<Movie[]> => {
|
||||
const params =
|
||||
type === 'theater'
|
||||
? { with_release_type: 3 }
|
||||
: { with_watch_monetization_types: type === 'streaming' ? 'flatrate' : 'rent' };
|
||||
return server
|
||||
.get<MovieDBResponse>('/discover/movie', {
|
||||
params: {
|
||||
...params,
|
||||
watch_region: 'US'
|
||||
}
|
||||
})
|
||||
.then((data) => data.results);
|
||||
};
|
||||
|
||||
export const popularMovies = async ({ page }: { page?: string } = {}): Promise<MovieDBResponse> => {
|
||||
return server.get('/discover/movie', {
|
||||
params: {
|
||||
page,
|
||||
sort_by: 'popularity.desc',
|
||||
'vote_count.gte': 0,
|
||||
'vote_average.lte': 10,
|
||||
'vote_average.gte': 0,
|
||||
'with_runtime.gte': 0,
|
||||
'with_runtime.lte': 400
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const trendingMovies = async ({ page }: { page?: string } = {}): Promise<Movie[]> => {
|
||||
return server
|
||||
.get<MovieDBResponse>('/trending/movie/day', {
|
||||
params: {
|
||||
page
|
||||
}
|
||||
})
|
||||
.then((data) => data.results);
|
||||
};
|
||||
|
||||
export const topMovies = async ({
|
||||
page,
|
||||
starring
|
||||
}: { page?: string; starring?: string } = {}): Promise<MovieDBResponse> => {
|
||||
return server.get('/discover/movie', {
|
||||
params: {
|
||||
page,
|
||||
with_cast: starring,
|
||||
with_people: starring,
|
||||
sort_by: 'vote_average.desc',
|
||||
'vote_count.gte': 300,
|
||||
'vote_average.lte': 10,
|
||||
'vote_average.gte': 0
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const similarMovies = async ({
|
||||
page,
|
||||
movieId,
|
||||
type = 'movie'
|
||||
}: {
|
||||
page?: string;
|
||||
movieId?: string;
|
||||
type?: ShowType;
|
||||
}): Promise<MovieDBResponse> => {
|
||||
return server.get(`/${type}/${movieId}/recommendations`, {
|
||||
params: {
|
||||
page
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const genres = async (): Promise<IDName[]> => {
|
||||
return server.get<{ genres: IDName[] }>('/genre/movie/list').then((data) => data.genres);
|
||||
};
|
||||
|
||||
export const externalIDs = async ({ id, type = 'movie' }: { id: number; type: ShowType }): Promise<string> => {
|
||||
return server.get<ExternalIDS>(`/${type}/${id}/external_ids`).then(({ imdb_id }) => imdb_id);
|
||||
};
|
||||
|
||||
export const credits = async ({
|
||||
movieId,
|
||||
type = 'movie'
|
||||
}: {
|
||||
movieId: number;
|
||||
type?: ShowType;
|
||||
}): Promise<Array<Actor>> => {
|
||||
return server
|
||||
.get<{ cast: Array<unknown> }>(`/${type}/${movieId}/${type === 'tv' ? 'aggregate_credits' : 'credits'}`)
|
||||
.then((data) => {
|
||||
if (type === 'tv') {
|
||||
return data.cast.map((item) => {
|
||||
const actor = item as AggregatedActor;
|
||||
const [role] = actor.roles || [{}];
|
||||
return { ...actor, ...role } as unknown as Actor;
|
||||
});
|
||||
}
|
||||
return data.cast as Array<Actor>;
|
||||
});
|
||||
};
|
||||
|
||||
export const YTSTorrents = async ({
|
||||
query,
|
||||
sort,
|
||||
type,
|
||||
id
|
||||
}: {
|
||||
query: string;
|
||||
sort: Sort;
|
||||
id: number;
|
||||
type: ShowType;
|
||||
}) => {
|
||||
try {
|
||||
const imdbID = await externalIDs({ id, type });
|
||||
const torrents = await yts.search({
|
||||
imdbID,
|
||||
query,
|
||||
sort
|
||||
});
|
||||
return torrents;
|
||||
} catch (error) {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export const TPBTorrents = async ({ query, sort }: { query: string; sort: Sort; id: number; type: ShowType }) => {
|
||||
try {
|
||||
const torrents = await pirateBay.search({
|
||||
query,
|
||||
sort
|
||||
});
|
||||
return torrents;
|
||||
} catch (error) {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export const trailers = async ({ movieId, type }: { movieId: number; type?: ShowType }): Promise<Trailer[]> => {
|
||||
return server
|
||||
.get<{ id: number; results: Trailer[] }>(`/${type}/${movieId}/videos`, {
|
||||
params: {
|
||||
language: 'en-US'
|
||||
}
|
||||
})
|
||||
.then((data) => data.results);
|
||||
};
|
||||
@@ -1,5 +0,0 @@
|
||||
const filterUnknownMovies = (movies: Movie[]): Movie[] => {
|
||||
return movies?.filter((movie) => movie?.vote_count && (movie?.release_date || movie?.first_air_date)) || [];
|
||||
};
|
||||
|
||||
export default filterUnknownMovies;
|
||||
@@ -13,4 +13,5 @@ export const queryClientOptions: QueryClientConfig = {
|
||||
};
|
||||
|
||||
const getQueryClient = cache(() => new QueryClient(queryClientOptions));
|
||||
|
||||
export default getQueryClient;
|
||||
@@ -5,17 +5,6 @@ export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs));
|
||||
}
|
||||
|
||||
export const mapFilters = (filters: Record<string, string>) => {
|
||||
try {
|
||||
return Object.entries(filters).reduce((filters, [key, value]) => {
|
||||
filters[key as keyof Filters] = value.split(',');
|
||||
return filters;
|
||||
}, {} as Partial<Filters>);
|
||||
} catch (e) {
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
export const createUniqueRandomGenerator = (max: number) => {
|
||||
const numbers = Array.from({ length: max }, (_, i) => i + 1);
|
||||
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
import axios, { AxiosResponse } from 'axios';
|
||||
|
||||
const client = axios.create({
|
||||
baseURL: `${process.env.NODE_ENV === 'development' ? 'http://' : 'https://'}${
|
||||
process.env.NEXT_PUBLIC_MOVIE_ADVISOR_BASE
|
||||
}/api`,
|
||||
withCredentials: true
|
||||
});
|
||||
|
||||
const handleResponse = (response: AxiosResponse): AxiosResponse['data'] => response.data;
|
||||
|
||||
client.interceptors.response.use(handleResponse);
|
||||
|
||||
client.interceptors.request.use(async (config) => {
|
||||
if (typeof window !== 'undefined') return config;
|
||||
|
||||
const { cookies } = await import('next/headers');
|
||||
|
||||
config.headers.set('Cookie', cookies().toString());
|
||||
|
||||
return config;
|
||||
});
|
||||
|
||||
export default client;
|
||||
Generated
+86
-1230
File diff suppressed because it is too large.
Load diff
@@ -11,22 +11,12 @@
|
||||
"dependencies": {
|
||||
"@radix-ui/react-dialog": "^1.1.1",
|
||||
"@radix-ui/react-dropdown-menu": "^2.0.6",
|
||||
"@radix-ui/react-hover-card": "^1.0.7",
|
||||
"@radix-ui/react-icons": "^1.3.0",
|
||||
"@radix-ui/react-label": "^2.0.2",
|
||||
"@radix-ui/react-menubar": "^1.0.3",
|
||||
"@radix-ui/react-navigation-menu": "^1.1.4",
|
||||
"@radix-ui/react-popover": "^1.0.6",
|
||||
"@radix-ui/react-scroll-area": "^1.0.4",
|
||||
"@radix-ui/react-separator": "^1.0.3",
|
||||
"@radix-ui/react-slider": "^1.1.2",
|
||||
"@radix-ui/react-slot": "^1.0.2",
|
||||
"@radix-ui/react-switch": "^1.0.3",
|
||||
"@radix-ui/react-tabs": "^1.0.4",
|
||||
"@radix-ui/react-toggle": "^1.0.3",
|
||||
"@radix-ui/react-tooltip": "^1.0.7",
|
||||
"@tanstack/react-query": "^5.17.3",
|
||||
"@tanstack/react-query-devtools": "^5.28.4",
|
||||
"axios": "^1.4.0",
|
||||
"class-variance-authority": "^0.7.0",
|
||||
"classnames": "^2.3.2",
|
||||
@@ -34,7 +24,6 @@
|
||||
"cmdk": "^0.2.1",
|
||||
"eslint": "8.45.0",
|
||||
"eslint-config-next": "^14.2.7",
|
||||
"framer-motion": "^10.16.16",
|
||||
"jotai": "^2.2.2",
|
||||
"js-cookie": "^3.0.5",
|
||||
"lucide-react": "^0.263.0",
|
||||
|
||||
+10
-3
@@ -1,4 +1,4 @@
|
||||
import { createContext, Dispatch, ReactNode, SetStateAction, useEffect, useState } from 'react';
|
||||
import { createContext, Dispatch, FC, ReactNode, SetStateAction, useEffect, useState } from 'react';
|
||||
import Cookies from 'js-cookie';
|
||||
|
||||
export const ThemeContext = createContext<[Theme, Dispatch<SetStateAction<Theme>>]>([
|
||||
@@ -6,7 +6,12 @@ export const ThemeContext = createContext<[Theme, Dispatch<SetStateAction<Theme>
|
||||
() => null
|
||||
]);
|
||||
|
||||
export default function Provider({ children, theme: initialTheme }: { children: ReactNode; theme?: Theme }) {
|
||||
interface Props {
|
||||
children: ReactNode;
|
||||
theme?: Theme;
|
||||
}
|
||||
|
||||
const Provider: FC<Props> = ({ children, theme: initialTheme }) => {
|
||||
const state = useState<Theme>((Cookies.get('theme') || initialTheme) as Theme);
|
||||
|
||||
const [theme, setTheme] = state;
|
||||
@@ -21,4 +26,6 @@ export default function Provider({ children, theme: initialTheme }: { children:
|
||||
}, [theme, setTheme]);
|
||||
|
||||
return <ThemeContext.Provider value={state}>{children}</ThemeContext.Provider>;
|
||||
}
|
||||
};
|
||||
|
||||
export default Provider;
|
||||
+9
-3
@@ -1,13 +1,19 @@
|
||||
'use client';
|
||||
|
||||
import { ReactNode, useState } from 'react';
|
||||
import { FC, ReactNode, useState } from 'react';
|
||||
import ModalContainer from 'react-modal-promise';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
|
||||
import { queryClientOptions } from '@/lib/queryClient';
|
||||
import ThemeProvider from '@/providers/Theme';
|
||||
|
||||
const Providers = ({ children, theme }: { children: ReactNode; theme?: Theme }) => {
|
||||
import ThemeProvider from './Theme';
|
||||
|
||||
interface Props {
|
||||
children: ReactNode;
|
||||
theme?: Theme;
|
||||
}
|
||||
|
||||
const Providers: FC<Props> = ({ children, theme }) => {
|
||||
const [queryClient] = useState(() => new QueryClient(queryClientOptions));
|
||||
|
||||
return (
|
||||
|
||||
+25
-73
@@ -2,16 +2,6 @@
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
@layer utilities {
|
||||
.no-scrollbar::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
.no-scrollbar {
|
||||
-ms-overflow-style: none;
|
||||
scrollbar-width: none;
|
||||
}
|
||||
}
|
||||
|
||||
@layer base {
|
||||
:root {
|
||||
--background: 0 0% 100%;
|
||||
@@ -83,85 +73,47 @@
|
||||
@layer base {
|
||||
* {
|
||||
@apply border-border;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
-webkit-touch-callout: none;
|
||||
}
|
||||
::-moz-selection {
|
||||
color: hsl(var(--secondary));
|
||||
background: hsl(var(--secondary-foreground));
|
||||
}
|
||||
::selection {
|
||||
color: hsl(var(--secondary));
|
||||
background: hsl(var(--secondary-foreground));
|
||||
}
|
||||
body {
|
||||
@apply bg-background text-foreground;
|
||||
}
|
||||
}
|
||||
|
||||
html,
|
||||
body {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
@layer utilities {
|
||||
.no-scrollbar {
|
||||
-ms-overflow-style: none;
|
||||
scrollbar-width: none;
|
||||
}
|
||||
.no-scrollbar::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
* {
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
-webkit-touch-callout: none;
|
||||
}
|
||||
|
||||
::-moz-selection {
|
||||
color: white;
|
||||
background: black;
|
||||
}
|
||||
::selection {
|
||||
color: white;
|
||||
background: black;
|
||||
}
|
||||
|
||||
.card-gradient {
|
||||
background: linear-gradient(
|
||||
rgba(0, 0, 0, 0.4) 0%,
|
||||
rgba(0, 0, 0, 0.396) 2.83%,
|
||||
rgba(0, 0, 0, 0.384) 5.67%,
|
||||
rgba(0, 0, 0, 0.37) 8.5%,
|
||||
rgba(0, 0, 0, 0.34) 11.33%,
|
||||
rgba(0, 0, 0, 0.306) 14.17%,
|
||||
rgba(0, 0, 0, 0.267) 17%,
|
||||
rgba(0, 0, 0, 0.224) 19.83%,
|
||||
rgba(0, 0, 0, 0.176) 22.67%,
|
||||
rgba(0, 0, 0, 0.133) 25.5%,
|
||||
rgba(0, 0, 0, 0.094) 28.33%,
|
||||
rgba(0, 0, 0, 0.06) 31.17%,
|
||||
rgba(0, 0, 0, 0.03) 34%,
|
||||
rgba(0, 0, 0, 0.016) 36.83%,
|
||||
rgba(0, 0, 0, 0.004) 39.67%,
|
||||
rgba(0, 0, 0, 0) 42.5%,
|
||||
rgba(0, 0, 0, 0) 57.5%,
|
||||
rgba(0, 0, 0, 0.004) 60.33%,
|
||||
rgba(0, 0, 0, 0.016) 63.17%,
|
||||
rgba(0, 0, 0, 0.03) 66%,
|
||||
rgba(0, 0, 0, 0.06) 68.83%,
|
||||
rgba(0, 0, 0, 0.094) 71.67%,
|
||||
rgba(0, 0, 0, 0.133) 74.5%,
|
||||
rgba(0, 0, 0, 0.176) 77.33%,
|
||||
rgba(0, 0, 0, 0.224) 80.17%,
|
||||
rgba(0, 0, 0, 0.267) 83%,
|
||||
rgba(0, 0, 0, 0.306) 85.83%,
|
||||
rgba(0, 0, 0, 0.34) 88.67%,
|
||||
rgba(0, 0, 0, 0.37) 91.5%,
|
||||
rgba(0, 0, 0, 0.384) 94.33%,
|
||||
rgba(0, 0, 0, 0.396) 97.17%,
|
||||
rgba(0, 0, 0, 0.4) 100%
|
||||
);
|
||||
}
|
||||
|
||||
.card-aspect-ratio {
|
||||
.card-aspect-ratio {
|
||||
width: 300px;
|
||||
height: 450px;
|
||||
flex-shrink: 0;
|
||||
@media screen and (max-width: 500px) {
|
||||
@media screen and (max-width: 600px) {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
aspect-ratio: 2/3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@supports (hanging-punctuation: first) and (font: -apple-system-body) and (-webkit-appearance: none) {
|
||||
@supports (hanging-punctuation: first) and (font: -apple-system-body) and (-webkit-appearance: none) {
|
||||
.card-aspect-ratio {
|
||||
@media screen and (max-width: 500px) {
|
||||
aspect-ratio: 2/2.908;
|
||||
@media screen and (max-width: 600px) {
|
||||
aspect-ratio: 1.35/2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
-3
@@ -5,14 +5,14 @@ module.exports = {
|
||||
theme: {
|
||||
container: {
|
||||
center: true,
|
||||
padding: '2rem',
|
||||
padding: '0.5rem',
|
||||
screens: {
|
||||
'2xl': '1400px'
|
||||
DEFAULT: '1240px'
|
||||
}
|
||||
},
|
||||
extend: {
|
||||
screens: {
|
||||
xs: '500px'
|
||||
xs: '600px'
|
||||
},
|
||||
colors: {
|
||||
border: 'hsl(var(--border))',
|
||||
@@ -77,6 +77,10 @@ module.exports = {
|
||||
'accordion-up': 'accordion-up 0.2s ease-out',
|
||||
'fade-in-slide-in': 'fadeInSlideIn 0.2s ease-in-out forwards',
|
||||
'fade-aside-slide-in': 'fadeAsideSlideIn 0.2s ease-in-out forwards'
|
||||
},
|
||||
backgroundImage: {
|
||||
vignette:
|
||||
'linear-gradient(rgba(0, 0, 0, 0.4) 0%,rgba(0, 0, 0, 0.396) 2.83%,rgba(0, 0, 0, 0.384) 5.67%,rgba(0, 0, 0, 0.37) 8.5%,rgba(0, 0, 0, 0.34) 11.33%,rgba(0, 0, 0, 0.306) 14.17%,rgba(0, 0, 0, 0.267) 17%,rgba(0, 0, 0, 0.224) 19.83%,rgba(0, 0, 0, 0.176) 22.67%,rgba(0, 0, 0, 0.133) 25.5%,rgba(0, 0, 0, 0.094) 28.33%,rgba(0, 0, 0, 0.06) 31.17%,rgba(0, 0, 0, 0.03) 34%,rgba(0, 0, 0, 0.016) 36.83%,rgba(0, 0, 0, 0.004) 39.67%,rgba(0, 0, 0, 0) 42.5%,rgba(0, 0, 0, 0) 57.5%,rgba(0, 0, 0, 0.004) 60.33%,rgba(0, 0, 0, 0.016) 63.17%,rgba(0, 0, 0, 0.03) 66%,rgba(0, 0, 0, 0.06) 68.83%,rgba(0, 0, 0, 0.094) 71.67%,rgba(0, 0, 0, 0.133) 74.5%,rgba(0, 0, 0, 0.176) 77.33%,rgba(0, 0, 0, 0.224) 80.17%,rgba(0, 0, 0, 0.267) 83%,rgba(0, 0, 0, 0.306) 85.83%,rgba(0, 0, 0, 0.34) 88.67%,rgba(0, 0, 0, 0.37) 91.5%,rgba(0, 0, 0, 0.384) 94.33%,rgba(0, 0, 0, 0.396) 97.17%,rgba(0, 0, 0, 0.4) 100%)'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Vendored
+37
-73
@@ -1,13 +1,17 @@
|
||||
type Theme = 'light' | 'dark';
|
||||
|
||||
interface MovieDBResponse {
|
||||
interface TMDBPagination<T> {
|
||||
page: number;
|
||||
results: Movie[];
|
||||
results: T[];
|
||||
total_pages: number;
|
||||
total_results: number;
|
||||
}
|
||||
|
||||
type ShowType = 'movie' | 'tv';
|
||||
interface Pagination<T> {
|
||||
page: number;
|
||||
total: number;
|
||||
results: T[];
|
||||
}
|
||||
|
||||
interface Movie {
|
||||
adult: boolean;
|
||||
@@ -20,14 +24,42 @@ interface Movie {
|
||||
popularity: number;
|
||||
poster_path: string;
|
||||
release_date: Date;
|
||||
first_air_date?: Date;
|
||||
title: string;
|
||||
name?: string;
|
||||
video: boolean;
|
||||
vote_average: number;
|
||||
vote_count: number;
|
||||
}
|
||||
|
||||
interface Series {
|
||||
adult: boolean;
|
||||
backdrop_path: string;
|
||||
genre_ids: number[];
|
||||
id: number;
|
||||
origin_country: string[];
|
||||
original_language: string;
|
||||
original_name: string;
|
||||
overview: string;
|
||||
popularity: number;
|
||||
poster_path: string;
|
||||
first_air_date: Date;
|
||||
name: string;
|
||||
vote_average: number;
|
||||
vote_count: number;
|
||||
}
|
||||
|
||||
interface Show {
|
||||
type: 'movie' | 'tv';
|
||||
id: number;
|
||||
title: string;
|
||||
overview: string;
|
||||
backdrop: string;
|
||||
poster: string;
|
||||
release: Date;
|
||||
rating: number;
|
||||
votes: number;
|
||||
genres: string[];
|
||||
}
|
||||
|
||||
interface Actor {
|
||||
adult: boolean;
|
||||
gender: number;
|
||||
@@ -63,23 +95,6 @@ interface Role {
|
||||
episode_count: number;
|
||||
}
|
||||
|
||||
interface Person {
|
||||
adult: boolean;
|
||||
also_known_as: string[];
|
||||
biography: string;
|
||||
birthday: Date;
|
||||
deathday: null;
|
||||
gender: number;
|
||||
homepage: null;
|
||||
id: number;
|
||||
imdb_id: string;
|
||||
known_for_department: string;
|
||||
name: string;
|
||||
place_of_birth: string;
|
||||
popularity: number;
|
||||
profile_path: string;
|
||||
}
|
||||
|
||||
interface Trailer {
|
||||
iso_639_1: string;
|
||||
iso_3166_1: string;
|
||||
@@ -98,36 +113,6 @@ interface IDName<T = number> {
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface TrackerTorrent {
|
||||
author: string;
|
||||
category: string;
|
||||
id: string;
|
||||
leeches: number;
|
||||
seeds: number;
|
||||
size: number;
|
||||
state: string;
|
||||
title: string;
|
||||
downloads: number;
|
||||
registered: Date;
|
||||
host: string;
|
||||
}
|
||||
|
||||
interface PirateTorrent {
|
||||
id: string;
|
||||
name: string;
|
||||
size: string;
|
||||
link: string;
|
||||
category: Category;
|
||||
seeders: string;
|
||||
leechers: string;
|
||||
uploadDate: Date;
|
||||
magnetLink: string;
|
||||
subcategory: Category;
|
||||
uploader: string;
|
||||
verified: boolean;
|
||||
uploaderLink: string;
|
||||
}
|
||||
|
||||
interface Torrent {
|
||||
id: string;
|
||||
title: string;
|
||||
@@ -136,27 +121,6 @@ interface Torrent {
|
||||
magnet: string;
|
||||
}
|
||||
|
||||
interface Category {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface Poster {
|
||||
aspect_ratio: number;
|
||||
height: number;
|
||||
iso_639_1: null;
|
||||
file_path: string;
|
||||
vote_average: number;
|
||||
vote_count: number;
|
||||
width: number;
|
||||
}
|
||||
|
||||
interface Filters {
|
||||
genres: Array<string>;
|
||||
year: Array<string>;
|
||||
score: Array<string>;
|
||||
}
|
||||
|
||||
interface ExternalIDS {
|
||||
id: number;
|
||||
imdb_id: string;
|
||||
|
||||
Reference in new issue
Block a user