2023-12-13 14:32:57 +03:00
|
|
|
|
'use client';
|
2023-08-26 19:39:49 +03:00
|
|
|
|
|
2023-12-15 17:34:50 +03:00
|
|
|
|
import clsx from 'clsx';
|
2023-12-13 14:32:57 +03:00
|
|
|
|
import { useCallback } from 'react';
|
2023-08-27 15:39:49 +03:00
|
|
|
|
|
2023-12-13 14:32:57 +03:00
|
|
|
|
import ConceptSearch from '@/components/Common/ConceptSearch';
|
2023-12-26 14:23:51 +03:00
|
|
|
|
import { useConceptNavigation } from '@/context/NavigationContext';
|
|
|
|
|
import { ILibraryFilter } from '@/models/miscellaneous';
|
|
|
|
|
import { LibraryFilterStrategy } from '@/models/miscellaneous';
|
2023-08-27 15:39:49 +03:00
|
|
|
|
|
2023-12-13 14:32:57 +03:00
|
|
|
|
import PickerStrategy from './PickerStrategy';
|
2023-08-26 19:39:49 +03:00
|
|
|
|
|
|
|
|
|
interface SearchPanelProps {
|
2023-12-28 14:04:44 +03:00
|
|
|
|
total: number;
|
|
|
|
|
filtered: number;
|
|
|
|
|
setFilter: React.Dispatch<React.SetStateAction<ILibraryFilter>>;
|
|
|
|
|
query: string;
|
|
|
|
|
setQuery: React.Dispatch<React.SetStateAction<string>>;
|
|
|
|
|
strategy: LibraryFilterStrategy;
|
2023-08-26 19:39:49 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-12-13 14:32:57 +03:00
|
|
|
|
function SearchPanel({ total, filtered, query, setQuery, strategy, setFilter }: SearchPanelProps) {
|
|
|
|
|
const router = useConceptNavigation();
|
2023-08-26 19:39:49 +03:00
|
|
|
|
|
2023-12-08 19:24:08 +03:00
|
|
|
|
function handleChangeQuery(newQuery: string) {
|
2023-08-27 00:19:19 +03:00
|
|
|
|
setQuery(newQuery);
|
2023-09-09 20:36:55 +03:00
|
|
|
|
setFilter(prev => ({
|
|
|
|
|
query: newQuery,
|
|
|
|
|
is_owned: prev.is_owned,
|
|
|
|
|
is_common: prev.is_common,
|
|
|
|
|
is_canonical: prev.is_canonical,
|
|
|
|
|
is_subscribed: prev.is_subscribed,
|
|
|
|
|
is_personal: prev.is_personal
|
|
|
|
|
}));
|
2023-08-27 00:19:19 +03:00
|
|
|
|
}
|
2023-08-26 19:39:49 +03:00
|
|
|
|
|
2023-08-27 15:39:49 +03:00
|
|
|
|
const handleChangeStrategy = useCallback(
|
2023-12-28 14:04:44 +03:00
|
|
|
|
(value: LibraryFilterStrategy) => {
|
|
|
|
|
if (value !== strategy) {
|
|
|
|
|
router.push(`/library?filter=${value}`);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
[strategy, router]
|
|
|
|
|
);
|
2023-08-27 15:39:49 +03:00
|
|
|
|
|
2023-08-26 19:39:49 +03:00
|
|
|
|
return (
|
2023-12-28 14:04:44 +03:00
|
|
|
|
<div className={clsx('sticky top-0', 'w-full max-h-[2.3rem]', 'pr-40 flex', 'border-b', 'clr-input')}>
|
|
|
|
|
<div className={clsx('min-w-[10rem]', 'px-2 self-center', 'select-none', 'whitespace-nowrap')}>
|
|
|
|
|
Фильтр
|
|
|
|
|
<span className='ml-2'>
|
|
|
|
|
{filtered} из {total}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className={clsx('flex-grow', 'flex gap-1 justify-center items-center')}>
|
|
|
|
|
<ConceptSearch noBorder className='min-w-[10rem]' value={query} onChange={handleChangeQuery} />
|
|
|
|
|
<PickerStrategy value={strategy} onChange={handleChangeStrategy} />
|
|
|
|
|
</div>
|
2023-11-27 11:33:34 +03:00
|
|
|
|
</div>
|
2023-12-28 14:04:44 +03:00
|
|
|
|
);
|
2023-08-26 19:39:49 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-12-28 14:04:44 +03:00
|
|
|
|
export default SearchPanel;
|