feat: animations
This commit is contained in:
1 parent
e4788ae384
commit
7b55619cf5
16 files changed
+643
-320
No files matched your search
@@ -1,15 +1,15 @@
|
||||
import { ChangeEvent, useRef, useState } from 'react';
|
||||
import { Search as SearchIcon, XCircle } from 'lucide-react';
|
||||
import { ChangeEvent, FC, useRef, useState } from 'react';
|
||||
import { create, InstanceProps } from 'react-modal-promise';
|
||||
import { XCircle } from 'lucide-react';
|
||||
|
||||
import List from '@/components/Movie/List';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Dialog, DialogContent } from '@/components/ui/dialog';
|
||||
import { Modal } from '@/components/ui/dialog';
|
||||
import { Input } from '@/components/ui/input';
|
||||
|
||||
import useSearch from './useSearch';
|
||||
|
||||
const Search = () => {
|
||||
const [isShow, setIsShow] = useState(false);
|
||||
const Search: FC<InstanceProps<void>> = ({ isOpen, onResolve }) => {
|
||||
const [title, setTitle] = useState('');
|
||||
const [query, setQuery] = useState('');
|
||||
const timeout = useRef<NodeJS.Timeout>();
|
||||
@@ -31,54 +31,45 @@ const Search = () => {
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
setIsShow(false);
|
||||
handleReset();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button variant='outline' size='icon' onClick={() => setIsShow(true)}>
|
||||
<SearchIcon />
|
||||
</Button>
|
||||
{isShow && (
|
||||
<Dialog defaultOpen={true} onOpenChange={handleClose}>
|
||||
<DialogContent className='block p-3 max-w-[950px]' onClose={() => setIsShow(false)}>
|
||||
<div className='relative'>
|
||||
<Input
|
||||
ref={inputRef}
|
||||
autoFocus
|
||||
placeholder='Start entering title...'
|
||||
value={title}
|
||||
onChange={handleChangeTitle}
|
||||
className='pr-10'
|
||||
/>
|
||||
<Button
|
||||
variant='outline'
|
||||
size='icon'
|
||||
onClick={handleReset}
|
||||
disabled={!query.length}
|
||||
className='absolute right-0 top-0'
|
||||
>
|
||||
<XCircle />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{Boolean(results?.pages.length) && (
|
||||
<div className='mt-3'>
|
||||
<List
|
||||
pages={results!.pages}
|
||||
fetchNextPage={fetchNextPage}
|
||||
hasNextPage={hasNextPage}
|
||||
withBottomGap={false}
|
||||
onPreviewClose={handleClose}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
<Modal className='block p-3 max-w-[950px]' isOpen={isOpen} onClose={() => onResolve()}>
|
||||
<div className='relative'>
|
||||
<Input
|
||||
ref={inputRef}
|
||||
autoFocus
|
||||
placeholder='Start entering title...'
|
||||
value={title}
|
||||
onChange={handleChangeTitle}
|
||||
className='pr-10'
|
||||
/>
|
||||
<Button
|
||||
variant='outline'
|
||||
size='icon'
|
||||
onClick={handleReset}
|
||||
disabled={!query.length}
|
||||
className='absolute right-0 top-0'
|
||||
>
|
||||
<XCircle />
|
||||
</Button>
|
||||
</div>
|
||||
{Boolean(results?.pages.length) && (
|
||||
<div className='mt-3'>
|
||||
<List
|
||||
pages={results!.pages}
|
||||
fetchNextPage={fetchNextPage}
|
||||
hasNextPage={hasNextPage}
|
||||
withBottomGap={false}
|
||||
onPreviewClose={handleClose}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export const showSearchModal = create(Search);
|
||||
|
||||
export default Search;
|
||||
@@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import { FC } from 'react';
|
||||
import { Moon, Sun } from 'lucide-react';
|
||||
import { Moon, Search as SearchIcon, Sun } from 'lucide-react';
|
||||
import Link from 'next/link';
|
||||
import { usePathname } from 'next/navigation';
|
||||
|
||||
@@ -10,7 +10,7 @@ import { Button } from '@/components/ui/button';
|
||||
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
import { useTheme } from '@/hooks/useTheme';
|
||||
|
||||
import Search from './components/Search';
|
||||
import { showSearchModal } from './components/Search';
|
||||
|
||||
const Header: FC = () => {
|
||||
const path = usePathname();
|
||||
@@ -26,7 +26,9 @@ const Header: FC = () => {
|
||||
<Button variant='outline' size='icon' onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}>
|
||||
{theme === 'light' ? <Moon /> : <Sun />}
|
||||
</Button>
|
||||
<Search />
|
||||
<Button variant='outline' size='icon' onClick={() => showSearchModal()}>
|
||||
<SearchIcon />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<Tabs value={path} className='flex-grow mt-2'>
|
||||
@@ -36,7 +38,7 @@ const Header: FC = () => {
|
||||
['/top', 'Top'],
|
||||
['/favorites', 'Favorites']
|
||||
].map(([path, label]) => (
|
||||
<Link href={path} className='w-full' key={path} prefetch>
|
||||
<Link href={path} className='w-full' key={path}>
|
||||
<TabsTrigger className='w-full' value={path}>
|
||||
{label}
|
||||
</TabsTrigger>
|
||||
|
||||
Reference in new issue
Block a user