From a4f420821ab188bc56ae72ec2124ab39fd533f55 Mon Sep 17 00:00:00 2001 From: ner Date: Sat, 5 Aug 2023 16:11:20 +0300 Subject: [PATCH] refactor: layout improvements; suggestions count increased up to 10 --- app/api/search/description/route.ts | 6 ++--- app/layout.tsx | 8 ++++++- components/Movie/Card.tsx | 8 +++---- components/Movie/List.tsx | 4 ++-- components/Movie/Preview.tsx | 24 ++++++++++++++------ components/Movie/components/Poster/index.tsx | 11 +++++---- components/ui/dialog.tsx | 11 +++------ styles/index.css | 2 +- 8 files changed, 44 insertions(+), 30 deletions(-) diff --git a/app/api/search/description/route.ts b/app/api/search/description/route.ts index 3658d45..4c15059 100644 --- a/app/api/search/description/route.ts +++ b/app/api/search/description/route.ts @@ -11,9 +11,9 @@ export async function GET(request: Request) { 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, + prompt: `Based on the movie description: ${params.description}, suggest 10 movies. Format of suggestions: only title separated by comma`, + max_tokens: 120, + temperature: 0.2, stop: ['Based on the movie description:'] }); diff --git a/app/layout.tsx b/app/layout.tsx index a1d788d..088c534 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -9,7 +9,13 @@ import '@/styles/index.css'; export const metadata: Metadata = { title: 'Movie advisor', - description: 'It will help you find a movie for evening' + description: 'It will help you find a movie for evening', + viewport: { + width: 'device-width', + initialScale: 1, + maximumScale: 1, + userScalable: false + } }; export default function RootLayout({ children }: { children: ReactNode }) { diff --git a/components/Movie/Card.tsx b/components/Movie/Card.tsx index e0cfbcf..a6b7f69 100644 --- a/components/Movie/Card.tsx +++ b/components/Movie/Card.tsx @@ -17,18 +17,18 @@ const Card: FC = ({ movie, className }) => { className={`${className} p-4 rounded-lg border bg-card text-card-foreground shadow-sm transition-shadow hover:shadow-lg`} >
-
+
{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 /> + <div className='flex w-full justify-end items-center gap-1 mt-[-8px]'> + <Star size={17} /> <span className='text-lg font-semibold'>{movie.vote_average}</span> </div> </div> - <div className='flex justify-center relative'> + <div className='flex justify-center relative mt-1 h-full'> <Poster title={movie.title} width={300} height={450} size={100} poster={movie.poster_path} /> </div> </div> diff --git a/components/Movie/List.tsx b/components/Movie/List.tsx index 451b5dd..fd2f561 100644 --- a/components/Movie/List.tsx +++ b/components/Movie/List.tsx @@ -36,7 +36,7 @@ const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage }) => { return ( <> - <ul className='flex gap-3 flex-wrap'> + <ul className='flex gap-3 flex-wrap justify-between'> {pages.map((page) => ( <Fragment key={page.page}> {page.results?.map((movie, index, array) => ( @@ -52,7 +52,7 @@ const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage }) => { </Fragment> ))} </ul> - <div className='h-4 w-full'></div> + <div className='h-4 w-full' /> {movie && ( <Dialog defaultOpen={true} onOpenChange={(isOpen) => !isOpen && setMovie(null)}> <DialogContent className='block p-0'> diff --git a/components/Movie/Preview.tsx b/components/Movie/Preview.tsx index d332c5e..bff6be4 100644 --- a/components/Movie/Preview.tsx +++ b/components/Movie/Preview.tsx @@ -19,17 +19,27 @@ const Preview: FC<Props> = ({ movie, className }) => { 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} /> + <Poster + title={movie.title} + width={300} + height={450} + size={250} + poster={movie.poster_path} + className='max-w-[300px]' + /> <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()})`} + <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> - <div className='flex items-center gap-2'> - <Star /> + <span className='flex items-center ml-auto gap-1 mt-[-8px]'> + <Star size={18} /> <span>{movie.vote_average}</span> - </div> + </span> </div> </div> <Separator className='my-4' /> diff --git a/components/Movie/components/Poster/index.tsx b/components/Movie/components/Poster/index.tsx index 7747369..71b7108 100644 --- a/components/Movie/components/Poster/index.tsx +++ b/components/Movie/components/Poster/index.tsx @@ -8,14 +8,17 @@ interface Props { width: number; height: number; size: number; + className?: string; } -const Poster: FC<Props> = ({ title, poster, width, height, size = 250 }) => { +const Poster: FC<Props> = ({ title, poster, width, height, size = 250, className }) => { return ( - <div className='max-w-[300px] h-[450px] w-full rounded-lg overflow-hidden shrink-0 relative m-auto lg:m-0'> + <div + className={`h-[${height}px] w-full flex flex-col rounded-lg overflow-hidden shrink-0 relative m-auto lg:m-0 ${className}`} + > {poster ? ( <Image - className='rounded-lg ' + className='rounded-lg m-auto' unoptimized height={height} width={width} @@ -23,7 +26,7 @@ const Poster: FC<Props> = ({ title, poster, width, height, size = 250 }) => { alt={title} /> ) : ( - <div className={`w-[${width}px] h-[${height}px] flex items-center justify-center rounded-lg border`}> + <div className={'w-full h-full grow flex items-center justify-center rounded-lg border'}> <ImageOff size={size} strokeWidth={1} /> </div> )} diff --git a/components/ui/dialog.tsx b/components/ui/dialog.tsx index f334012..6fc3d5b 100644 --- a/components/ui/dialog.tsx +++ b/components/ui/dialog.tsx @@ -2,7 +2,6 @@ import * as React from 'react'; import * as DialogPrimitive from '@radix-ui/react-dialog'; -import { X } from 'lucide-react'; import { cn } from '@/lib/utils'; @@ -35,21 +34,17 @@ const DialogContent = React.forwardRef< React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> >(({ className, children, ...props }, ref) => ( <DialogPortal> - <DialogOverlay className='overflow-auto'> + <DialogOverlay className='overflow-auto flex justify-center'> <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', + '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} - <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.Close type='button' autoFocus={false} className='absolute w-full block h-[20vh] outline-0' /> </DialogPrimitive.Content> </DialogOverlay> </DialogPortal> diff --git a/styles/index.css b/styles/index.css index 69afeac..fd35c4d 100644 --- a/styles/index.css +++ b/styles/index.css @@ -81,7 +81,7 @@ main, header { - max-width: 1200px; + max-width: 1050px; margin: 0 auto; padding: 0 12px; } \ No newline at end of file