2024-06-07 20:17:03 +03:00
|
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import clsx from 'clsx';
|
|
|
|
|
|
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';
|
|
|
|
|
import useDropdown from '@/hooks/useDropdown';
|
|
|
|
|
import { LocationHead } from '@/models/library';
|
2025-01-15 16:06:18 +03:00
|
|
|
|
import { useHasCustomFilter, useLibrarySearchStore } from '@/stores/librarySearch';
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-15 16:06:18 +03:00
|
|
|
|
function ToolbarSearch({ total, filtered }: ToolbarSearchProps) {
|
2024-06-07 20:17:03 +03:00
|
|
|
|
const headMenu = useDropdown();
|
2024-09-27 12:03:13 +03:00
|
|
|
|
const userMenu = useDropdown();
|
|
|
|
|
|
2025-01-15 16:06:18 +03:00
|
|
|
|
const query = useLibrarySearchStore(state => state.query);
|
|
|
|
|
const setQuery = useLibrarySearchStore(state => state.setQuery);
|
|
|
|
|
const path = useLibrarySearchStore(state => state.path);
|
|
|
|
|
const setPath = useLibrarySearchStore(state => state.setPath);
|
|
|
|
|
const head = useLibrarySearchStore(state => state.head);
|
|
|
|
|
const setHead = useLibrarySearchStore(state => state.setHead);
|
|
|
|
|
const folderMode = useLibrarySearchStore(state => state.folderMode);
|
|
|
|
|
const toggleFolderMode = useLibrarySearchStore(state => state.toggleFolderMode);
|
|
|
|
|
const isOwned = useLibrarySearchStore(state => state.isOwned);
|
|
|
|
|
const toggleOwned = useLibrarySearchStore(state => state.toggleOwned);
|
|
|
|
|
const isEditor = useLibrarySearchStore(state => state.isEditor);
|
|
|
|
|
const toggleEditor = useLibrarySearchStore(state => state.toggleEditor);
|
|
|
|
|
const isVisible = useLibrarySearchStore(state => state.isVisible);
|
|
|
|
|
const toggleVisible = useLibrarySearchStore(state => state.toggleVisible);
|
|
|
|
|
const filterUser = useLibrarySearchStore(state => state.filterUser);
|
|
|
|
|
const setFilterUser = useLibrarySearchStore(state => state.setFilterUser);
|
|
|
|
|
|
|
|
|
|
const resetFilter = useLibrarySearchStore(state => state.resetFilter);
|
|
|
|
|
const hasCustomFilter = useHasCustomFilter();
|
|
|
|
|
|
2024-12-13 21:30:49 +03:00
|
|
|
|
const userActive = isOwned !== undefined || isEditor !== undefined || filterUser !== undefined;
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
2024-12-13 21:30:49 +03:00
|
|
|
|
function handleChange(newValue: LocationHead | undefined) {
|
|
|
|
|
headMenu.hide();
|
2025-01-15 16:06:18 +03:00
|
|
|
|
setHead(newValue);
|
2024-12-13 21:30:49 +03:00
|
|
|
|
}
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
2024-12-13 21:30:49 +03:00
|
|
|
|
function handleToggleFolder() {
|
2024-06-19 22:09:31 +03:00
|
|
|
|
headMenu.hide();
|
|
|
|
|
toggleFolderMode();
|
2024-12-13 21:30:49 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleFolderClick(event: CProps.EventMouse) {
|
|
|
|
|
if (event.ctrlKey || event.metaKey) {
|
|
|
|
|
toggleFolderMode();
|
|
|
|
|
} else {
|
|
|
|
|
headMenu.toggle();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-19 22:09:31 +03:00
|
|
|
|
|
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}
|
|
|
|
|
/>
|
2024-12-12 13:17:24 +03:00
|
|
|
|
<SelectUser
|
|
|
|
|
noBorder
|
|
|
|
|
placeholder='Выберите владельца'
|
|
|
|
|
className='min-w-[15rem] text-sm mx-1 mb-1'
|
|
|
|
|
value={filterUser}
|
2025-01-15 16:06:18 +03:00
|
|
|
|
onSelectValue={setFilterUser}
|
2024-12-12 13:17:24 +03:00
|
|
|
|
/>
|
2024-09-27 12:03:13 +03:00
|
|
|
|
</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-11-21 15:09:31 +03:00
|
|
|
|
query={query}
|
2025-01-15 16:06:18 +03:00
|
|
|
|
onChangeQuery={setQuery}
|
2024-06-07 20:17:03 +03:00
|
|
|
|
/>
|
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-11-21 15:09:31 +03:00
|
|
|
|
query={path}
|
2025-01-15 16:06:18 +03:00
|
|
|
|
onChangeQuery={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;
|