Skip to content
Snippets Groups Projects
Commit 8b3b0b65 authored by Loïc Poullain's avatar Loïc Poullain
Browse files

Enable commune search

parent 88483e4a
No related branches found
No related tags found
1 merge request!92Activer la recherche des communes
......@@ -24,8 +24,6 @@ type Props = PropsFromRedux & {}
class Results extends PureComponent<Props> {
render() {
const { communesTypes } = this.props;
const url = new URLSearchParams(window.location.search);
const isSearchVisible = url.has("search");
return (
<div className={styles.container}>
<Grid container spacing={3}>
......@@ -48,15 +46,13 @@ class Results extends PureComponent<Props> {
habitants={communeType.habitants}
index={index}
name={communeType.name}
potentielFinancier={communeType.potentielFinancier}
potentielFinancierParHab={communeType.potentielFinancierParHab}
/>
</Grid>
))}
{isSearchVisible && (
<Grid item lg={4} md={6} sm={6} xl={3} xs={12}>
<CommuneSearch />
</Grid>
)}
</Grid>
</div>
);
......
......@@ -8,13 +8,7 @@ import { PureComponent } from "react";
// eslint-disable-next-line no-unused-vars
import { Commune } from "../../../../../redux/reducers/descriptions/dotations";
// import request from "../../../../common/utils/request";
function sleep(delay = 0) {
return new Promise((resolve) => {
setTimeout(resolve, delay);
});
}
import request from "../../../../common/utils/request";
interface Props {
onChange: (commune: Commune) => void;
......@@ -26,9 +20,7 @@ interface State {
value: Commune | null;
}
// interface ResponseBody {
// communes: Commune[]
// }
type ResponseBody = Commune[];
export class SearchInput extends PureComponent<Props, State> {
constructor(props) {
......@@ -45,39 +37,16 @@ export class SearchInput extends PureComponent<Props, State> {
async search(search: string): Promise<void> {
this.setState({ communes: null });
// await request
// .get(`/dotations?search=${encodeURI(search)}`)
// .then(({ communes }: ResponseBody) => {
// this.setState({ communes });
// })
// .catch(() => {});
if (!search) {
return;
}
await sleep(1e3);
this.setState({
communes: [
{
code: "76384",
departement: "Seine-Maritime",
habitants: 9101,
name: "Lillebonne",
potentielFinancier: 2188.612857,
},
{
code: "76214",
departement: "Seine-Maritime",
habitants: 262,
name: "Dénestanville",
potentielFinancier: 706.242647,
},
{
code: "77186",
departement: "Seine-et-Marne",
habitants: 15417,
name: "Fontainebleau",
potentielFinancier: 1110.296193,
},
],
});
await request
.get(`/search?commune=${encodeURI(search)}`)
.then((communes: ResponseBody) => {
this.setState({ communes });
})
.catch(() => {});
}
render() {
......
......@@ -41,7 +41,7 @@ type Props = PropsFromRedux & Commune & {
class CommuneType extends PureComponent<Props> {
render() {
const {
departement, habitants, index, isFetching, name, potentielFinancier, remove,
departement, habitants, index, isFetching, name, potentielFinancierParHab, remove,
} = this.props;
return (
<Card
......@@ -52,7 +52,7 @@ class CommuneType extends PureComponent<Props> {
<HabitantLabel habitants={habitants} />
</div>
<PotentielFinancier
potentielFinancier={potentielFinancier}
potentielFinancier={potentielFinancierParHab}
/>
</Fragment>
)}
......
......@@ -6,7 +6,7 @@ export interface Commune {
name: string;
departement: string;
habitants: number;
potentielFinancier: number;
potentielFinancierParHab: number;
}
const DEFAULT_STATE: Commune[] = [
......@@ -15,28 +15,28 @@ const DEFAULT_STATE: Commune[] = [
departement: "Seine-Maritime",
habitants: 9101,
name: "Lillebonne",
potentielFinancier: 2188.612857,
potentielFinancierParHab: 2188.612857,
},
{
code: "76214",
departement: "Seine-Maritime",
habitants: 262,
name: "Dénestanville",
potentielFinancier: 706.242647,
potentielFinancierParHab: 706.242647,
},
{
code: "77186",
departement: "Seine-et-Marne",
habitants: 15417,
name: "Fontainebleau",
potentielFinancier: 1110.296193,
potentielFinancierParHab: 1110.296193,
},
{
code: "01012",
departement: "Ain",
habitants: 330,
name: "Aranc",
potentielFinancier: 956.960606,
potentielFinancierParHab: 820.251948,
},
];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment