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';
|
|
|
|
|
import { useConceptNavigation } from '@/context/NagivationContext';
|
|
|
|
|
import { ILibraryFilter } from '@/models/miscelanious';
|
|
|
|
|
import { LibraryFilterStrategy } from '@/models/miscelanious';
|
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-08-27 15:39:49 +03:00
|
|
|
|
total: number
|
|
|
|
|
filtered: number
|
2023-08-26 19:39:49 +03:00
|
|
|
|
setFilter: React.Dispatch<React.SetStateAction<ILibraryFilter>>
|
2023-09-11 21:06:51 +03:00
|
|
|
|
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(
|
|
|
|
|
(value: LibraryFilterStrategy) => {
|
2023-12-13 14:32:57 +03:00
|
|
|
|
if (value !== strategy) {
|
|
|
|
|
router.push(`/library?filter=${value}`);
|
2023-08-27 15:39:49 +03:00
|
|
|
|
}
|
2023-12-13 14:32:57 +03:00
|
|
|
|
}, [strategy, router]);
|
2023-08-27 15:39:49 +03:00
|
|
|
|
|
2023-08-26 19:39:49 +03:00
|
|
|
|
return (
|
2023-12-15 17:34:50 +03:00
|
|
|
|
<div className={clsx(
|
|
|
|
|
'sticky top-0',
|
|
|
|
|
'w-full max-h-[2.3rem]',
|
2023-12-17 20:19:28 +03:00
|
|
|
|
'pr-40 flex items-stretch',
|
2023-12-15 17:34:50 +03:00
|
|
|
|
'border-b',
|
|
|
|
|
'clr-input'
|
|
|
|
|
)}>
|
|
|
|
|
<div className={clsx(
|
|
|
|
|
'min-w-[10rem]',
|
|
|
|
|
'px-2 self-center',
|
|
|
|
|
'select-none',
|
|
|
|
|
'whitespace-nowrap',
|
|
|
|
|
)}>
|
2023-11-27 11:33:34 +03:00
|
|
|
|
Фильтр
|
|
|
|
|
<span className='ml-2'>
|
|
|
|
|
{filtered} из {total}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
2023-12-15 17:34:50 +03:00
|
|
|
|
<div className={clsx(
|
2023-12-17 20:19:28 +03:00
|
|
|
|
'flex-grow',
|
2023-12-15 17:34:50 +03:00
|
|
|
|
'flex gap-1 justify-center items-center'
|
|
|
|
|
)}>
|
2023-12-08 19:24:08 +03:00
|
|
|
|
<ConceptSearch noBorder
|
2023-12-18 19:42:27 +03:00
|
|
|
|
className='min-w-[10rem]'
|
2023-12-08 19:24:08 +03:00
|
|
|
|
value={query}
|
|
|
|
|
onChange={handleChangeQuery}
|
|
|
|
|
/>
|
2023-11-27 11:33:34 +03:00
|
|
|
|
<PickerStrategy
|
|
|
|
|
value={strategy}
|
|
|
|
|
onChange={handleChangeStrategy}
|
|
|
|
|
/>
|
2023-08-26 19:39:49 +03:00
|
|
|
|
</div>
|
2023-11-27 11:33:34 +03:00
|
|
|
|
</div>);
|
2023-08-26 19:39:49 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-12-13 14:32:57 +03:00
|
|
|
|
export default SearchPanel;
|