feat: Initialize project
This commit is contained in:
1 parent
eccc32337f
commit
3c1050898e
65 files changed
+5661
-596
No files matched your search
+56
-1
@@ -1,3 +1,58 @@
|
||||
{
|
||||
"extends": "next/core-web-vitals"
|
||||
"extends": "next/core-web-vitals",
|
||||
"plugins": [
|
||||
"simple-import-sort"
|
||||
],
|
||||
"rules": {
|
||||
"simple-import-sort/imports": "error",
|
||||
"simple-import-sort/exports": "error",
|
||||
"quotes": ["error", "single"]
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"files": [
|
||||
"*.js",
|
||||
"*.jsx",
|
||||
"*.ts",
|
||||
"*.tsx"
|
||||
],
|
||||
"rules": {
|
||||
"simple-import-sort/imports": [
|
||||
"error",
|
||||
{
|
||||
"groups": [
|
||||
// Packages `react` related packages come first.
|
||||
[
|
||||
"^react",
|
||||
"^@?\\w"
|
||||
],
|
||||
// Internal packages.
|
||||
[
|
||||
"^(@|components)(/.*|$)"
|
||||
],
|
||||
// Side effect imports.
|
||||
[
|
||||
"^\\u0000"
|
||||
],
|
||||
// Parent imports. Put `..` last.
|
||||
[
|
||||
"^\\.\\.(?!/?$)",
|
||||
"^\\.\\./?$"
|
||||
],
|
||||
// Other relative imports. Put same-folder imports and `.` last.
|
||||
[
|
||||
"^\\./(?=.*/)(?!/?$)",
|
||||
"^\\.(?!/?$)",
|
||||
"^\\./?$"
|
||||
],
|
||||
// Style imports.
|
||||
[
|
||||
"^.+\\.?(css)$"
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.idea/
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"singleQuote": true,
|
||||
"jsxSingleQuote": true,
|
||||
"semi": true,
|
||||
"tabWidth": 2,
|
||||
"bracketSpacing": true,
|
||||
"jsxBracketSameLine": false,
|
||||
"arrowParens": "always",
|
||||
"trailingComma": "none",
|
||||
"printWidth": 120,
|
||||
"importOrder": ["^@/(.*)$", "^[./]"],
|
||||
"importOrderSeparation": true,
|
||||
"importOrderSortSpecifiers": true
|
||||
}
|
||||
@@ -1,34 +1,3 @@
|
||||
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
|
||||
This is [Movie advisor](https://nextjs.org/), project which can help you find movie for your lonely evening.
|
||||
|
||||
## Getting Started
|
||||
|
||||
First, run the development server:
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
# or
|
||||
yarn dev
|
||||
# or
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
||||
|
||||
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
|
||||
|
||||
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
|
||||
|
||||
## Learn More
|
||||
|
||||
To learn more about Next.js, take a look at the following resources:
|
||||
|
||||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
||||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
||||
|
||||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
|
||||
|
||||
## Deploy on Vercel
|
||||
|
||||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
|
||||
|
||||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
|
||||
Powered by [NextJS](https://nextjs.org/), [TMDB](https://developer.themoviedb.org/docs) and a little bit [OpenAI](https://openai.com/blog/openai-api)
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Filters } from '@/app/(site)/useFilters';
|
||||
import client from '@/network';
|
||||
|
||||
const API = {
|
||||
genres(): Promise<IDName[]> {
|
||||
return client.get('/genres');
|
||||
},
|
||||
credits({ movieId }: { movieId: Movie['id'] }): Promise<Actor[]> {
|
||||
return client.get('/credits', {
|
||||
params: {
|
||||
movieId
|
||||
}
|
||||
});
|
||||
},
|
||||
random({ filters }: { filters: Partial<Filters> }): Promise<Movie[]> {
|
||||
return client.get('/random', {
|
||||
params: {
|
||||
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]
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default API;
|
||||
@@ -0,0 +1,84 @@
|
||||
'use client';
|
||||
|
||||
import { Dispatch, SetStateAction, useRef, useState } from 'react';
|
||||
|
||||
import useFilters, { Filters } from '@/app/(site)/useFilters';
|
||||
import { Card } from '@/components/ui/card';
|
||||
import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area';
|
||||
import { Slider } from '@/components/ui/slider';
|
||||
import { Toggle } from '@/components/ui/toggle';
|
||||
|
||||
import useGenres from './useGenres';
|
||||
|
||||
export default function Filter() {
|
||||
const { filters, setFilters } = useFilters();
|
||||
const { data: genres } = 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()));
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<ScrollArea className='mb-2'>
|
||||
<Card>
|
||||
<ul className='flex gap-2'>
|
||||
{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>
|
||||
<ScrollBar orientation='horizontal' className='opacity-0' />
|
||||
</ScrollArea>
|
||||
<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>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
'use client';
|
||||
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import API from '@/app/(site)/api';
|
||||
const useGenres = () => {
|
||||
return useQuery({
|
||||
suspense: true,
|
||||
queryKey: ['genres'],
|
||||
queryFn: API.genres
|
||||
});
|
||||
};
|
||||
|
||||
export default useGenres;
|
||||
@@ -0,0 +1,21 @@
|
||||
'use client';
|
||||
|
||||
import { RefreshCcwDot } from 'lucide-react';
|
||||
|
||||
import Movie from '@/components/Movie/Preview';
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
import useRandomMovie from './useRandomMovie';
|
||||
|
||||
export default function Container() {
|
||||
const { movie, next } = useRandomMovie();
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button className='w-full mb-2 p-2' onClick={next} title='Next movie'>
|
||||
<RefreshCcwDot size={24} strokeWidth={1} />
|
||||
</Button>
|
||||
<Movie movie={movie} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Loader } from 'lucide-react';
|
||||
export default function Loading() {
|
||||
return (
|
||||
<div className='w-full min-h-[70vh] flex items-center justify-center'>
|
||||
<div className='animate-spin'>
|
||||
<Loader />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import Filter from './components/Filter';
|
||||
import Container from './container';
|
||||
|
||||
export default async function Random() {
|
||||
return (
|
||||
<>
|
||||
<Filter />
|
||||
<Container />
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import client from '@/network';
|
||||
|
||||
const API = {
|
||||
search: {
|
||||
byTitle({ query, page }: { query: string; page: number }): Promise<MovieDBResponse> {
|
||||
return client.get('/search', {
|
||||
params: {
|
||||
query,
|
||||
page
|
||||
}
|
||||
});
|
||||
},
|
||||
byDescription({ description }: { description: string }): Promise<Array<Movie>> {
|
||||
return client.get('/search/description', {
|
||||
params: {
|
||||
description
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default API;
|
||||
@@ -0,0 +1,87 @@
|
||||
'use client';
|
||||
import { ChangeEvent, FormEvent, useRef, useState } from 'react';
|
||||
import { Loader, Search } from 'lucide-react';
|
||||
|
||||
import List from '@/components/Movie/List';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
|
||||
import useSearch from './useSearch';
|
||||
import useSuggestions from './useSuggestions';
|
||||
|
||||
export default function Container() {
|
||||
const [title, setTitle] = useState('');
|
||||
const [query, setQuery] = useState('');
|
||||
const [description, setDescription] = useState('');
|
||||
const timeout = useRef<NodeJS.Timeout>();
|
||||
|
||||
const titleRef = useRef<HTMLInputElement>(null);
|
||||
const descriptionRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
const handleChangeTitle = ({ target: { value } }: ChangeEvent<HTMLInputElement>) => {
|
||||
setTitle(value);
|
||||
|
||||
clearTimeout(timeout.current);
|
||||
timeout.current = setTimeout(() => setQuery(value.trim()), 300);
|
||||
};
|
||||
|
||||
const { data: results, hasNextPage, fetchNextPage } = useSearch({ query });
|
||||
|
||||
const { data: suggestions, isLoading } = useSuggestions({ description });
|
||||
|
||||
const handleSearchByDescription = (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
setDescription(descriptionRef.current?.value || '');
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Tabs defaultValue='title' className='mb-2'>
|
||||
<TabsList className='grid w-full grid-cols-2'>
|
||||
<TabsTrigger
|
||||
value='title'
|
||||
onClick={() => {
|
||||
setDescription('');
|
||||
titleRef.current?.focus();
|
||||
}}
|
||||
>
|
||||
by title
|
||||
</TabsTrigger>
|
||||
<TabsTrigger
|
||||
value='description'
|
||||
onClick={() => {
|
||||
setTitle('');
|
||||
setQuery('');
|
||||
descriptionRef.current?.focus();
|
||||
}}
|
||||
>
|
||||
by description
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
<TabsContent value='title'>
|
||||
<Input
|
||||
ref={titleRef}
|
||||
autoFocus
|
||||
placeholder='Start entering title...'
|
||||
value={title}
|
||||
onChange={handleChangeTitle}
|
||||
/>
|
||||
</TabsContent>
|
||||
<TabsContent value='description'>
|
||||
<form onSubmit={handleSearchByDescription} className='flex items-stretch gap-2'>
|
||||
<Input ref={descriptionRef} placeholder='Describe movie which you want to watch...' name='description' />
|
||||
<Button type='submit' className='h-auto pe-3 ps-3' disabled={isLoading} title='Search'>
|
||||
{isLoading ? <Loader className='animate-spin' /> : <Search />}
|
||||
</Button>
|
||||
</form>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
<List
|
||||
pages={results?.pages || suggestions?.pages || []}
|
||||
fetchNextPage={fetchNextPage}
|
||||
hasNextPage={hasNextPage}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import Container from './container';
|
||||
|
||||
export default function Search() {
|
||||
return <Container />;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { useInfiniteQuery, useQuery } from '@tanstack/react-query';
|
||||
|
||||
import API from './api';
|
||||
|
||||
const useSearch = ({ query }: { query: string }) => {
|
||||
return useInfiniteQuery({
|
||||
queryKey: ['search', query],
|
||||
queryFn: ({ pageParam: page }) => API.search.byTitle({ query, page }),
|
||||
enabled: Boolean(query),
|
||||
defaultPageParam: 1,
|
||||
getNextPageParam({ page, total_pages }) {
|
||||
if (page === total_pages) return undefined;
|
||||
|
||||
return page + 1;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export default useSearch;
|
||||
@@ -0,0 +1,20 @@
|
||||
import { useInfiniteQuery } from '@tanstack/react-query';
|
||||
|
||||
import API from '@/app/(site)/search/api';
|
||||
|
||||
const useSuggestions = ({ description }: { description: string }) => {
|
||||
return useInfiniteQuery({
|
||||
enabled: Boolean(description),
|
||||
queryKey: ['suggestions', description],
|
||||
queryFn: () =>
|
||||
API.search.byDescription({ description }).then((movies) => {
|
||||
return { page: 1, results: movies, total_pages: 1, total_results: movies.length } as MovieDBResponse;
|
||||
}),
|
||||
defaultPageParam: 1,
|
||||
getNextPageParam() {
|
||||
return undefined;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export default useSuggestions;
|
||||
@@ -0,0 +1,17 @@
|
||||
import client from '@/network';
|
||||
|
||||
const API = {
|
||||
top({ page }: { page: string }): Promise<MovieDBResponse> {
|
||||
return client.get('/discover', {
|
||||
params: {
|
||||
page,
|
||||
sort_by: 'vote_average.desc',
|
||||
'vote_count.gte': 300,
|
||||
'vote_average.lte': 10,
|
||||
'vote_average.gte': 0
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default API;
|
||||
@@ -0,0 +1,11 @@
|
||||
'use client';
|
||||
|
||||
import List from '@/components/Movie/List';
|
||||
|
||||
import useTop from './useTop';
|
||||
|
||||
export default function Container() {
|
||||
const { data: top, hasNextPage, fetchNextPage } = useTop();
|
||||
|
||||
return <List pages={top?.pages || []} fetchNextPage={fetchNextPage} hasNextPage={hasNextPage} />;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import Container from './container';
|
||||
|
||||
export default function Top() {
|
||||
return <Container />;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
'use client';
|
||||
|
||||
import { useInfiniteQuery } from '@tanstack/react-query';
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
|
||||
import API from './api';
|
||||
|
||||
const useTop = () => {
|
||||
const page = useSearchParams().get('page');
|
||||
|
||||
return useInfiniteQuery({
|
||||
queryKey: ['top'],
|
||||
queryFn: ({ pageParam: page }) => API.top({ page }),
|
||||
suspense: true,
|
||||
getNextPageParam({ page, total_pages }) {
|
||||
if (page === total_pages) return undefined;
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
const url = new URL(location.href);
|
||||
|
||||
url.searchParams.set('page', page.toString());
|
||||
|
||||
window.history.pushState(null, '', url.href);
|
||||
}
|
||||
|
||||
return `${page + 1}`;
|
||||
},
|
||||
defaultPageParam: page || '1'
|
||||
});
|
||||
};
|
||||
|
||||
export default useTop;
|
||||
@@ -0,0 +1,13 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import API from './api';
|
||||
|
||||
const useCredits = ({ movieId }: { movieId?: Movie['id'] }) => {
|
||||
return useQuery({
|
||||
queryKey: ['credits', movieId],
|
||||
queryFn: () => API.credits({ movieId: movieId! }),
|
||||
enabled: Boolean(movieId)
|
||||
});
|
||||
};
|
||||
|
||||
export default useCredits;
|
||||
@@ -0,0 +1,35 @@
|
||||
import { useMemo } from 'react';
|
||||
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
||||
|
||||
export interface Filters {
|
||||
genres: Array<string>;
|
||||
year: Array<string>;
|
||||
score: Array<string>;
|
||||
}
|
||||
|
||||
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(() => {
|
||||
return Object.entries(filters).reduce((filters, [key, value]) => {
|
||||
filters[key as keyof Filters] = value.split(',');
|
||||
return filters;
|
||||
}, {} as Partial<Filters>);
|
||||
}, [filters]),
|
||||
setFilters
|
||||
};
|
||||
};
|
||||
|
||||
export default useFilters;
|
||||
@@ -0,0 +1,58 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import useFilters from '@/app/(site)/useFilters';
|
||||
|
||||
import API from './api';
|
||||
|
||||
const UPDATE_RATE = 10;
|
||||
|
||||
const previousIndexes: Record<string, number> = {};
|
||||
|
||||
const useRandomMovie = () => {
|
||||
const { filters } = useFilters();
|
||||
const indexByFilter = previousIndexes[JSON.stringify(filters)];
|
||||
const [index, setIndex] = useState(indexByFilter || 0);
|
||||
|
||||
const { data: movies, refetch } = useQuery({
|
||||
queryKey: ['random-movie', filters],
|
||||
queryFn: () => API.random({ filters }),
|
||||
suspense: true,
|
||||
structuralSharing(current, next) {
|
||||
const uniqueIds: Record<string, number> = {};
|
||||
|
||||
return (current || []).concat(next).reduce((unique, movie) => {
|
||||
if (uniqueIds[movie.id]) return unique;
|
||||
|
||||
uniqueIds[movie.id] = movie.id;
|
||||
unique.push(movie);
|
||||
|
||||
return unique;
|
||||
}, [] as Movie[]);
|
||||
}
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
setIndex(indexByFilter || 0);
|
||||
}, [indexByFilter]);
|
||||
|
||||
const next = () => {
|
||||
if ((index && index % UPDATE_RATE === 0) || movies!.length < UPDATE_RATE) {
|
||||
refetch();
|
||||
}
|
||||
|
||||
const nextIndex = index + 1;
|
||||
|
||||
previousIndexes[JSON.stringify(filters)] = nextIndex;
|
||||
setIndex(nextIndex);
|
||||
};
|
||||
|
||||
return {
|
||||
movie: movies?.[index],
|
||||
next
|
||||
};
|
||||
};
|
||||
|
||||
export default useRandomMovie;
|
||||
@@ -0,0 +1,12 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
import server from '@/network/server';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const params = Object.fromEntries(new URL(request.url).searchParams.entries());
|
||||
const response: { cast: Array<Actor> } = await server.get(`/movie/${params.movieId}/credits`);
|
||||
|
||||
return NextResponse.json(response?.cast || []);
|
||||
}
|
||||
|
||||
export const revalidate = 3600;
|
||||
@@ -0,0 +1,14 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
import server from '@/network/server';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const params = Object.fromEntries(new URL(request.url).searchParams.entries());
|
||||
const response = await server.get('/discover/movie', {
|
||||
params
|
||||
});
|
||||
|
||||
return NextResponse.json(response);
|
||||
}
|
||||
|
||||
export const revalidate = 0;
|
||||
@@ -0,0 +1,11 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
import server from '@/network/server';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const response: { genres: IDName[] } = await server.get('/genre/movie/list');
|
||||
|
||||
return NextResponse.json(response.genres);
|
||||
}
|
||||
|
||||
export const revalidate = 3600 * 24;
|
||||
@@ -0,0 +1,31 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
import server from '@/network/server';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const params = Object.fromEntries(new URL(request.url).searchParams.entries());
|
||||
const fetch = (): Promise<Movie[]> => {
|
||||
return server
|
||||
.get('/discover/movie', {
|
||||
params: {
|
||||
sort_by: 'popularity.desc',
|
||||
page: Math.floor(Math.random() * 1000) + 1,
|
||||
...params
|
||||
}
|
||||
})
|
||||
.then((data: unknown) => {
|
||||
const response: MovieDBResponse = data as MovieDBResponse;
|
||||
|
||||
if (!response?.results || !response?.results.length) {
|
||||
return fetch();
|
||||
}
|
||||
|
||||
return response.results;
|
||||
})
|
||||
.catch(fetch) as Promise<Movie[]>;
|
||||
};
|
||||
|
||||
return NextResponse.json(await fetch());
|
||||
}
|
||||
|
||||
export const revalidate = 0;
|
||||
@@ -0,0 +1,54 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { Configuration, OpenAIApi } from 'openai';
|
||||
|
||||
import server from '@/network/server';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const params = Object.fromEntries(new URL(request.url).searchParams.entries());
|
||||
|
||||
const openai = new OpenAIApi(new Configuration({ apiKey: process.env.CHAT_GPT_KEY }));
|
||||
|
||||
try {
|
||||
const completion = await openai.createCompletion({
|
||||
model: 'text-davinci-003',
|
||||
prompt: `Based on the movie description: ${params.description}, suggest 5 movies. Format of suggestions: only title separated by comma`,
|
||||
max_tokens: 70,
|
||||
temperature: 0.4,
|
||||
stop: ['Based on the movie description:']
|
||||
});
|
||||
|
||||
const suggestedMovies = (completion.data.choices[0].text?.split(',') || []).map((movie) =>
|
||||
movie.replace(/^\s*\d+\.\s*/, '')
|
||||
);
|
||||
|
||||
if (!suggestedMovies.length) return NextResponse.json([]);
|
||||
|
||||
const movies = await Promise.allSettled(
|
||||
suggestedMovies.map((movie) =>
|
||||
server
|
||||
.get('/search/movie', {
|
||||
params: {
|
||||
query: movie
|
||||
}
|
||||
})
|
||||
.then((response: unknown) => {
|
||||
const data = response as MovieDBResponse;
|
||||
|
||||
return (data?.results || []).slice(0, 1);
|
||||
})
|
||||
)
|
||||
).then((results) => {
|
||||
return results.reduce((movies, result) => {
|
||||
if (result.status !== 'fulfilled') return movies;
|
||||
|
||||
movies.push(...result.value);
|
||||
|
||||
return movies;
|
||||
}, [] as Movie[]);
|
||||
});
|
||||
|
||||
return NextResponse.json(movies);
|
||||
} catch (error) {
|
||||
return NextResponse.json([]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
import server from '@/network/server';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const params = Object.fromEntries(new URL(request.url).searchParams.entries());
|
||||
const response = await server.get('/search/movie', {
|
||||
params
|
||||
});
|
||||
|
||||
return NextResponse.json(response);
|
||||
}
|
||||
-107
@@ -1,107 +0,0 @@
|
||||
:root {
|
||||
--max-width: 1100px;
|
||||
--border-radius: 12px;
|
||||
--font-mono: ui-monospace, Menlo, Monaco, 'Cascadia Mono', 'Segoe UI Mono',
|
||||
'Roboto Mono', 'Oxygen Mono', 'Ubuntu Monospace', 'Source Code Pro',
|
||||
'Fira Mono', 'Droid Sans Mono', 'Courier New', monospace;
|
||||
|
||||
--foreground-rgb: 0, 0, 0;
|
||||
--background-start-rgb: 214, 219, 220;
|
||||
--background-end-rgb: 255, 255, 255;
|
||||
|
||||
--primary-glow: conic-gradient(
|
||||
from 180deg at 50% 50%,
|
||||
#16abff33 0deg,
|
||||
#0885ff33 55deg,
|
||||
#54d6ff33 120deg,
|
||||
#0071ff33 160deg,
|
||||
transparent 360deg
|
||||
);
|
||||
--secondary-glow: radial-gradient(
|
||||
rgba(255, 255, 255, 1),
|
||||
rgba(255, 255, 255, 0)
|
||||
);
|
||||
|
||||
--tile-start-rgb: 239, 245, 249;
|
||||
--tile-end-rgb: 228, 232, 233;
|
||||
--tile-border: conic-gradient(
|
||||
#00000080,
|
||||
#00000040,
|
||||
#00000030,
|
||||
#00000020,
|
||||
#00000010,
|
||||
#00000010,
|
||||
#00000080
|
||||
);
|
||||
|
||||
--callout-rgb: 238, 240, 241;
|
||||
--callout-border-rgb: 172, 175, 176;
|
||||
--card-rgb: 180, 185, 188;
|
||||
--card-border-rgb: 131, 134, 135;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--foreground-rgb: 255, 255, 255;
|
||||
--background-start-rgb: 0, 0, 0;
|
||||
--background-end-rgb: 0, 0, 0;
|
||||
|
||||
--primary-glow: radial-gradient(rgba(1, 65, 255, 0.4), rgba(1, 65, 255, 0));
|
||||
--secondary-glow: linear-gradient(
|
||||
to bottom right,
|
||||
rgba(1, 65, 255, 0),
|
||||
rgba(1, 65, 255, 0),
|
||||
rgba(1, 65, 255, 0.3)
|
||||
);
|
||||
|
||||
--tile-start-rgb: 2, 13, 46;
|
||||
--tile-end-rgb: 2, 5, 19;
|
||||
--tile-border: conic-gradient(
|
||||
#ffffff80,
|
||||
#ffffff40,
|
||||
#ffffff30,
|
||||
#ffffff20,
|
||||
#ffffff10,
|
||||
#ffffff10,
|
||||
#ffffff80
|
||||
);
|
||||
|
||||
--callout-rgb: 20, 20, 20;
|
||||
--callout-border-rgb: 108, 108, 108;
|
||||
--card-rgb: 100, 100, 100;
|
||||
--card-border-rgb: 200, 200, 200;
|
||||
}
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
html,
|
||||
body {
|
||||
max-width: 100vw;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
body {
|
||||
color: rgb(var(--foreground-rgb));
|
||||
background: linear-gradient(
|
||||
to bottom,
|
||||
transparent,
|
||||
rgb(var(--background-end-rgb))
|
||||
)
|
||||
rgb(var(--background-start-rgb));
|
||||
}
|
||||
|
||||
a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
html {
|
||||
color-scheme: dark;
|
||||
}
|
||||
}
|
||||
+21
-15
@@ -1,22 +1,28 @@
|
||||
import './globals.css'
|
||||
import type { Metadata } from 'next'
|
||||
import { Inter } from 'next/font/google'
|
||||
import React, { ReactNode } from 'react';
|
||||
import type { Metadata } from 'next';
|
||||
import { cookies } from 'next/headers';
|
||||
|
||||
const inter = Inter({ subsets: ['latin'] })
|
||||
import Header from '@/components/Header';
|
||||
import Providers from '@/providers';
|
||||
|
||||
import '@/styles/index.css';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: 'Create Next App',
|
||||
description: 'Generated by create next app',
|
||||
}
|
||||
title: 'Movie advisor',
|
||||
description: 'It will help you find a movie for evening'
|
||||
};
|
||||
|
||||
export default function RootLayout({ children }: { children: ReactNode }) {
|
||||
const theme = cookies().get('theme')?.value as Theme;
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<body className={inter.className}>{children}</body>
|
||||
<html lang='en' className={theme}>
|
||||
<body>
|
||||
<Providers theme={theme}>
|
||||
<Header />
|
||||
<main>{children}</main>
|
||||
</Providers>
|
||||
</body>
|
||||
</html>
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -1,229 +0,0 @@
|
||||
.main {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 6rem;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.description {
|
||||
display: inherit;
|
||||
justify-content: inherit;
|
||||
align-items: inherit;
|
||||
font-size: 0.85rem;
|
||||
max-width: var(--max-width);
|
||||
width: 100%;
|
||||
z-index: 2;
|
||||
font-family: var(--font-mono);
|
||||
}
|
||||
|
||||
.description a {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.description p {
|
||||
position: relative;
|
||||
margin: 0;
|
||||
padding: 1rem;
|
||||
background-color: rgba(var(--callout-rgb), 0.5);
|
||||
border: 1px solid rgba(var(--callout-border-rgb), 0.3);
|
||||
border-radius: var(--border-radius);
|
||||
}
|
||||
|
||||
.code {
|
||||
font-weight: 700;
|
||||
font-family: var(--font-mono);
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, minmax(25%, auto));
|
||||
width: var(--max-width);
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 1rem 1.2rem;
|
||||
border-radius: var(--border-radius);
|
||||
background: rgba(var(--card-rgb), 0);
|
||||
border: 1px solid rgba(var(--card-border-rgb), 0);
|
||||
transition: background 200ms, border 200ms;
|
||||
}
|
||||
|
||||
.card span {
|
||||
display: inline-block;
|
||||
transition: transform 200ms;
|
||||
}
|
||||
|
||||
.card h2 {
|
||||
font-weight: 600;
|
||||
margin-bottom: 0.7rem;
|
||||
}
|
||||
|
||||
.card p {
|
||||
margin: 0;
|
||||
opacity: 0.6;
|
||||
font-size: 0.9rem;
|
||||
line-height: 1.5;
|
||||
max-width: 30ch;
|
||||
}
|
||||
|
||||
.center {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
position: relative;
|
||||
padding: 4rem 0;
|
||||
}
|
||||
|
||||
.center::before {
|
||||
background: var(--secondary-glow);
|
||||
border-radius: 50%;
|
||||
width: 480px;
|
||||
height: 360px;
|
||||
margin-left: -400px;
|
||||
}
|
||||
|
||||
.center::after {
|
||||
background: var(--primary-glow);
|
||||
width: 240px;
|
||||
height: 180px;
|
||||
z-index: -1;
|
||||
}
|
||||
|
||||
.center::before,
|
||||
.center::after {
|
||||
content: '';
|
||||
left: 50%;
|
||||
position: absolute;
|
||||
filter: blur(45px);
|
||||
transform: translateZ(0);
|
||||
}
|
||||
|
||||
.logo {
|
||||
position: relative;
|
||||
}
|
||||
/* Enable hover only on non-touch devices */
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
.card:hover {
|
||||
background: rgba(var(--card-rgb), 0.1);
|
||||
border: 1px solid rgba(var(--card-border-rgb), 0.15);
|
||||
}
|
||||
|
||||
.card:hover span {
|
||||
transform: translateX(4px);
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion) {
|
||||
.card:hover span {
|
||||
transform: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* Mobile */
|
||||
@media (max-width: 700px) {
|
||||
.content {
|
||||
padding: 4rem;
|
||||
}
|
||||
|
||||
.grid {
|
||||
grid-template-columns: 1fr;
|
||||
margin-bottom: 120px;
|
||||
max-width: 320px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 1rem 2.5rem;
|
||||
}
|
||||
|
||||
.card h2 {
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.center {
|
||||
padding: 8rem 0 6rem;
|
||||
}
|
||||
|
||||
.center::before {
|
||||
transform: none;
|
||||
height: 300px;
|
||||
}
|
||||
|
||||
.description {
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
.description a {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.description p,
|
||||
.description div {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
position: fixed;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.description p {
|
||||
align-items: center;
|
||||
inset: 0 0 auto;
|
||||
padding: 2rem 1rem 1.4rem;
|
||||
border-radius: 0;
|
||||
border: none;
|
||||
border-bottom: 1px solid rgba(var(--callout-border-rgb), 0.25);
|
||||
background: linear-gradient(
|
||||
to bottom,
|
||||
rgba(var(--background-start-rgb), 1),
|
||||
rgba(var(--callout-rgb), 0.5)
|
||||
);
|
||||
background-clip: padding-box;
|
||||
backdrop-filter: blur(24px);
|
||||
}
|
||||
|
||||
.description div {
|
||||
align-items: flex-end;
|
||||
pointer-events: none;
|
||||
inset: auto 0 0;
|
||||
padding: 2rem;
|
||||
height: 200px;
|
||||
background: linear-gradient(
|
||||
to bottom,
|
||||
transparent 0%,
|
||||
rgb(var(--background-end-rgb)) 40%
|
||||
);
|
||||
z-index: 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Tablet and Smaller Desktop */
|
||||
@media (min-width: 701px) and (max-width: 1120px) {
|
||||
.grid {
|
||||
grid-template-columns: repeat(2, 50%);
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.vercelLogo {
|
||||
filter: invert(1);
|
||||
}
|
||||
|
||||
.logo {
|
||||
filter: invert(1) drop-shadow(0 0 0.3rem #ffffff70);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes rotate {
|
||||
from {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
import Image from 'next/image'
|
||||
import styles from './page.module.css'
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<main className={styles.main}>
|
||||
<div className={styles.description}>
|
||||
<p>
|
||||
Get started by editing
|
||||
<code className={styles.code}>app/page.tsx</code>
|
||||
</p>
|
||||
<div>
|
||||
<a
|
||||
href="https://vercel.com?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
By{' '}
|
||||
<Image
|
||||
src="/vercel.svg"
|
||||
alt="Vercel Logo"
|
||||
className={styles.vercelLogo}
|
||||
width={100}
|
||||
height={24}
|
||||
priority
|
||||
/>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className={styles.center}>
|
||||
<Image
|
||||
className={styles.logo}
|
||||
src="/next.svg"
|
||||
alt="Next.js Logo"
|
||||
width={180}
|
||||
height={37}
|
||||
priority
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className={styles.grid}>
|
||||
<a
|
||||
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
|
||||
className={styles.card}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<h2>
|
||||
Docs <span>-></span>
|
||||
</h2>
|
||||
<p>Find in-depth information about Next.js features and API.</p>
|
||||
</a>
|
||||
|
||||
<a
|
||||
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
|
||||
className={styles.card}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<h2>
|
||||
Learn <span>-></span>
|
||||
</h2>
|
||||
<p>Learn about Next.js in an interactive course with quizzes!</p>
|
||||
</a>
|
||||
|
||||
<a
|
||||
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
|
||||
className={styles.card}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<h2>
|
||||
Templates <span>-></span>
|
||||
</h2>
|
||||
<p>Explore the Next.js 13 playground.</p>
|
||||
</a>
|
||||
|
||||
<a
|
||||
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
|
||||
className={styles.card}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<h2>
|
||||
Deploy <span>-></span>
|
||||
</h2>
|
||||
<p>
|
||||
Instantly deploy your Next.js site to a shareable URL with Vercel.
|
||||
</p>
|
||||
</a>
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"$schema": "https://ui.shadcn.com/schema.json",
|
||||
"style": "default",
|
||||
"rsc": true,
|
||||
"tsx": true,
|
||||
"tailwind": {
|
||||
"config": "tailwind.config.js",
|
||||
"css": "styles/index.css",
|
||||
"baseColor": "slate",
|
||||
"cssVariables": true
|
||||
},
|
||||
"aliases": {
|
||||
"components": "@/components",
|
||||
"utils": "@/lib/utils"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
'use client';
|
||||
|
||||
import { FC } from 'react';
|
||||
import { Moon, Sun } from 'lucide-react';
|
||||
import Link from 'next/link';
|
||||
import { usePathname } from 'next/navigation';
|
||||
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
import { useTheme } from '@/hooks/useTheme';
|
||||
|
||||
const Header: FC = () => {
|
||||
const path = usePathname();
|
||||
const [theme, setTheme] = useTheme();
|
||||
|
||||
return (
|
||||
<header className='bg-background sticky pt-[12px] pb-2 top-0 z-10'>
|
||||
<div className='flex items-center justify-between'>
|
||||
<Link href='/'>
|
||||
<Badge className='whitespace-nowrap'>Movie advisor</Badge>
|
||||
</Link>
|
||||
<Button variant='outline' size='icon' onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}>
|
||||
{theme === 'light' ? <Moon /> : <Sun />}
|
||||
</Button>
|
||||
</div>
|
||||
<Tabs value={path} className='flex-grow mt-2'>
|
||||
<TabsList className='grid w-full grid-cols-3'>
|
||||
{[
|
||||
['/', 'Random'],
|
||||
['/top', 'Top'],
|
||||
['/search', 'Search']
|
||||
].map(([path, label]) => (
|
||||
<Link href={path} className='w-full' key={path}>
|
||||
<TabsTrigger className='w-full' value={path}>
|
||||
{label}
|
||||
</TabsTrigger>
|
||||
</Link>
|
||||
))}
|
||||
</TabsList>
|
||||
</Tabs>
|
||||
</header>
|
||||
);
|
||||
};
|
||||
|
||||
export default Header;
|
||||
@@ -0,0 +1,38 @@
|
||||
import { FC } from 'react';
|
||||
import { Star } from 'lucide-react';
|
||||
|
||||
import Poster from '@/components/Movie/components/Poster';
|
||||
import Title from '@/components/Movie/components/Title';
|
||||
|
||||
interface Props {
|
||||
movie?: Movie;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const Card: FC<Props> = ({ movie, className }) => {
|
||||
if (!movie) return null;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`${className} p-4 rounded-lg border bg-card text-card-foreground shadow-sm transition-shadow hover:shadow-lg`}
|
||||
>
|
||||
<div>
|
||||
<div className='grid items-center grid-cols-[1fr_70px]'>
|
||||
<Title title={movie.title} />
|
||||
{movie.release_date && (
|
||||
<span className='flex justify-end text-lg font-semibold'>{new Date(movie.release_date).getFullYear()}</span>
|
||||
)}
|
||||
</div>
|
||||
<div className='flex w-full justify-between'>
|
||||
<Star />
|
||||
<span className='text-lg font-semibold'>{movie.vote_average}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className='flex justify-center relative'>
|
||||
<Poster title={movie.title} width={300} height={450} size={100} poster={movie.poster_path} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Card;
|
||||
@@ -0,0 +1,67 @@
|
||||
import { FC, Fragment, useLayoutEffect, useState } from 'react';
|
||||
import { InfiniteData, useInfiniteQuery, UseInfiniteQueryResult } from '@tanstack/react-query';
|
||||
|
||||
import Card from '@/components/Movie/Card';
|
||||
import Preview from '@/components/Movie/Preview';
|
||||
import { Dialog, DialogContent } from '@/components/ui/dialog';
|
||||
|
||||
interface Props {
|
||||
pages: Array<MovieDBResponse>;
|
||||
hasNextPage: boolean;
|
||||
fetchNextPage: () => void;
|
||||
}
|
||||
|
||||
const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage }) => {
|
||||
const [movie, setMovie] = useState<Movie | null>(null);
|
||||
const [loader, setLoader] = useState<HTMLLIElement>();
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (!loader || !hasNextPage) return;
|
||||
|
||||
const observer = new IntersectionObserver(
|
||||
([{ isIntersecting }]) => {
|
||||
if (!isIntersecting) return;
|
||||
|
||||
fetchNextPage();
|
||||
},
|
||||
{
|
||||
threshold: 1
|
||||
}
|
||||
);
|
||||
|
||||
observer.observe(loader);
|
||||
|
||||
return () => observer.disconnect();
|
||||
}, [fetchNextPage, loader, hasNextPage]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<ul className='flex gap-3 flex-wrap'>
|
||||
{pages.map((page) => (
|
||||
<Fragment key={page.page}>
|
||||
{page.results?.map((movie, index, array) => (
|
||||
<li
|
||||
key={movie.id}
|
||||
className='flex grow basis-[300px] cursor-pointer'
|
||||
onClick={() => setMovie(movie)}
|
||||
ref={array.length / 2 !== index ? undefined : (element) => setLoader(element!)}
|
||||
>
|
||||
<Card movie={movie} className='grow' />
|
||||
</li>
|
||||
))}
|
||||
</Fragment>
|
||||
))}
|
||||
</ul>
|
||||
<div className='h-4 w-full'></div>
|
||||
{movie && (
|
||||
<Dialog defaultOpen={true} onOpenChange={(isOpen) => !isOpen && setMovie(null)}>
|
||||
<DialogContent className='block p-0'>
|
||||
<Preview movie={movie} className='border-none' />
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default List;
|
||||
@@ -0,0 +1,75 @@
|
||||
import { FC } from 'react';
|
||||
import { Star, User2 } from 'lucide-react';
|
||||
import Image from 'next/image';
|
||||
|
||||
import useCredits from '@/app/(site)/useCredits';
|
||||
import Poster from '@/components/Movie/components/Poster';
|
||||
import Title from '@/components/Movie/components/Title';
|
||||
import { CardTitle } from '@/components/ui/card';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
|
||||
interface Props {
|
||||
movie?: Movie;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const Preview: FC<Props> = ({ movie, className }) => {
|
||||
const { data: credits } = useCredits({ movieId: movie?.id });
|
||||
if (!movie) return null;
|
||||
return (
|
||||
<div className={`p-3 rounded-lg border bg-card text-card-foreground shadow-sm ${className}`}>
|
||||
<div className='flex flex-col lg:flex-row max-w-[100%] gap-3 overflow-hidden'>
|
||||
<Poster title={movie.title} width={300} height={450} size={250} poster={movie.poster_path} />
|
||||
<div className='flex flex-col grow lg:max-w-[calc(100%-(300px+0.75rem))]'>
|
||||
<div className='flex'>
|
||||
<div className='flex flex-row w-full items-end justify-between text-lg font-semibold'>
|
||||
<span>
|
||||
<Title title={movie.title} /> {movie.release_date && `(${new Date(movie.release_date).getFullYear()})`}
|
||||
</span>
|
||||
<div className='flex items-center gap-2'>
|
||||
<Star />
|
||||
<span>{movie.vote_average}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Separator className='my-4' />
|
||||
<div className='flex flex-col items-start grow justify-between'>
|
||||
<p className='leading-7'>{movie.overview}</p>
|
||||
{Boolean(credits?.length) && (
|
||||
<div className='overflow-auto max-w-[100%] mt-4'>
|
||||
<ul className='flex gap-2'>
|
||||
{credits?.map((actor) => (
|
||||
<li
|
||||
key={`${actor.id}_${actor.cast_id}`}
|
||||
title={actor.name}
|
||||
className='p-2 rounded-lg border bg-card text-card-foreground shadow-sm self-end max-w-[150px] w-full shrink-0'
|
||||
>
|
||||
<div className='rounded-lg overflow-hidden'>
|
||||
{actor.profile_path ? (
|
||||
<Image
|
||||
unoptimized
|
||||
height={225}
|
||||
width={150}
|
||||
src={`https://image.tmdb.org/t/p/w500/${actor.profile_path}`}
|
||||
alt={actor.name}
|
||||
/>
|
||||
) : (
|
||||
<div className='w-[132px] h-[198px] flex items-center justify-center rounded-lg border'>
|
||||
<User2 size={120} strokeWidth={1} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<p className='pt-2 overflow-ellipsis whitespace-nowrap overflow-hidden'>{actor.name}</p>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Preview;
|
||||
@@ -0,0 +1,34 @@
|
||||
import { FC } from 'react';
|
||||
import { ImageOff } from 'lucide-react';
|
||||
import Image from 'next/image';
|
||||
|
||||
interface Props {
|
||||
title: string;
|
||||
poster: string;
|
||||
width: number;
|
||||
height: number;
|
||||
size: number;
|
||||
}
|
||||
|
||||
const Poster: FC<Props> = ({ title, poster, width, height, size = 250 }) => {
|
||||
return (
|
||||
<div className='max-w-[300px] h-[450px] w-full rounded-lg overflow-hidden shrink-0 relative m-auto lg:m-0'>
|
||||
{poster ? (
|
||||
<Image
|
||||
className='rounded-lg '
|
||||
unoptimized
|
||||
height={height}
|
||||
width={width}
|
||||
src={`https://image.tmdb.org/t/p/w500/${poster}`}
|
||||
alt={title}
|
||||
/>
|
||||
) : (
|
||||
<div className={`w-[${width}px] h-[${height}px] flex items-center justify-center rounded-lg border`}>
|
||||
<ImageOff size={size} strokeWidth={1} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Poster;
|
||||
@@ -0,0 +1,35 @@
|
||||
import { FC, useState } from 'react';
|
||||
import Marquee from 'react-fast-marquee';
|
||||
|
||||
import { useTheme } from '@/hooks/useTheme';
|
||||
|
||||
interface Props {
|
||||
title: string;
|
||||
}
|
||||
|
||||
const Title: FC<Props> = ({ title }) => {
|
||||
const [isScrollableTitle, setIsScrollableTitle] = useState(false);
|
||||
const [theme] = useTheme();
|
||||
return (
|
||||
<Marquee
|
||||
play={isScrollableTitle}
|
||||
gradient={isScrollableTitle}
|
||||
gradientWidth={10}
|
||||
gradientColor={theme === 'light' ? [255, 255, 255] : [2, 8, 23]}
|
||||
className='movie-title overflow-hidden h-[30px] text-lg font-semibold'
|
||||
>
|
||||
<div
|
||||
ref={(element) => {
|
||||
const header = element?.closest('.movie-title') as HTMLDivElement;
|
||||
const isScrollableTitle = (header?.offsetWidth || 0) < (element?.offsetWidth || 0);
|
||||
|
||||
isScrollableTitle && setIsScrollableTitle(isScrollableTitle);
|
||||
}}
|
||||
>
|
||||
{title}
|
||||
</div>
|
||||
</Marquee>
|
||||
);
|
||||
};
|
||||
|
||||
export default Title;
|
||||
@@ -0,0 +1,7 @@
|
||||
import { FC } from 'react';
|
||||
|
||||
const Search: FC = () => {
|
||||
return <div>Search</div>;
|
||||
};
|
||||
|
||||
export default Search;
|
||||
@@ -0,0 +1,36 @@
|
||||
import * as React from 'react'
|
||||
import { cva, type VariantProps } from 'class-variance-authority'
|
||||
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
const badgeVariants = cva(
|
||||
'inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2',
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default:
|
||||
'border-transparent bg-primary text-primary-foreground hover:bg-primary/80',
|
||||
secondary:
|
||||
'border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80',
|
||||
destructive:
|
||||
'border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80',
|
||||
outline: 'text-foreground',
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: 'default',
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
export interface BadgeProps
|
||||
extends React.HTMLAttributes<HTMLDivElement>,
|
||||
VariantProps<typeof badgeVariants> {}
|
||||
|
||||
function Badge({ className, variant, ...props }: BadgeProps) {
|
||||
return (
|
||||
<div className={cn(badgeVariants({ variant }), className)} {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
export { Badge, badgeVariants }
|
||||
@@ -0,0 +1,56 @@
|
||||
import * as React from 'react'
|
||||
import { Slot } from '@radix-ui/react-slot'
|
||||
import { cva, type VariantProps } from 'class-variance-authority'
|
||||
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
const buttonVariants = cva(
|
||||
'inline-flex items-center justify-center rounded-md text-sm font-medium 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',
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: 'bg-primary text-primary-foreground hover:bg-primary/90',
|
||||
destructive:
|
||||
'bg-destructive text-destructive-foreground hover:bg-destructive/90',
|
||||
outline:
|
||||
'border border-input bg-background hover:bg-accent hover:text-accent-foreground',
|
||||
secondary:
|
||||
'bg-secondary text-secondary-foreground hover:bg-secondary/80',
|
||||
ghost: 'hover:bg-accent hover:text-accent-foreground',
|
||||
link: 'text-primary underline-offset-4 hover:underline',
|
||||
},
|
||||
size: {
|
||||
default: 'h-10 px-4 py-2',
|
||||
sm: 'h-9 rounded-md px-3',
|
||||
lg: 'h-11 rounded-md px-8',
|
||||
icon: 'h-10 w-10',
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: 'default',
|
||||
size: 'default',
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
export interface ButtonProps
|
||||
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
||||
VariantProps<typeof buttonVariants> {
|
||||
asChild?: boolean
|
||||
}
|
||||
|
||||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
({ className, variant, size, asChild = false, ...props }, ref) => {
|
||||
const Comp = asChild ? Slot : 'button'
|
||||
return (
|
||||
<Comp
|
||||
className={cn(buttonVariants({ variant, size, className }))}
|
||||
ref={ref}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
)
|
||||
Button.displayName = 'Button'
|
||||
|
||||
export { Button, buttonVariants }
|
||||
@@ -0,0 +1,79 @@
|
||||
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 }
|
||||
@@ -0,0 +1,89 @@
|
||||
'use client';
|
||||
|
||||
import * as React from 'react';
|
||||
import * as DialogPrimitive from '@radix-ui/react-dialog';
|
||||
import { X } from 'lucide-react';
|
||||
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
const Dialog = DialogPrimitive.Root;
|
||||
|
||||
const DialogTrigger = DialogPrimitive.Trigger;
|
||||
|
||||
const DialogPortal = ({ className, ...props }: DialogPrimitive.DialogPortalProps) => (
|
||||
<DialogPrimitive.Portal className={cn(className)} {...props} />
|
||||
);
|
||||
DialogPortal.displayName = DialogPrimitive.Portal.displayName;
|
||||
|
||||
const DialogOverlay = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Overlay>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DialogPrimitive.Overlay
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'fixed inset-0 z-50 bg-background/80 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
|
||||
|
||||
const DialogContent = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<DialogPortal>
|
||||
<DialogOverlay className='overflow-auto'>
|
||||
<DialogPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'absolute left-[50%] translate-x-[-50%] top-[20vh] max-w-[1000px] w-[calc(100%-24px)] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 rounded-lg',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<DialogPrimitive.Close className='absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground'>
|
||||
<X className='h-4 w-4' />
|
||||
<span className='sr-only'>Close</span>
|
||||
</DialogPrimitive.Close>
|
||||
<DialogPrimitive.Close className='absolute w-full block h-[20vh]' />
|
||||
</DialogPrimitive.Content>
|
||||
</DialogOverlay>
|
||||
</DialogPortal>
|
||||
));
|
||||
DialogContent.displayName = DialogPrimitive.Content.displayName;
|
||||
|
||||
const DialogHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div className={cn('flex flex-col space-y-1.5 text-center sm:text-left', className)} {...props} />
|
||||
);
|
||||
DialogHeader.displayName = 'DialogHeader';
|
||||
|
||||
const DialogFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div className={cn('flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2', className)} {...props} />
|
||||
);
|
||||
DialogFooter.displayName = 'DialogFooter';
|
||||
|
||||
const DialogTitle = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Title>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DialogPrimitive.Title
|
||||
ref={ref}
|
||||
className={cn('text-lg font-semibold leading-none tracking-tight', className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
DialogTitle.displayName = DialogPrimitive.Title.displayName;
|
||||
|
||||
const DialogDescription = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Description>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DialogPrimitive.Description ref={ref} className={cn('text-sm text-muted-foreground', className)} {...props} />
|
||||
));
|
||||
DialogDescription.displayName = DialogPrimitive.Description.displayName;
|
||||
|
||||
export { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger };
|
||||
@@ -0,0 +1,25 @@
|
||||
import * as React from "react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
export interface InputProps
|
||||
extends React.InputHTMLAttributes<HTMLInputElement> {}
|
||||
|
||||
const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
||||
({ className, type, ...props }, ref) => {
|
||||
return (
|
||||
<input
|
||||
type={type}
|
||||
className={cn(
|
||||
"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
ref={ref}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
)
|
||||
Input.displayName = "Input"
|
||||
|
||||
export { Input }
|
||||
@@ -0,0 +1,48 @@
|
||||
'use client'
|
||||
|
||||
import * as React from 'react'
|
||||
import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area'
|
||||
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
const ScrollArea = React.forwardRef<
|
||||
React.ElementRef<typeof ScrollAreaPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<ScrollAreaPrimitive.Root
|
||||
ref={ref}
|
||||
className={cn('relative overflow-hidden', className)}
|
||||
{...props}
|
||||
>
|
||||
<ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit]">
|
||||
{children}
|
||||
</ScrollAreaPrimitive.Viewport>
|
||||
<ScrollBar />
|
||||
<ScrollAreaPrimitive.Corner />
|
||||
</ScrollAreaPrimitive.Root>
|
||||
))
|
||||
ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName
|
||||
|
||||
const ScrollBar = React.forwardRef<
|
||||
React.ElementRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>,
|
||||
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>
|
||||
>(({ className, orientation = 'vertical', ...props }, ref) => (
|
||||
<ScrollAreaPrimitive.ScrollAreaScrollbar
|
||||
ref={ref}
|
||||
orientation={orientation}
|
||||
className={cn(
|
||||
'flex touch-none select-none transition-colors',
|
||||
orientation === 'vertical' &&
|
||||
'h-full w-2.5 border-l border-l-transparent p-[1px]',
|
||||
orientation === 'horizontal' &&
|
||||
'h-2.5 border-t border-t-transparent p-[1px]',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ScrollAreaPrimitive.ScrollAreaThumb className="relative flex-1 rounded-full bg-border" />
|
||||
</ScrollAreaPrimitive.ScrollAreaScrollbar>
|
||||
))
|
||||
ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName
|
||||
|
||||
export { ScrollArea, ScrollBar }
|
||||
@@ -0,0 +1,31 @@
|
||||
'use client'
|
||||
|
||||
import * as React from 'react'
|
||||
import * as SeparatorPrimitive from '@radix-ui/react-separator'
|
||||
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
const Separator = React.forwardRef<
|
||||
React.ElementRef<typeof SeparatorPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root>
|
||||
>(
|
||||
(
|
||||
{ className, orientation = 'horizontal', decorative = true, ...props },
|
||||
ref
|
||||
) => (
|
||||
<SeparatorPrimitive.Root
|
||||
ref={ref}
|
||||
decorative={decorative}
|
||||
orientation={orientation}
|
||||
className={cn(
|
||||
'shrink-0 bg-border',
|
||||
orientation === 'horizontal' ? 'h-[1px] w-full' : 'h-full w-[1px]',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
)
|
||||
Separator.displayName = SeparatorPrimitive.Root.displayName
|
||||
|
||||
export { Separator }
|
||||
@@ -0,0 +1,32 @@
|
||||
'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 };
|
||||
@@ -0,0 +1,55 @@
|
||||
'use client'
|
||||
|
||||
import * as React from 'react'
|
||||
import * as TabsPrimitive from '@radix-ui/react-tabs'
|
||||
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
const Tabs = TabsPrimitive.Root
|
||||
|
||||
const TabsList = React.forwardRef<
|
||||
React.ElementRef<typeof TabsPrimitive.List>,
|
||||
React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<TabsPrimitive.List
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
TabsList.displayName = TabsPrimitive.List.displayName
|
||||
|
||||
const TabsTrigger = React.forwardRef<
|
||||
React.ElementRef<typeof TabsPrimitive.Trigger>,
|
||||
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<TabsPrimitive.Trigger
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all 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=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
TabsTrigger.displayName = TabsPrimitive.Trigger.displayName
|
||||
|
||||
const TabsContent = React.forwardRef<
|
||||
React.ElementRef<typeof TabsPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<TabsPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
TabsContent.displayName = TabsPrimitive.Content.displayName
|
||||
|
||||
export { Tabs, TabsContent,TabsList, TabsTrigger }
|
||||
@@ -0,0 +1,45 @@
|
||||
'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,7 @@
|
||||
'use client';
|
||||
|
||||
import { useContext } from 'react';
|
||||
|
||||
import { ThemeContext } from '@/providers/Theme';
|
||||
|
||||
export const useTheme = () => useContext(ThemeContext);
|
||||
@@ -0,0 +1,6 @@
|
||||
import { clsx } from 'clsx'
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
|
||||
export function cn(...inputs) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { type ClassValue, clsx } from 'clsx'
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import axios, { AxiosResponse } from 'axios';
|
||||
|
||||
const client = axios.create({
|
||||
baseURL: `${process.env.NODE_ENV === 'development' ? 'http://' : 'https://'}${
|
||||
process.env.NEXT_PUBLIC_VERCEL_URL
|
||||
}/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;
|
||||
@@ -0,0 +1,15 @@
|
||||
import axios, { AxiosResponse } from 'axios';
|
||||
|
||||
export const server = axios.create({
|
||||
baseURL: 'https://api.themoviedb.org/3',
|
||||
headers: {
|
||||
Authorization: `Bearer ${process.env.MOVIE_DB_TOKEN}`,
|
||||
accept: 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
const handleResponse = (response: AxiosResponse): AxiosResponse['data'] => response.data;
|
||||
|
||||
server.interceptors.response.use(handleResponse);
|
||||
|
||||
export default server;
|
||||
+11
-2
@@ -1,4 +1,13 @@
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {}
|
||||
const nextConfig = {
|
||||
images: {
|
||||
remotePatterns: [
|
||||
{
|
||||
protocol: 'https',
|
||||
hostname: '**'
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = nextConfig
|
||||
module.exports = nextConfig;
|
||||
Generated
+3747
-108
File diff suppressed because it is too large.
Load diff
+42
-6
@@ -9,14 +9,50 @@
|
||||
"lint": "next lint"
|
||||
},
|
||||
"dependencies": {
|
||||
"@radix-ui/react-dialog": "^1.0.4",
|
||||
"@radix-ui/react-dropdown-menu": "^2.0.5",
|
||||
"@radix-ui/react-label": "^2.0.2",
|
||||
"@radix-ui/react-menubar": "^1.0.3",
|
||||
"@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.6",
|
||||
"@tanstack/react-query": "5.0.0-alpha.71",
|
||||
"@tanstack/react-query-next-experimental": "^5.0.0-alpha.80",
|
||||
"axios": "^1.4.0",
|
||||
"class-variance-authority": "^0.7.0",
|
||||
"classnames": "^2.3.2",
|
||||
"clsx": "^2.0.0",
|
||||
"cmdk": "^0.2.0",
|
||||
"eslint": "8.45.0",
|
||||
"eslint-config-next": "13.4.12",
|
||||
"jotai": "^2.2.2",
|
||||
"js-cookie": "^3.0.5",
|
||||
"lucide-react": "^0.263.0",
|
||||
"next": "13.4.9",
|
||||
"next-themes": "^0.2.1",
|
||||
"openai": "^3.3.0",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0",
|
||||
"react-fast-marquee": "^1.6.0",
|
||||
"tailwind-merge": "^1.14.0",
|
||||
"tailwindcss-animate": "^1.0.6",
|
||||
"typescript": "5.1.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/js-cookie": "^3.0.3",
|
||||
"@types/node": "20.4.4",
|
||||
"@types/react": "18.2.15",
|
||||
"@types/react-dom": "18.2.7",
|
||||
"eslint": "8.45.0",
|
||||
"eslint-config-next": "13.4.12",
|
||||
"next": "13.4.12",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0",
|
||||
"typescript": "5.1.6"
|
||||
"autoprefixer": "^10.4.14",
|
||||
"eslint-plugin-simple-import-sort": "^10.0.0",
|
||||
"postcss": "^8.4.27",
|
||||
"prettier": "^3.0.0",
|
||||
"tailwindcss": "^3.3.3"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { createContext, Dispatch, ReactNode, SetStateAction, useEffect, useState } from 'react';
|
||||
import Cookies from 'js-cookie';
|
||||
|
||||
export const ThemeContext = createContext<[Theme, Dispatch<SetStateAction<Theme>>]>([
|
||||
Cookies.get('theme') as Theme,
|
||||
() => null
|
||||
]);
|
||||
|
||||
export default function Provider({ children, theme: initialTheme }: { children: ReactNode; theme?: Theme }) {
|
||||
const state = useState<Theme>((Cookies.get('theme') || initialTheme) as Theme);
|
||||
|
||||
const [theme, setTheme] = state;
|
||||
|
||||
useEffect(() => {
|
||||
if (!theme) {
|
||||
return setTheme(window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
|
||||
}
|
||||
|
||||
document.documentElement.setAttribute('class', theme);
|
||||
Cookies.set('theme', theme);
|
||||
}, [theme, setTheme]);
|
||||
|
||||
return <ThemeContext.Provider value={state}>{children}</ThemeContext.Provider>;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
'use client';
|
||||
|
||||
import { ReactNode, useState } from 'react';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import { ReactQueryStreamedHydration } from '@tanstack/react-query-next-experimental';
|
||||
|
||||
import ThemeProvider from '@/providers/Theme';
|
||||
|
||||
const Providers = ({ children, theme }: { children: ReactNode; theme?: Theme }) => {
|
||||
const [queryClient] = useState(
|
||||
() =>
|
||||
new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
refetchOnWindowFocus: false,
|
||||
staleTime: Number.POSITIVE_INFINITY
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
return (
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<ReactQueryStreamedHydration>
|
||||
<ThemeProvider theme={theme}>{children}</ThemeProvider>
|
||||
</ReactQueryStreamedHydration>
|
||||
</QueryClientProvider>
|
||||
);
|
||||
};
|
||||
|
||||
export default Providers;
|
||||
File renamed without changes.
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
@@ -0,0 +1,87 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
@layer base {
|
||||
:root {
|
||||
--background: 0 0% 100%;
|
||||
--gradient-color: 0 0% 100%, 0 0% 0%;
|
||||
--foreground: 222.2 84% 4.9%;
|
||||
|
||||
--muted: 210 40% 96.1%;
|
||||
--muted-foreground: 215.4 16.3% 46.9%;
|
||||
|
||||
--popover: 0 0% 100%;
|
||||
--popover-foreground: 222.2 84% 4.9%;
|
||||
|
||||
--card: 0 0% 100%;
|
||||
--card-foreground: 222.2 84% 4.9%;
|
||||
|
||||
--border: 214.3 31.8% 91.4%;
|
||||
--input: 214.3 31.8% 91.4%;
|
||||
|
||||
--primary: 222.2 47.4% 11.2%;
|
||||
--primary-foreground: 210 40% 98%;
|
||||
|
||||
--secondary: 210 40% 96.1%;
|
||||
--secondary-foreground: 222.2 47.4% 11.2%;
|
||||
|
||||
--accent: 210 40% 96.1%;
|
||||
--accent-foreground: 222.2 47.4% 11.2%;
|
||||
|
||||
--destructive: 0 84.2% 60.2%;
|
||||
--destructive-foreground: 210 40% 98%;
|
||||
|
||||
--ring: 215 20.2% 65.1%;
|
||||
|
||||
--radius: 0.5rem;
|
||||
}
|
||||
|
||||
.dark {
|
||||
--background: 222.2 84% 4.9%;
|
||||
--gradient-color: 222.2 84% 4.9%, 0 0% 0%;
|
||||
--foreground: 210 40% 98%;
|
||||
|
||||
--muted: 217.2 32.6% 17.5%;
|
||||
--muted-foreground: 215 20.2% 65.1%;
|
||||
|
||||
--popover: 222.2 84% 4.9%;
|
||||
--popover-foreground: 210 40% 98%;
|
||||
|
||||
--card: 222.2 84% 4.9%;
|
||||
--card-foreground: 210 40% 98%;
|
||||
|
||||
--border: 217.2 32.6% 17.5%;
|
||||
--input: 217.2 32.6% 17.5%;
|
||||
|
||||
--primary: 210 40% 98%;
|
||||
--primary-foreground: 222.2 47.4% 11.2%;
|
||||
|
||||
--secondary: 217.2 32.6% 17.5%;
|
||||
--secondary-foreground: 210 40% 98%;
|
||||
|
||||
--accent: 217.2 32.6% 17.5%;
|
||||
--accent-foreground: 210 40% 98%;
|
||||
|
||||
--destructive: 0 62.8% 30.6%;
|
||||
--destructive-foreground: 0 85.7% 97.3%;
|
||||
|
||||
--ring: 217.2 32.6% 17.5%;
|
||||
}
|
||||
}
|
||||
|
||||
@layer base {
|
||||
* {
|
||||
@apply border-border;
|
||||
}
|
||||
body {
|
||||
@apply bg-background text-foreground;
|
||||
}
|
||||
}
|
||||
|
||||
main,
|
||||
header {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 0 12px;
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
darkMode: ['class'],
|
||||
content: [
|
||||
'./pages/**/*.{ts,tsx}',
|
||||
'./components/**/*.{ts,tsx}',
|
||||
'./app/**/*.{ts,tsx}',
|
||||
'./src/**/*.{ts,tsx}',
|
||||
],
|
||||
theme: {
|
||||
container: {
|
||||
center: true,
|
||||
padding: '2rem',
|
||||
screens: {
|
||||
'2xl': '1400px',
|
||||
},
|
||||
},
|
||||
extend: {
|
||||
colors: {
|
||||
border: 'hsl(var(--border))',
|
||||
input: 'hsl(var(--input))',
|
||||
ring: 'hsl(var(--ring))',
|
||||
background: 'hsl(var(--background))',
|
||||
foreground: 'hsl(var(--foreground))',
|
||||
primary: {
|
||||
DEFAULT: 'hsl(var(--primary))',
|
||||
foreground: 'hsl(var(--primary-foreground))',
|
||||
},
|
||||
secondary: {
|
||||
DEFAULT: 'hsl(var(--secondary))',
|
||||
foreground: 'hsl(var(--secondary-foreground))',
|
||||
},
|
||||
destructive: {
|
||||
DEFAULT: 'hsl(var(--destructive))',
|
||||
foreground: 'hsl(var(--destructive-foreground))',
|
||||
},
|
||||
muted: {
|
||||
DEFAULT: 'hsl(var(--muted))',
|
||||
foreground: 'hsl(var(--muted-foreground))',
|
||||
},
|
||||
accent: {
|
||||
DEFAULT: 'hsl(var(--accent))',
|
||||
foreground: 'hsl(var(--accent-foreground))',
|
||||
},
|
||||
popover: {
|
||||
DEFAULT: 'hsl(var(--popover))',
|
||||
foreground: 'hsl(var(--popover-foreground))',
|
||||
},
|
||||
card: {
|
||||
DEFAULT: 'hsl(var(--card))',
|
||||
foreground: 'hsl(var(--card-foreground))',
|
||||
},
|
||||
},
|
||||
borderRadius: {
|
||||
lg: 'var(--radius)',
|
||||
md: 'calc(var(--radius) - 2px)',
|
||||
sm: 'calc(var(--radius) - 4px)',
|
||||
},
|
||||
keyframes: {
|
||||
'accordion-down': {
|
||||
from: { height: 0 },
|
||||
to: { height: 'var(--radix-accordion-content-height)' },
|
||||
},
|
||||
'accordion-up': {
|
||||
from: { height: 'var(--radix-accordion-content-height)' },
|
||||
to: { height: 0 },
|
||||
},
|
||||
},
|
||||
animation: {
|
||||
'accordion-down': 'accordion-down 0.2s ease-out',
|
||||
'accordion-up': 'accordion-up 0.2s ease-out',
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: [require('tailwindcss-animate')],
|
||||
}
|
||||
Vendored
+45
@@ -0,0 +1,45 @@
|
||||
type Theme = 'light' | 'dark';
|
||||
|
||||
interface MovieDBResponse {
|
||||
page: number;
|
||||
results: Movie[];
|
||||
total_pages: number;
|
||||
total_results: number;
|
||||
}
|
||||
|
||||
interface Movie {
|
||||
adult: boolean;
|
||||
backdrop_path: string;
|
||||
genre_ids: number[];
|
||||
id: number;
|
||||
original_language: string;
|
||||
original_title: string;
|
||||
overview: string;
|
||||
popularity: number;
|
||||
poster_path: string;
|
||||
release_date: Date;
|
||||
title: string;
|
||||
video: boolean;
|
||||
vote_average: number;
|
||||
vote_count: number;
|
||||
}
|
||||
|
||||
interface Actor {
|
||||
adult: boolean;
|
||||
gender: number;
|
||||
id: number;
|
||||
known_for_department: string;
|
||||
name: string;
|
||||
original_name: string;
|
||||
popularity: number;
|
||||
profile_path: string;
|
||||
cast_id: number;
|
||||
character: string;
|
||||
credit_id: string;
|
||||
order: number;
|
||||
}
|
||||
|
||||
interface IDName<T = number> {
|
||||
id: T;
|
||||
name: string;
|
||||
}
|
||||
Reference in new issue
Block a user