feat: filter can be hidden
This commit is contained in:
1 parent
c42d5a5298
commit
ff506e755c
13 files changed
+73
-83
No files matched your search
@@ -12,7 +12,7 @@ import useGenres from './useGenres';
|
|||||||
|
|
||||||
export default function Filter() {
|
export default function Filter() {
|
||||||
const { filters, setFilters } = useFilters();
|
const { filters, setFilters } = useFilters();
|
||||||
const { data: genres } = useGenres();
|
const { data: genres, isFetched } = useGenres();
|
||||||
|
|
||||||
const [years, setYears] = useState(filters.year || ['1990', new Date().getFullYear().toString()]);
|
const [years, setYears] = useState(filters.year || ['1990', new Date().getFullYear().toString()]);
|
||||||
const [scores, setScores] = useState(filters.score || ['0', '10']);
|
const [scores, setScores] = useState(filters.score || ['0', '10']);
|
||||||
@@ -39,6 +39,8 @@ export default function Filter() {
|
|||||||
setter(value.map((value) => value.toString()));
|
setter(value.map((value) => value.toString()));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!isFetched) return;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ScrollArea className='mb-2'>
|
<ScrollArea className='mb-2'>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { useQuery } from '@tanstack/react-query';
|
|||||||
import API from '@/app/(site)/api';
|
import API from '@/app/(site)/api';
|
||||||
const useGenres = () => {
|
const useGenres = () => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
suspense: true,
|
suspense: false,
|
||||||
queryKey: ['genres'],
|
queryKey: ['genres'],
|
||||||
queryFn: API.genres
|
queryFn: API.genres
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,27 +1,42 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { ArrowLeft, ArrowRight } from 'lucide-react';
|
import { useAtom } from 'jotai';
|
||||||
|
import { atomWithStorage } from 'jotai/utils';
|
||||||
|
import { ArrowLeft, ArrowRight, SlidersHorizontal } from 'lucide-react';
|
||||||
|
|
||||||
import Movie from '@/components/Movie/Preview';
|
import Movie from '@/components/Movie/Preview';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
|
|
||||||
|
import Filter from './components/Filter';
|
||||||
import useRandomMovie from './useRandomMovie';
|
import useRandomMovie from './useRandomMovie';
|
||||||
|
|
||||||
|
const isShowFilterAtom = atomWithStorage('is-show-filters', false);
|
||||||
|
|
||||||
export default function Container() {
|
export default function Container() {
|
||||||
|
const [isShowFilter, setIsShowFilter] = useAtom(isShowFilterAtom);
|
||||||
const { movie, next, previous, hasPrevious } = useRandomMovie();
|
const { movie, next, previous, hasPrevious } = useRandomMovie();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className='gap-2 flex bg-background mb-2 lg:static max-sm:z-10 max-sm:fixed max-sm:bottom-0 max-sm:left-0 max-sm:w-full max-sm:p-2 max-sm:mb-0'>
|
{isShowFilter && <Filter />}
|
||||||
|
<div className='gap-2 flex bg-background mb-2 lg:static max-sm:z-10 max-sm:fixed max-sm:bottom-0 max-sm:left-0 max-sm:w-full max-sm:p-2 max-sm:px-[12px] max-sm:mb-0'>
|
||||||
<Button className='p-2' onClick={previous} disabled={!hasPrevious} title='Previous movie'>
|
<Button className='p-2' onClick={previous} disabled={!hasPrevious} title='Previous movie'>
|
||||||
<ArrowLeft size={24} strokeWidth={1} />
|
<ArrowLeft size={24} strokeWidth={1} />
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button
|
||||||
|
className='p-2'
|
||||||
|
onClick={() => setIsShowFilter((isShow) => !isShow)}
|
||||||
|
title={isShowFilter ? 'Hide filters' : 'Show filters'}
|
||||||
|
variant={isShowFilter ? 'outline' : 'default'}
|
||||||
|
>
|
||||||
|
<SlidersHorizontal size={24} strokeWidth={1} />
|
||||||
|
</Button>
|
||||||
<Button className='w-full p-2 grow' onClick={next} title='Next movie'>
|
<Button className='w-full p-2 grow' onClick={next} title='Next movie'>
|
||||||
<ArrowRight size={24} strokeWidth={1} />
|
<ArrowRight size={24} strokeWidth={1} />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<Movie key={movie?.id} movie={movie} />
|
<Movie key={movie?.id} movie={movie} />
|
||||||
<div className='w-full h-2' />
|
<div className='w-full h-2 max-sm:h-20' />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
+1
-7
@@ -1,11 +1,5 @@
|
|||||||
import Filter from './components/Filter';
|
|
||||||
import Container from './container';
|
import Container from './container';
|
||||||
|
|
||||||
export default async function Random() {
|
export default async function Random() {
|
||||||
return (
|
return <Container />;
|
||||||
<>
|
|
||||||
<Filter />
|
|
||||||
<Container />
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ const Header: FC = () => {
|
|||||||
['/search', 'Search'],
|
['/search', 'Search'],
|
||||||
['/favorites', 'Favorites']
|
['/favorites', 'Favorites']
|
||||||
].map(([path, label]) => (
|
].map(([path, label]) => (
|
||||||
<Link href={path} className='w-full' key={path}>
|
<Link href={path} className='w-full' key={path} prefetch>
|
||||||
<TabsTrigger className='w-full' value={path}>
|
<TabsTrigger className='w-full' value={path}>
|
||||||
{label}
|
{label}
|
||||||
</TabsTrigger>
|
</TabsTrigger>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { FC } from 'react';
|
import { FC, ReactNode } from 'react';
|
||||||
import { Star } from 'lucide-react';
|
|
||||||
|
|
||||||
import Poster from '@/components/Movie/components/Poster';
|
import Poster from '@/components/Movie/components/Poster';
|
||||||
import Rating from '@/components/Movie/components/Rating';
|
import Rating from '@/components/Movie/components/Rating';
|
||||||
@@ -8,17 +7,17 @@ import Title from '@/components/Movie/components/Title';
|
|||||||
interface Props {
|
interface Props {
|
||||||
movie?: Movie;
|
movie?: Movie;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
children?: ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Card: FC<Props> = ({ movie, className }) => {
|
const Card: FC<Props> = ({ movie, className, children }) => {
|
||||||
if (!movie) return null;
|
if (!movie) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div className={`${className} rounded-lg bg-card text-card-foreground shadow-sm transition-shadow hover:shadow-lg`}>
|
||||||
className={`${className} rounded-lg border bg-card text-card-foreground shadow-sm transition-shadow hover:shadow-lg`}
|
|
||||||
>
|
|
||||||
<div className='flex justify-center relative grow overflow-hidden rounded-lg'>
|
<div className='flex justify-center relative grow overflow-hidden rounded-lg'>
|
||||||
<Poster title={movie.title} width={300} height={450} size={100} poster={movie.poster_path} />
|
<Poster title={movie.title} width={300} height={450} size={100} poster={movie.poster_path} />
|
||||||
|
{children}
|
||||||
<div className='absolute left-0 top-0 w-full h-20 bg-gradient-to-t from-transparent to-black opacity-80'>
|
<div className='absolute left-0 top-0 w-full h-20 bg-gradient-to-t from-transparent to-black opacity-80'>
|
||||||
<div className='max-w-[300px] w-full mx-auto pt-1 px-3 text-white'>
|
<div className='max-w-[300px] w-full mx-auto pt-1 px-3 text-white'>
|
||||||
<div className='grid items-center grid-cols-[1fr_50px]'>
|
<div className='grid items-center grid-cols-[1fr_50px]'>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { FC, Fragment, useLayoutEffect, useState } from 'react';
|
import { FC, Fragment, useLayoutEffect, useState } from 'react';
|
||||||
import { InfiniteData, useInfiniteQuery, UseInfiniteQueryResult } from '@tanstack/react-query';
|
|
||||||
|
|
||||||
import Card from '@/components/Movie/Card';
|
import Card from '@/components/Movie/Card';
|
||||||
import Preview from '@/components/Movie/Preview';
|
import Preview from '@/components/Movie/Preview';
|
||||||
@@ -56,7 +55,7 @@ const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage }) => {
|
|||||||
<div className='h-4 w-full' />
|
<div className='h-4 w-full' />
|
||||||
{movie && (
|
{movie && (
|
||||||
<Dialog defaultOpen={true} onOpenChange={(isOpen) => !isOpen && setMovie(null)}>
|
<Dialog defaultOpen={true} onOpenChange={(isOpen) => !isOpen && setMovie(null)}>
|
||||||
<DialogContent className='block p-0'>
|
<DialogContent className='block p-0' onClose={() => setMovie(null)}>
|
||||||
<Preview
|
<Preview
|
||||||
key={movie.id}
|
key={movie.id}
|
||||||
movie={movie}
|
movie={movie}
|
||||||
|
|||||||
@@ -4,15 +4,13 @@ import { useRouter } from 'next/navigation';
|
|||||||
|
|
||||||
import useTrailer from '@/app/(site)/useTrailer';
|
import useTrailer from '@/app/(site)/useTrailer';
|
||||||
import Credits from '@/components/Movie/components/Credits';
|
import Credits from '@/components/Movie/components/Credits';
|
||||||
import Poster from '@/components/Movie/components/Poster';
|
|
||||||
import Rating from '@/components/Movie/components/Rating';
|
|
||||||
import Title from '@/components/Movie/components/Title';
|
|
||||||
import Trailer from '@/components/Movie/components/Trailer';
|
import Trailer from '@/components/Movie/components/Trailer';
|
||||||
import { Separator } from '@/components/ui/separator';
|
import { Separator } from '@/components/ui/separator';
|
||||||
|
|
||||||
import { Button } from '../ui/button';
|
import { Button } from '../ui/button';
|
||||||
|
|
||||||
import Torrents from './components/Torrents';
|
import Torrents from './components/Torrents';
|
||||||
|
import Card from './Card';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
movie?: Movie;
|
movie?: Movie;
|
||||||
@@ -31,15 +29,8 @@ const Preview: FC<Props> = ({ movie, className, onClose }) => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className={`p-3 rounded-xl border bg-card text-card-foreground shadow-sm ${className}`}>
|
<div className={`p-3 rounded-xl border bg-card text-card-foreground shadow-sm ${className}`}>
|
||||||
<div className='flex flex-col lg:flex-row max-w-[100%] gap-3 overflow-hidden'>
|
<div className='flex flex-col lg:flex-row max-w-[100%] gap-3'>
|
||||||
<Poster
|
<Card movie={movie} className='max-w-[300px] min-w-[300px] mx-auto w-full'>
|
||||||
className='max-w-[300px]'
|
|
||||||
title={movie.title}
|
|
||||||
width={300}
|
|
||||||
height={450}
|
|
||||||
size={100}
|
|
||||||
poster={movie.poster_path}
|
|
||||||
>
|
|
||||||
{trailer && (
|
{trailer && (
|
||||||
<div
|
<div
|
||||||
onClick={() => setIsShowTrailer(true)}
|
onClick={() => setIsShowTrailer(true)}
|
||||||
@@ -49,24 +40,9 @@ const Preview: FC<Props> = ({ movie, className, onClose }) => {
|
|||||||
<Play size={100} className='fill-white' />
|
<Play size={100} className='fill-white' />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</Poster>
|
</Card>
|
||||||
<div className='flex flex-col grow'>
|
<div className='flex flex-col grow'>
|
||||||
<div className='flex'>
|
<div className='flex w-full gap-2'>
|
||||||
<div className='flex flex-row flex-wrap w-full text-lg font-semibold'>
|
|
||||||
<span className='flex w-full items-center'>
|
|
||||||
<span className='mr-2 w-full'>
|
|
||||||
<Title title={movie.title} />
|
|
||||||
</span>
|
|
||||||
{movie.release_date && <span className='ml-auto'>{new Date(movie.release_date).getFullYear()}</span>}
|
|
||||||
</span>
|
|
||||||
<Rating movie={movie} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<Separator className='my-2' />
|
|
||||||
<div className='flex flex-col items-start grow justify-between'>
|
|
||||||
<p className='leading-7'>{movie.overview}</p>
|
|
||||||
</div>
|
|
||||||
<div className='flex w-full mt-2 gap-2'>
|
|
||||||
<Button className='h-8 grow' onClick={() => setIsShowTorrents(true)}>
|
<Button className='h-8 grow' onClick={() => setIsShowTorrents(true)}>
|
||||||
Torrents
|
Torrents
|
||||||
</Button>
|
</Button>
|
||||||
@@ -80,6 +56,8 @@ const Preview: FC<Props> = ({ movie, className, onClose }) => {
|
|||||||
Similar
|
Similar
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
<Separator className='my-2' />
|
||||||
|
<p className='leading-7'>{movie.overview}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Credits movieId={movie.id} onPersonClick={() => onClose?.()} />
|
<Credits movieId={movie.id} onPersonClick={() => onClose?.()} />
|
||||||
|
|||||||
@@ -16,16 +16,6 @@ type Sorting = {
|
|||||||
by: ORDER;
|
by: ORDER;
|
||||||
};
|
};
|
||||||
|
|
||||||
function convertToBytes(size: string) {
|
|
||||||
const units: Record<string, number> = { B: 1, KiB: 1024, MiB: 1024 * 1024, GiB: 1024 * 1024 * 1024 };
|
|
||||||
const [value, unit] = size.split(' ');
|
|
||||||
return parseFloat(value) * units[unit];
|
|
||||||
}
|
|
||||||
|
|
||||||
function compareSizes(size1: string, size2: string) {
|
|
||||||
return convertToBytes(size1) - convertToBytes(size2);
|
|
||||||
}
|
|
||||||
|
|
||||||
const TableHeadSortable = ({
|
const TableHeadSortable = ({
|
||||||
title,
|
title,
|
||||||
by,
|
by,
|
||||||
@@ -60,8 +50,8 @@ const Torrents: FC<Props> = ({ title, onClose }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog defaultOpen={true} onOpenChange={(isOpen) => !isOpen && onClose()}>
|
<Dialog defaultOpen={true} onOpenChange={(isOpen) => !isOpen && onClose()}>
|
||||||
<DialogContent className='p-0'>
|
<DialogContent className='p-0' onClose={onClose}>
|
||||||
<Table>
|
<Table className='rounded-xl overflow-hidden'>
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead className='px-2'>Title</TableHead>
|
<TableHead className='px-2'>Title</TableHead>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ const Trailer: FC<Props> = ({ trailerKey, onClose }) => {
|
|||||||
return (
|
return (
|
||||||
trailerKey && (
|
trailerKey && (
|
||||||
<Dialog defaultOpen={true} onOpenChange={(isOpen) => !isOpen && onClose()}>
|
<Dialog defaultOpen={true} onOpenChange={(isOpen) => !isOpen && onClose()}>
|
||||||
<DialogContent className='block p-0 min-h-[400px] aspect-w-16 aspect-h-9'>
|
<DialogContent className='block p-0 min-h-[400px] border-none aspect-w-16 aspect-h-9' onClose={onClose}>
|
||||||
<iframe
|
<iframe
|
||||||
allow='autoplay'
|
allow='autoplay'
|
||||||
className='border-none rounded-lg'
|
className='border-none rounded-lg'
|
||||||
|
|||||||
+22
-19
@@ -1,6 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
import { useState } from 'react';
|
||||||
import * as DialogPrimitive from '@radix-ui/react-dialog';
|
import * as DialogPrimitive from '@radix-ui/react-dialog';
|
||||||
|
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
@@ -21,7 +22,7 @@ const DialogOverlay = React.forwardRef<
|
|||||||
<DialogPrimitive.Overlay
|
<DialogPrimitive.Overlay
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
'fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
|
'fixed inset-0 z-50 bg-black/70 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
@@ -31,24 +32,26 @@ DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
|
|||||||
|
|
||||||
const DialogContent = React.forwardRef<
|
const DialogContent = React.forwardRef<
|
||||||
React.ElementRef<typeof DialogPrimitive.Content>,
|
React.ElementRef<typeof DialogPrimitive.Content>,
|
||||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
|
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & { onClose?: () => void }
|
||||||
>(({ className, children, ...props }, ref) => (
|
>(({ className, children, ...props }, ref) => {
|
||||||
<DialogPortal>
|
return (
|
||||||
<DialogOverlay className='overflow-auto flex justify-center'>
|
<DialogPortal>
|
||||||
<DialogPrimitive.Content
|
<DialogOverlay className='overflow-auto flex justify-center'>
|
||||||
ref={ref}
|
<DialogPrimitive.Content
|
||||||
className={cn(
|
ref={ref}
|
||||||
'absolute 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={cn(
|
||||||
className
|
'absolute 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-xl',
|
||||||
)}
|
className
|
||||||
{...props}
|
)}
|
||||||
>
|
{...props}
|
||||||
{children}
|
>
|
||||||
<div className='absolute w-full block h-[20vh] pointer-events-none' />
|
{children}
|
||||||
</DialogPrimitive.Content>
|
<div className='absolute w-full block h-[20vh] pointer-events-none' />
|
||||||
</DialogOverlay>
|
</DialogPrimitive.Content>
|
||||||
</DialogPortal>
|
</DialogOverlay>
|
||||||
));
|
</DialogPortal>
|
||||||
|
);
|
||||||
|
});
|
||||||
DialogContent.displayName = DialogPrimitive.Content.displayName;
|
DialogContent.displayName = DialogPrimitive.Content.displayName;
|
||||||
|
|
||||||
const DialogHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
|
const DialogHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
import axios, { AxiosResponse } from 'axios';
|
import axios, { AxiosResponse } from 'axios';
|
||||||
|
|
||||||
const client = axios.create({
|
const client = axios.create({
|
||||||
baseURL: `${process.env.NODE_ENV === 'development' ? 'http://' : 'https://'}${
|
baseURL: `${process.env.NODE_ENV === 'development' ? 'http://' : 'http://'}${
|
||||||
process.env.NEXT_PUBLIC_MOVIE_ADVISOR_BASE
|
process.env.NEXT_PUBLIC_MOVIE_ADVISOR_BASE
|
||||||
}/api`,
|
}/api`,
|
||||||
withCredentials: true
|
withCredentials: true
|
||||||
|
|||||||
Vendored
+10
@@ -116,3 +116,13 @@ interface Category {
|
|||||||
id: string;
|
id: string;
|
||||||
name: 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;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user