2024-06-07 20:17:03 +03:00
|
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import clsx from 'clsx';
|
2024-09-27 12:03:13 +03:00
|
|
|
|
import { motion } from 'framer-motion';
|
|
|
|
|
import { useCallback, useMemo } from 'react';
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
2024-08-20 15:09:36 +03:00
|
|
|
|
import { LocationIcon, VisibilityIcon } from '@/components/DomainIcons';
|
2024-09-27 12:03:13 +03:00
|
|
|
|
import {
|
|
|
|
|
IconEditor,
|
|
|
|
|
IconFilterReset,
|
|
|
|
|
IconFolder,
|
|
|
|
|
IconFolderSearch,
|
|
|
|
|
IconFolderTree,
|
|
|
|
|
IconOwner,
|
|
|
|
|
IconUserSearch
|
|
|
|
|
} from '@/components/Icons';
|
2024-06-19 22:09:31 +03:00
|
|
|
|
import { CProps } from '@/components/props';
|
2024-09-27 12:03:13 +03:00
|
|
|
|
import SelectUser from '@/components/select/SelectUser';
|
2024-06-07 20:17:03 +03:00
|
|
|
|
import Dropdown from '@/components/ui/Dropdown';
|
|
|
|
|
import DropdownButton from '@/components/ui/DropdownButton';
|
|
|
|
|
import MiniButton from '@/components/ui/MiniButton';
|
|
|
|
|
import SearchBar from '@/components/ui/SearchBar';
|
|
|
|
|
import SelectorButton from '@/components/ui/SelectorButton';
|
2024-09-27 12:03:13 +03:00
|
|
|
|
import { useUsers } from '@/context/UsersContext';
|
2024-06-07 20:17:03 +03:00
|
|
|
|
import useDropdown from '@/hooks/useDropdown';
|
|
|
|
|
import { LocationHead } from '@/models/library';
|
2024-09-27 12:03:13 +03:00
|
|
|
|
import { UserID } from '@/models/user';
|
|
|
|
|
import { animateDropdownItem } from '@/styling/animations';
|
2024-06-21 11:16:47 +03:00
|
|
|
|
import { prefixes } from '@/utils/constants';
|
2024-06-07 20:17:03 +03:00
|
|
|
|
import { describeLocationHead, labelLocationHead } from '@/utils/labels';
|
|
|
|
|
import { tripleToggleColor } from '@/utils/utils';
|
|
|
|
|
|
2024-06-26 19:47:05 +03:00
|
|
|
|
interface ToolbarSearchProps {
|
2024-06-07 20:17:03 +03:00
|
|
|
|
total: number;
|
|
|
|
|
filtered: number;
|
2024-06-18 15:06:52 +03:00
|
|
|
|
hasCustomFilter: boolean;
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
|
query: string;
|
|
|
|
|
setQuery: React.Dispatch<React.SetStateAction<string>>;
|
|
|
|
|
path: string;
|
|
|
|
|
setPath: React.Dispatch<React.SetStateAction<string>>;
|
|
|
|
|
head: LocationHead | undefined;
|
|
|
|
|
setHead: React.Dispatch<React.SetStateAction<LocationHead | undefined>>;
|
|
|
|
|
|
2024-06-19 22:09:31 +03:00
|
|
|
|
folderMode: boolean;
|
|
|
|
|
toggleFolderMode: () => void;
|
|
|
|
|
|
2024-06-07 20:17:03 +03:00
|
|
|
|
isVisible: boolean | undefined;
|
|
|
|
|
toggleVisible: () => void;
|
|
|
|
|
isOwned: boolean | undefined;
|
|
|
|
|
toggleOwned: () => void;
|
|
|
|
|
isEditor: boolean | undefined;
|
|
|
|
|
toggleEditor: () => void;
|
2024-09-27 12:03:13 +03:00
|
|
|
|
filterUser: UserID | undefined;
|
|
|
|
|
setFilterUser: React.Dispatch<React.SetStateAction<UserID | undefined>>;
|
|
|
|
|
|
2024-06-18 15:06:52 +03:00
|
|
|
|
resetFilter: () => void;
|
2024-06-07 20:17:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-26 19:47:05 +03:00
|
|
|
|
function ToolbarSearch({
|
2024-06-07 20:17:03 +03:00
|
|
|
|
total,
|
|
|
|
|
filtered,
|
2024-06-18 15:06:52 +03:00
|
|
|
|
hasCustomFilter,
|
|
|
|
|
|
2024-06-07 20:17:03 +03:00
|
|
|
|
query,
|
|
|
|
|
setQuery,
|
|
|
|
|
path,
|
|
|
|
|
setPath,
|
|
|
|
|
head,
|
|
|
|
|
setHead,
|
|
|
|
|
|
2024-06-19 22:09:31 +03:00
|
|
|
|
folderMode,
|
|
|
|
|
toggleFolderMode,
|
|
|
|
|
|
2024-06-07 20:17:03 +03:00
|
|
|
|
isVisible,
|
|
|
|
|
toggleVisible,
|
|
|
|
|
isOwned,
|
|
|
|
|
toggleOwned,
|
|
|
|
|
isEditor,
|
2024-06-18 15:06:52 +03:00
|
|
|
|
toggleEditor,
|
2024-09-27 12:03:13 +03:00
|
|
|
|
filterUser,
|
|
|
|
|
setFilterUser,
|
|
|
|
|
|
2024-06-18 15:06:52 +03:00
|
|
|
|
resetFilter
|
2024-06-26 19:47:05 +03:00
|
|
|
|
}: ToolbarSearchProps) {
|
2024-06-07 20:17:03 +03:00
|
|
|
|
const headMenu = useDropdown();
|
2024-09-27 12:03:13 +03:00
|
|
|
|
const userMenu = useDropdown();
|
|
|
|
|
const { users } = useUsers();
|
|
|
|
|
|
|
|
|
|
const userActive = useMemo(
|
|
|
|
|
() => isOwned !== undefined || isEditor !== undefined || filterUser !== undefined,
|
|
|
|
|
[isOwned, isEditor, filterUser]
|
|
|
|
|
);
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
|
|
const handleChange = useCallback(
|
|
|
|
|
(newValue: LocationHead | undefined) => {
|
|
|
|
|
headMenu.hide();
|
|
|
|
|
setHead(newValue);
|
|
|
|
|
},
|
|
|
|
|
[headMenu, setHead]
|
|
|
|
|
);
|
|
|
|
|
|
2024-06-19 22:09:31 +03:00
|
|
|
|
const handleToggleFolder = useCallback(() => {
|
|
|
|
|
headMenu.hide();
|
|
|
|
|
toggleFolderMode();
|
|
|
|
|
}, [headMenu, toggleFolderMode]);
|
|
|
|
|
|
|
|
|
|
const handleFolderClick = useCallback(
|
|
|
|
|
(event: CProps.EventMouse) => {
|
2024-06-21 11:16:47 +03:00
|
|
|
|
if (event.ctrlKey || event.metaKey) {
|
2024-06-19 22:09:31 +03:00
|
|
|
|
toggleFolderMode();
|
|
|
|
|
} else {
|
|
|
|
|
headMenu.toggle();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
[headMenu, toggleFolderMode]
|
|
|
|
|
);
|
|
|
|
|
|
2024-06-07 20:17:03 +03:00
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
className={clsx(
|
|
|
|
|
'sticky top-0', // prettier: split lines
|
2024-09-15 21:18:32 +03:00
|
|
|
|
'h-[2.2rem]',
|
|
|
|
|
'flex items-center gap-3',
|
2024-06-07 20:17:03 +03:00
|
|
|
|
'border-b',
|
|
|
|
|
'text-sm',
|
|
|
|
|
'clr-input'
|
|
|
|
|
)}
|
|
|
|
|
>
|
2024-08-21 16:49:04 +03:00
|
|
|
|
<div
|
2024-09-15 21:18:32 +03:00
|
|
|
|
className={clsx(
|
|
|
|
|
'ml-3 pt-1 self-center',
|
2024-09-27 12:03:13 +03:00
|
|
|
|
'min-w-[4.5rem] sm:min-w-[7.4rem]',
|
2024-09-15 21:18:32 +03:00
|
|
|
|
'select-none',
|
|
|
|
|
'whitespace-nowrap'
|
|
|
|
|
)}
|
2024-08-21 16:49:04 +03:00
|
|
|
|
>
|
2024-06-07 20:17:03 +03:00
|
|
|
|
{filtered} из {total}
|
|
|
|
|
</div>
|
|
|
|
|
|
2024-09-27 12:03:13 +03:00
|
|
|
|
<div className='cc-icons'>
|
|
|
|
|
<MiniButton
|
|
|
|
|
title='Видимость'
|
|
|
|
|
icon={<VisibilityIcon value={true} className={tripleToggleColor(isVisible)} />}
|
|
|
|
|
onClick={toggleVisible}
|
|
|
|
|
/>
|
2024-06-18 15:06:52 +03:00
|
|
|
|
|
2024-09-27 12:03:13 +03:00
|
|
|
|
<div ref={userMenu.ref} className='flex'>
|
2024-06-18 15:06:52 +03:00
|
|
|
|
<MiniButton
|
2024-09-27 12:03:13 +03:00
|
|
|
|
title='Поиск пользователя'
|
|
|
|
|
hideTitle={userMenu.isOpen}
|
|
|
|
|
icon={<IconUserSearch size='1.25rem' className={userActive ? 'icon-green' : 'icon-primary'} />}
|
|
|
|
|
onClick={userMenu.toggle}
|
2024-06-18 15:06:52 +03:00
|
|
|
|
/>
|
2024-09-27 12:03:13 +03:00
|
|
|
|
<Dropdown isOpen={userMenu.isOpen}>
|
|
|
|
|
<DropdownButton
|
|
|
|
|
text='Я - Владелец'
|
|
|
|
|
icon={<IconOwner size='1.25rem' className={tripleToggleColor(isOwned)} />}
|
|
|
|
|
onClick={toggleOwned}
|
|
|
|
|
/>
|
|
|
|
|
<DropdownButton
|
|
|
|
|
text='Я - Редактор'
|
|
|
|
|
icon={<IconEditor size='1.25rem' className={tripleToggleColor(isEditor)} />}
|
|
|
|
|
onClick={toggleEditor}
|
|
|
|
|
/>
|
|
|
|
|
<motion.div className='px-1 pb-1' variants={animateDropdownItem}>
|
|
|
|
|
<SelectUser
|
|
|
|
|
noBorder
|
|
|
|
|
placeholder='Выберите владельца'
|
|
|
|
|
className='min-w-[15rem] text-sm'
|
|
|
|
|
items={users}
|
|
|
|
|
value={filterUser}
|
|
|
|
|
onSelectValue={setFilterUser}
|
|
|
|
|
/>
|
|
|
|
|
</motion.div>
|
|
|
|
|
</Dropdown>
|
2024-06-14 21:43:05 +03:00
|
|
|
|
</div>
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
2024-09-27 12:03:13 +03:00
|
|
|
|
<MiniButton
|
|
|
|
|
title='Сбросить фильтры'
|
|
|
|
|
icon={<IconFilterReset size='1.25rem' className='icon-primary' />}
|
|
|
|
|
onClick={resetFilter}
|
|
|
|
|
disabled={!hasCustomFilter}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className='flex h-full flex-grow pr-4'>
|
2024-06-07 20:17:03 +03:00
|
|
|
|
<SearchBar
|
|
|
|
|
id='library_search'
|
|
|
|
|
placeholder='Поиск'
|
|
|
|
|
noBorder
|
2024-09-27 12:03:13 +03:00
|
|
|
|
className={clsx('min-w-[7rem] sm:min-w-[10rem] max-w-[20rem]', folderMode && 'flex-grow')}
|
2024-06-07 20:17:03 +03:00
|
|
|
|
value={query}
|
|
|
|
|
onChange={setQuery}
|
|
|
|
|
/>
|
2024-06-19 22:09:31 +03:00
|
|
|
|
{!folderMode ? (
|
|
|
|
|
<div ref={headMenu.ref} className='flex items-center h-full py-1 select-none'>
|
|
|
|
|
<SelectorButton
|
|
|
|
|
transparent
|
|
|
|
|
className='h-full rounded-lg'
|
|
|
|
|
titleHtml={(head ? describeLocationHead(head) : 'Выберите каталог') + '<br/>Ctrl + клик - Проводник'}
|
|
|
|
|
hideTitle={headMenu.isOpen}
|
|
|
|
|
icon={
|
|
|
|
|
head ? (
|
|
|
|
|
<LocationIcon value={head} size='1.25rem' />
|
|
|
|
|
) : (
|
2024-09-27 12:03:13 +03:00
|
|
|
|
<IconFolderSearch size='1.25rem' className='clr-text-controls' />
|
2024-06-19 22:09:31 +03:00
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
onClick={handleFolderClick}
|
|
|
|
|
text={head ?? '//'}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<Dropdown isOpen={headMenu.isOpen} stretchLeft className='z-modalTooltip'>
|
2024-09-27 12:03:13 +03:00
|
|
|
|
<DropdownButton title='Переключение в режим Проводник' onClick={handleToggleFolder}>
|
2024-06-20 11:50:26 +03:00
|
|
|
|
<div className='inline-flex items-center gap-3'>
|
|
|
|
|
<IconFolderTree size='1rem' className='clr-text-controls' />
|
|
|
|
|
<span>проводник...</span>
|
|
|
|
|
</div>
|
|
|
|
|
</DropdownButton>
|
2024-06-19 22:09:31 +03:00
|
|
|
|
<DropdownButton className='w-[10rem]' onClick={() => handleChange(undefined)}>
|
|
|
|
|
<div className='inline-flex items-center gap-3'>
|
|
|
|
|
<IconFolder size='1rem' className='clr-text-controls' />
|
|
|
|
|
<span>отображать все</span>
|
|
|
|
|
</div>
|
|
|
|
|
</DropdownButton>
|
|
|
|
|
{Object.values(LocationHead).map((head, index) => {
|
|
|
|
|
return (
|
|
|
|
|
<DropdownButton
|
|
|
|
|
className='w-[10rem]'
|
|
|
|
|
key={`${prefixes.location_head_list}${index}`}
|
|
|
|
|
onClick={() => handleChange(head)}
|
|
|
|
|
title={describeLocationHead(head)}
|
|
|
|
|
>
|
|
|
|
|
<div className='inline-flex items-center gap-3'>
|
|
|
|
|
<LocationIcon value={head} size='1rem' />
|
|
|
|
|
{labelLocationHead(head)}
|
|
|
|
|
</div>
|
|
|
|
|
</DropdownButton>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</Dropdown>
|
|
|
|
|
</div>
|
|
|
|
|
) : null}
|
|
|
|
|
{!folderMode ? (
|
|
|
|
|
<SearchBar
|
|
|
|
|
id='path_search'
|
|
|
|
|
placeholder='Путь'
|
|
|
|
|
noIcon
|
|
|
|
|
noBorder
|
2024-09-27 12:03:13 +03:00
|
|
|
|
className='w-[4.5rem] sm:w-[5rem] flex-grow'
|
2024-06-19 22:09:31 +03:00
|
|
|
|
value={path}
|
|
|
|
|
onChange={setPath}
|
2024-06-07 20:17:03 +03:00
|
|
|
|
/>
|
2024-06-19 22:09:31 +03:00
|
|
|
|
) : null}
|
2024-06-07 20:17:03 +03:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-26 19:47:05 +03:00
|
|
|
|
export default ToolbarSearch;
|