2022-02-08 12:49:51 +01:00
|
|
|
import React from 'react';
|
|
|
|
import { QueryClientProvider } from 'react-query';
|
|
|
|
import type { FeatureCollection, Geometry } from 'geojson';
|
|
|
|
|
|
|
|
import ComboSearch, { ComboSearchProps } from './ComboSearch';
|
|
|
|
import { queryClient } from './shared/queryClient';
|
|
|
|
|
|
|
|
type RawResult = FeatureCollection<Geometry, { label: string }>;
|
|
|
|
type AdresseResult = RawResult['features'][0];
|
|
|
|
type ComboAdresseSearchProps = Omit<
|
|
|
|
ComboSearchProps<AdresseResult>,
|
|
|
|
'minimumInputLength' | 'transformResult' | 'transformResults' | 'scope'
|
|
|
|
>;
|
|
|
|
|
|
|
|
export default function ComboAdresseSearch({
|
|
|
|
allowInputValues = true,
|
|
|
|
...props
|
|
|
|
}: ComboAdresseSearchProps) {
|
|
|
|
return (
|
|
|
|
<QueryClientProvider client={queryClient}>
|
|
|
|
<ComboSearch<AdresseResult>
|
|
|
|
{...props}
|
|
|
|
allowInputValues={allowInputValues}
|
|
|
|
scope="adresse"
|
|
|
|
minimumInputLength={2}
|
|
|
|
transformResult={({ properties: { label } }) => [label, label, label]}
|
|
|
|
transformResults={(_, result) => (result as RawResult).features}
|
2022-10-10 21:09:23 +02:00
|
|
|
debounceDelay={300}
|
2022-02-08 12:49:51 +01:00
|
|
|
/>
|
|
|
|
</QueryClientProvider>
|
|
|
|
);
|
|
|
|
}
|