'use client'; import clsx from 'clsx'; import { SelectUser } from '@/features/users'; import { MiniButton, SelectorButton } from '@/components/Control'; import { LocationIcon, VisibilityIcon } from '@/components/DomainIcons'; import { Dropdown, DropdownButton, useDropdown } from '@/components/Dropdown'; import { IconEditor, IconFilterReset, IconFolder, IconFolderSearch, IconFolderTree, IconOwner, IconUserSearch } from '@/components/Icons'; import { SearchBar } from '@/components/Input'; import { CProps } from '@/components/props'; import { prefixes } from '@/utils/constants'; import { tripleToggleColor } from '@/utils/utils'; import { describeLocationHead, labelLocationHead } from '../../labels'; import { LocationHead } from '../../models/library'; import { useHasCustomFilter, useLibrarySearchStore } from '../../stores/librarySearch'; interface ToolbarSearchProps { total: number; filtered: number; } function ToolbarSearch({ total, filtered }: ToolbarSearchProps) { const headMenu = useDropdown(); const userMenu = useDropdown(); 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(); const userActive = isOwned !== undefined || isEditor !== undefined || filterUser !== undefined; function handleChange(newValue: LocationHead | undefined) { headMenu.hide(); setHead(newValue); } function handleToggleFolder() { headMenu.hide(); toggleFolderMode(); } function handleFolderClick(event: CProps.EventMouse) { if (event.ctrlKey || event.metaKey) { toggleFolderMode(); } else { headMenu.toggle(); } } return (
{filtered} из {total}
} onClick={toggleVisible} />
} onClick={userMenu.toggle} /> } onClick={toggleOwned} /> } onClick={toggleEditor} />
} onClick={resetFilter} disabled={!hasCustomFilter} />
{!folderMode ? (
Ctrl + клик - Проводник'} hideTitle={headMenu.isOpen} icon={ head ? ( ) : ( ) } onClick={handleFolderClick} text={head ?? '//'} />
проводник...
handleChange(undefined)}>
отображать все
{Object.values(LocationHead).map((head, index) => { return ( handleChange(head)} title={describeLocationHead(head)} >
{labelLocationHead(head)}
); })}
) : null} {!folderMode ? ( ) : null}
); } export default ToolbarSearch;