2024-06-07 20:17:03 +03:00
|
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import clsx from 'clsx';
|
|
|
|
|
|
2025-02-26 00:16:22 +03:00
|
|
|
|
import { SelectUser } from '@/features/users/components';
|
2025-02-12 21:36:03 +03:00
|
|
|
|
|
2025-02-10 01:32:16 +03:00
|
|
|
|
import { MiniButton, SelectorButton } from '@/components/Control';
|
|
|
|
|
import { Dropdown, DropdownButton, useDropdown } from '@/components/Dropdown';
|
2024-09-27 12:03:13 +03:00
|
|
|
|
import {
|
|
|
|
|
IconEditor,
|
|
|
|
|
IconFilterReset,
|
|
|
|
|
IconFolder,
|
|
|
|
|
IconFolderSearch,
|
|
|
|
|
IconFolderTree,
|
|
|
|
|
IconOwner,
|
|
|
|
|
IconUserSearch
|
|
|
|
|
} from '@/components/Icons';
|
2025-02-12 13:41:58 +03:00
|
|
|
|
import { SearchBar } from '@/components/Input';
|
2024-06-21 11:16:47 +03:00
|
|
|
|
import { prefixes } from '@/utils/constants';
|
2024-06-07 20:17:03 +03:00
|
|
|
|
import { tripleToggleColor } from '@/utils/utils';
|
|
|
|
|
|
2025-02-26 00:16:22 +03:00
|
|
|
|
import { IconItemVisibility } from '../../components/IconItemVisibility';
|
|
|
|
|
import { IconLocationHead } from '../../components/IconLocationHead';
|
2025-02-11 20:56:11 +03:00
|
|
|
|
import { describeLocationHead, labelLocationHead } from '../../labels';
|
2025-02-10 01:32:16 +03:00
|
|
|
|
import { LocationHead } from '../../models/library';
|
|
|
|
|
import { useHasCustomFilter, useLibrarySearchStore } from '../../stores/librarySearch';
|
|
|
|
|
|
2024-06-26 19:47:05 +03:00
|
|
|
|
interface ToolbarSearchProps {
|
2024-06-07 20:17:03 +03:00
|
|
|
|
total: number;
|
|
|
|
|
filtered: number;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-19 23:29:45 +03:00
|
|
|
|
export 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();
|
|
|
|
|
|
2025-02-19 22:32:50 +03:00
|
|
|
|
const userActive = isOwned !== null || isEditor !== null || filterUser !== null;
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
2025-02-19 22:32:50 +03:00
|
|
|
|
function handleChange(newValue: LocationHead | null) {
|
2024-12-13 21:30:49 +03:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2025-02-22 14:03:13 +03:00
|
|
|
|
function handleFolderClick(event: React.MouseEvent<Element>) {
|
2024-12-13 21:30:49 +03:00
|
|
|
|
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(
|
2025-01-23 19:41:31 +03:00
|
|
|
|
'sticky top-0', //
|
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='Видимость'
|
2025-02-26 00:16:22 +03:00
|
|
|
|
icon={<IconItemVisibility value={true} className={tripleToggleColor(isVisible)} />}
|
2024-09-27 12:03:13 +03:00
|
|
|
|
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-02-04 20:35:18 +03:00
|
|
|
|
onChange={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>
|
|
|
|
|
|
2025-02-20 20:22:05 +03:00
|
|
|
|
<div className='flex h-full grow pr-4'>
|
2024-06-07 20:17:03 +03:00
|
|
|
|
<SearchBar
|
|
|
|
|
id='library_search'
|
|
|
|
|
placeholder='Поиск'
|
|
|
|
|
noBorder
|
2025-02-20 20:22:05 +03:00
|
|
|
|
className={clsx('min-w-[7rem] sm:min-w-[10rem] max-w-[20rem]', folderMode && '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 ? (
|
2025-02-26 00:16:22 +03:00
|
|
|
|
<IconLocationHead value={head} size='1.25rem' />
|
2024-06-19 22:09:31 +03:00
|
|
|
|
) : (
|
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 ?? '//'}
|
|
|
|
|
/>
|
|
|
|
|
|
2025-02-25 13:24:06 +03:00
|
|
|
|
<Dropdown isOpen={headMenu.isOpen} stretchLeft className='z-modal-tooltip'>
|
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>
|
2025-02-19 22:32:50 +03:00
|
|
|
|
<DropdownButton className='w-[10rem]' onClick={() => handleChange(null)}>
|
2024-06-19 22:09:31 +03:00
|
|
|
|
<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'>
|
2025-02-26 00:16:22 +03:00
|
|
|
|
<IconLocationHead value={head} size='1rem' />
|
2024-06-19 22:09:31 +03:00
|
|
|
|
{labelLocationHead(head)}
|
|
|
|
|
</div>
|
|
|
|
|
</DropdownButton>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</Dropdown>
|
|
|
|
|
</div>
|
|
|
|
|
) : null}
|
|
|
|
|
{!folderMode ? (
|
|
|
|
|
<SearchBar
|
|
|
|
|
id='path_search'
|
|
|
|
|
placeholder='Путь'
|
|
|
|
|
noIcon
|
|
|
|
|
noBorder
|
2025-02-20 20:22:05 +03:00
|
|
|
|
className='w-[4.5rem] sm:w-[5rem] 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>
|
|
|
|
|
);
|
|
|
|
|
}
|