Skip to content

Commit

Permalink
startups: allow filtering out investigations
Browse files Browse the repository at this point in the history
Closes #21046.
  • Loading branch information
freesteph committed Feb 20, 2025
1 parent 3539ed5 commit 9fdc577
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 34 deletions.
7 changes: 7 additions & 0 deletions _includes/startups-filters.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@
<p class="fr-hint-text" id="{{include.prefix}}toggle-hint-text">Ces services sont déployés à l'ensemble du territoire national et ont atteint un seuil d'impact significatif.</p>
</div>
</div>
<div class="fr-grid-row">
<div class="fr-col fr-toggle">
<input type="checkbox" class="fr-toggle__input exclude-investigations" aria-describedby="exclude-investigations-toggle-hint-text" id="exclude-investigations-toggle" />
<label class="fr-toggle__label" for="exclude-investigations-toggle" data-fr-checked-label="Activé" data-fr-unchecked-label="Désactivé">Exclure les investigations</label>
<p class="fr-hint-text" id="exclude-investigations-toggle-hint-text">Les investigations sont des services numériques en devenir. À ce stade, l'équipe est souvent réduite.</p>
</div>
</div>
</div>
5 changes: 5 additions & 0 deletions _layouts/startups.html
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,9 @@ <h3><span class="phase-counter">{{ counter }}</span> <span class="phase-label">{
document.querySelectorAll(".select-impact").forEach((selectElement) => {
createNationalImpactSelect(selectElement, data, nationalImpactValue);
});

filters.excludeInvestigations = urlParams.get("exclude-investigations") == "true";

setupExcludeInvestigations();

</script>
73 changes: 39 additions & 34 deletions assets/additional/js/search-startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,15 @@ const filterCards = (startups) => {
)
.filter((startup) =>
filters.is_national_impact ? startupHasNationalImpact(startup) : true,
)
.filter((startup) =>
filters.excludeInvestigations ? startupIsNotInvestigation(startup) : true,
);
};

const startupIsNotInvestigation = (startup) =>
startup.phase !== "investigation";

const startupHasNationalImpact = (startup) =>
startup.events.find((event) => event.name === "national_impact");

Expand Down Expand Up @@ -238,16 +244,10 @@ const createIncubatorSelect = (selectElement, data, incubators, initValue) => {
selectElement.value = initValue;
onIncubatorChange(initValue);
}
selectElement.addEventListener("change", (e) => {
const value = e.target.value;
selectElement.addEventListener("change", ({ target: { value } }) => {
onIncubatorChange(value);
const urlParams = new URLSearchParams(window.location.search);
urlParams.set("incubateur", value);
history.replaceState(
null,
null,
`${window.location.origin + window.location.pathname}?${urlParams}`,
);

setLocationParam("incubateur", value);
});
};

Expand All @@ -274,13 +274,8 @@ const createUsertypesSelect = (selectElement, data, initValue) => {
selectElement.addEventListener("change", (e) => {
const value = e.target.value;
onUsertypesChange(value);
const urlParams = new URLSearchParams(window.location.search);
urlParams.set("usertypes", value);
history.replaceState(
null,
null,
`${window.location.origin + window.location.pathname}?${urlParams}`,
);

setLocationParam("usertypes", value);
});
};

Expand All @@ -303,16 +298,10 @@ const createThematiquesSelect = (selectElement, data, initValue) => {
selectElement.value = initValue;
onThematiquesChange(initValue);
}
selectElement.addEventListener("change", (e) => {
const value = e.target.value;
selectElement.addEventListener("change", ({ target: { value } }) => {
onThematiquesChange(value);
const urlParams = new URLSearchParams(window.location.search);
urlParams.set("thematiques", value);
history.replaceState(
null,
null,
`${window.location.origin + window.location.pathname}?${urlParams}`,
);

setLocationParam("thematiques", value);
});
};

Expand All @@ -327,15 +316,31 @@ const createNationalImpactSelect = (selectElement, data, initValue) => {
}, 1000);
onNationalImpactChange(true);
}
selectElement.addEventListener("change", (e) => {
const value = selectElement.checked;
selectElement.addEventListener("change", ({ target: { value } }) => {
onNationalImpactChange(value);
const urlParams = new URLSearchParams(window.location.search);
urlParams.set("national_impact", value);
history.replaceState(
null,
null,
`${window.location.origin + window.location.pathname}?${urlParams}`,
);

setLocationParam("national_impact", value);
});
};

function setLocationParam(param, value) {
const url = new URL(window.location);

url.searchParams.set(param, value);

history.replaceState(null, null, url);
}

function setupExcludeInvestigations() {
const toggle = document.getElementById("exclude-investigations-toggle");

toggle.checked = filters.excludeInvestigations;

toggle.addEventListener("change", ({ target: { checked: value } }) => {
filters.excludeInvestigations = value;

setLocationParam("exclude-investigations", value);

updateCards(data);
});
}

0 comments on commit 9fdc577

Please sign in to comment.