30 lines
875 B
TypeScript
30 lines
875 B
TypeScript
import { useQuery } from './utils';
|
|
import { useMemo } from 'react';
|
|
import { type Section, SectionRow } from './SectionRow';
|
|
|
|
function getEndpoint(searchTerm: string) {
|
|
return `/admin/autocomplete/sections?term=${searchTerm}`;
|
|
}
|
|
|
|
export function AutocompleteSections({ searchTerm }: { searchTerm: string }) {
|
|
const { data } = useQuery<Section[]>(useMemo(() => getEndpoint(searchTerm), [searchTerm]), { cache: false });
|
|
|
|
return (
|
|
<>
|
|
{data?.map((section, i) => (
|
|
<SectionRow
|
|
section={section}
|
|
hasSubsections={!!section.has_subsections}
|
|
key={`as${section.id}-${i}`}
|
|
/>
|
|
))}
|
|
|
|
{!!data && data.length === 0 && (
|
|
<div className="AutocompleteWindow__not-found">
|
|
<strong>Sekce nenalezena</strong>
|
|
</div>
|
|
)}
|
|
</>
|
|
);
|
|
}
|