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() {
|
||||
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 [scores, setScores] = useState(filters.score || ['0', '10']);
|
||||
@@ -39,6 +39,8 @@ export default function Filter() {
|
||||
setter(value.map((value) => value.toString()));
|
||||
};
|
||||
|
||||
if (!isFetched) return;
|
||||
|
||||
return (
|
||||
<>
|
||||
<ScrollArea className='mb-2'>
|
||||
|
||||
@@ -5,7 +5,7 @@ import { useQuery } from '@tanstack/react-query';
|
||||
import API from '@/app/(site)/api';
|
||||
const useGenres = () => {
|
||||
return useQuery({
|
||||
suspense: true,
|
||||
suspense: false,
|
||||
queryKey: ['genres'],
|
||||
queryFn: API.genres
|
||||
});
|
||||
|
||||
@@ -1,27 +1,42 @@
|
||||
'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 { Button } from '@/components/ui/button';
|
||||
|
||||
import Filter from './components/Filter';
|
||||
import useRandomMovie from './useRandomMovie';
|
||||
|
||||
const isShowFilterAtom = atomWithStorage('is-show-filters', false);
|
||||
|
||||
export default function Container() {
|
||||
const [isShowFilter, setIsShowFilter] = useAtom(isShowFilterAtom);
|
||||
const { movie, next, previous, hasPrevious } = useRandomMovie();
|
||||
|
||||
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'>
|
||||
<ArrowLeft size={24} strokeWidth={1} />
|
||||
</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'>
|
||||
<ArrowRight size={24} strokeWidth={1} />
|
||||
</Button>
|
||||
</div>
|
||||
<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';
|
||||
|
||||
export default async function Random() {
|
||||
return (
|
||||
<>
|
||||
<Filter />
|
||||
<Container />
|
||||
</>
|
||||
);
|
||||
return <Container />;
|
||||
}
|
||||
@@ -32,7 +32,7 @@ const Header: FC = () => {
|
||||
['/search', 'Search'],
|
||||
['/favorites', 'Favorites']
|
||||
].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}>
|
||||
{label}
|
||||
</TabsTrigger>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { FC } from 'react';
|
||||
import { Star } from 'lucide-react';
|
||||
import { FC, ReactNode } from 'react';
|
||||
|
||||
import Poster from '@/components/Movie/components/Poster';
|
||||
import Rating from '@/components/Movie/components/Rating';
|
||||
@@ -8,17 +7,17 @@ import Title from '@/components/Movie/components/Title';
|
||||
interface Props {
|
||||
movie?: Movie;
|
||||
className?: string;
|
||||
children?: ReactNode;
|
||||
}
|
||||
|
||||
const Card: FC<Props> = ({ movie, className }) => {
|
||||
const Card: FC<Props> = ({ movie, className, children }) => {
|
||||
if (!movie) return null;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`${className} rounded-lg border bg-card text-card-foreground shadow-sm transition-shadow hover:shadow-lg`}
|
||||
>
|
||||
<div className={`${className} rounded-lg bg-card text-card-foreground shadow-sm transition-shadow hover:shadow-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} />
|
||||
{children}
|
||||
<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='grid items-center grid-cols-[1fr_50px]'>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
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';
|
||||
@@ -56,7 +55,7 @@ const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage }) => {
|
||||
<div className='h-4 w-full' />
|
||||
{movie && (
|
||||
<Dialog defaultOpen={true} onOpenChange={(isOpen) => !isOpen && setMovie(null)}>
|
||||
<DialogContent className='block p-0'>
|
||||
<DialogContent className='block p-0' onClose={() => setMovie(null)}>
|
||||
<Preview
|
||||
key={movie.id}
|
||||
movie={movie}
|
||||
|
||||
@@ -4,15 +4,13 @@ import { useRouter } from 'next/navigation';
|
||||
|
||||
import useTrailer from '@/app/(site)/useTrailer';
|
||||
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 { Separator } from '@/components/ui/separator';
|
||||
|
||||
import { Button } from '../ui/button';
|
||||
|
||||
import Torrents from './components/Torrents';
|
||||
import Card from './Card';
|
||||
|
||||
interface Props {
|
||||
movie?: Movie;
|
||||
@@ -31,15 +29,8 @@ const Preview: FC<Props> = ({ movie, className, onClose }) => {
|
||||
return (
|
||||
<>
|
||||
<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'>
|
||||
<Poster
|
||||
className='max-w-[300px]'
|
||||
title={movie.title}
|
||||
width={300}
|
||||
height={450}
|
||||
size={100}
|
||||
poster={movie.poster_path}
|
||||
>
|
||||
<div className='flex flex-col lg:flex-row max-w-[100%] gap-3'>
|
||||
<Card movie={movie} className='max-w-[300px] min-w-[300px] mx-auto w-full'>
|
||||
{trailer && (
|
||||
<div
|
||||
onClick={() => setIsShowTrailer(true)}
|
||||
@@ -49,24 +40,9 @@ const Preview: FC<Props> = ({ movie, className, onClose }) => {
|
||||
<Play size={100} className='fill-white' />
|
||||
</div>
|
||||
)}
|
||||
</Poster>
|
||||
</Card>
|
||||
<div className='flex flex-col grow'>
|
||||
<div className='flex'>
|
||||
<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'>
|
||||
<div className='flex w-full gap-2'>
|
||||
<Button className='h-8 grow' onClick={() => setIsShowTorrents(true)}>
|
||||
Torrents
|
||||
</Button>
|
||||
@@ -80,6 +56,8 @@ const Preview: FC<Props> = ({ movie, className, onClose }) => {
|
||||
Similar
|
||||
</Button>
|
||||
</div>
|
||||
<Separator className='my-2' />
|
||||
<p className='leading-7'>{movie.overview}</p>
|
||||
</div>
|
||||
</div>
|
||||
<Credits movieId={movie.id} onPersonClick={() => onClose?.()} />
|
||||
|
||||
@@ -16,16 +16,6 @@ type Sorting = {
|
||||
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 = ({
|
||||
title,
|
||||
by,
|
||||
@@ -60,8 +50,8 @@ const Torrents: FC<Props> = ({ title, onClose }) => {
|
||||
|
||||
return (
|
||||
<Dialog defaultOpen={true} onOpenChange={(isOpen) => !isOpen && onClose()}>
|
||||
<DialogContent className='p-0'>
|
||||
<Table>
|
||||
<DialogContent className='p-0' onClose={onClose}>
|
||||
<Table className='rounded-xl overflow-hidden'>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className='px-2'>Title</TableHead>
|
||||
|
||||
@@ -11,7 +11,7 @@ const Trailer: FC<Props> = ({ trailerKey, onClose }) => {
|
||||
return (
|
||||
trailerKey && (
|
||||
<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
|
||||
allow='autoplay'
|
||||
className='border-none rounded-lg'
|
||||
|
||||
+22
-19
@@ -1,6 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import * as React from 'react';
|
||||
import { useState } from 'react';
|
||||
import * as DialogPrimitive from '@radix-ui/react-dialog';
|
||||
|
||||
import { cn } from '@/lib/utils';
|
||||
@@ -21,7 +22,7 @@ const DialogOverlay = React.forwardRef<
|
||||
<DialogPrimitive.Overlay
|
||||
ref={ref}
|
||||
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
|
||||
)}
|
||||
{...props}
|
||||
@@ -31,24 +32,26 @@ 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 flex justify-center'>
|
||||
<DialogPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'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
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<div className='absolute w-full block h-[20vh] pointer-events-none' />
|
||||
</DialogPrimitive.Content>
|
||||
</DialogOverlay>
|
||||
</DialogPortal>
|
||||
));
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & { onClose?: () => void }
|
||||
>(({ className, children, ...props }, ref) => {
|
||||
return (
|
||||
<DialogPortal>
|
||||
<DialogOverlay className='overflow-auto flex justify-center'>
|
||||
<DialogPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'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}
|
||||
>
|
||||
{children}
|
||||
<div className='absolute w-full block h-[20vh] pointer-events-none' />
|
||||
</DialogPrimitive.Content>
|
||||
</DialogOverlay>
|
||||
</DialogPortal>
|
||||
);
|
||||
});
|
||||
DialogContent.displayName = DialogPrimitive.Content.displayName;
|
||||
|
||||
const DialogHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
import axios, { AxiosResponse } from 'axios';
|
||||
|
||||
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
|
||||
}/api`,
|
||||
withCredentials: true
|
||||
|
||||
Vendored
+10
@@ -116,3 +116,13 @@ interface Category {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface Poster {
|
||||
aspect_ratio: number;
|
||||
height: number;
|
||||
iso_639_1: null;
|
||||
file_path: string;
|
||||
vote_average: number;
|
||||
vote_count: number;
|
||||
width: number;
|
||||
}
|
||||
Reference in new issue
Block a user