-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: mise en palce de l'outil de recherche
- Loading branch information
Showing
12 changed files
with
170 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { fr } from "@codegouvfr/react-dsfr"; | ||
import MuiDsfrThemeProvider from "@codegouvfr/react-dsfr/mui"; | ||
import Autocomplete from "@mui/material/Autocomplete"; | ||
import TextField from "@mui/material/TextField"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { declareComponentKeys } from "i18nifty"; | ||
import { FC } from "react"; | ||
import { useDebounceValue } from "usehooks-ts"; | ||
import { SearchResult } from "../../../../@types/app_espaceco"; | ||
import { Translations, useTranslation } from "../../../../i18n/i18n"; | ||
import RQKeys from "../../../../modules/espaceco/RQKeys"; | ||
import { jsonFetch } from "../../../../modules/jsonFetch"; | ||
|
||
type SearchProps = { | ||
filter: Record<string, unknown>; | ||
onChange?: (value: string | null) => void; | ||
}; | ||
|
||
const autocompleteUrl = "https://data.geopf.fr/geocodage/completion"; | ||
|
||
const Search: FC<SearchProps> = ({ filter, onChange }) => { | ||
const { t } = useTranslation("Search"); | ||
|
||
const [text, setText] = useDebounceValue("", 500); | ||
|
||
const searchQuery = useQuery<SearchResult>({ | ||
queryKey: RQKeys.searchAddress(text), | ||
queryFn: ({ signal }) => { | ||
const qParams = new URLSearchParams({ text: text, ...filter }).toString(); | ||
return jsonFetch<SearchResult>(`${autocompleteUrl}?${qParams}`, { signal }); | ||
}, | ||
enabled: text.length >= 3, | ||
staleTime: 10 * 1000, | ||
}); | ||
console.log(searchQuery.data); | ||
|
||
return ( | ||
<div> | ||
<span className={fr.cx("fr-hint-text")}>{t("position_hint")}</span> | ||
<MuiDsfrThemeProvider> | ||
<Autocomplete | ||
loading={searchQuery.isPending} | ||
loadingText={t("loading")} | ||
noOptionsText={t("no_results")} | ||
getOptionLabel={(option) => option.fulltext} | ||
options={searchQuery.data?.results ?? []} | ||
renderInput={(params) => ( | ||
<TextField | ||
{...params} | ||
InputProps={{ | ||
...params.InputProps, | ||
type: "search", | ||
}} | ||
/> | ||
)} | ||
isOptionEqualToValue={(option, v) => option.fulltext === v.fulltext} | ||
onInputChange={(_, v) => setText(v)} | ||
// onChange={(_, v) => onChange(v)} | ||
/> | ||
</MuiDsfrThemeProvider> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Search; | ||
|
||
// traductions | ||
export const { i18n } = declareComponentKeys<"position_hint" | "no_results" | "loading">()("Search"); | ||
|
||
export const SearchFrTranslations: Translations<"fr">["Search"] = { | ||
position_hint: "Fixer la position et définissez le niveau de zoom (utilisez votre souris ou la barre de recherche ci-dessous", | ||
no_results: "Aucun résultat", | ||
loading: "Recherche en cours ...", | ||
}; | ||
|
||
export const SearchEnTranslations: Translations<"en">["Search"] = { | ||
position_hint: "Fix the position and set the zoom level (use your mouse or the search bar below", | ||
no_results: "No results", | ||
loading: "Searching ...", | ||
}; |
38 changes: 38 additions & 0 deletions
38
assets/espaceco/pages/communities/management/ZoomAndCentering.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { FC } from "react"; | ||
import { CommunityResponseDTO } from "../../../../@types/espaceco"; | ||
import WKT from "ol/format/WKT"; | ||
import { fr } from "@codegouvfr/react-dsfr"; | ||
import Input from "@codegouvfr/react-dsfr/Input"; | ||
import { useTranslation } from "../../../../i18n/i18n"; | ||
import Search from "./Search"; | ||
|
||
type ZoomAndCenteringProps = { | ||
community: CommunityResponseDTO; | ||
}; | ||
|
||
const ZoomAndCentering: FC<ZoomAndCenteringProps> = ({ community }) => { | ||
let point; | ||
if (community.position) { | ||
const feature = new WKT().readFeature(community.position, { | ||
dataProjection: "EPSG:4326", | ||
}); | ||
point = feature.getGeometry().getCoordinates(); | ||
} | ||
console.log(point); | ||
|
||
return ( | ||
<div className={fr.cx("fr-grid-row")}> | ||
<div className={fr.cx("fr-col-5")}> | ||
<Search | ||
filter={{ | ||
type: "PositionOfInterest,StreetAddress", | ||
maximumResponses: 10, | ||
}} | ||
/>{" "} | ||
</div> | ||
<div className={fr.cx("fr-col-7")}></div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ZoomAndCentering; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters