From 12de693413eb336c236ee65707bac8982dbc550e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Guillois?= Date: Wed, 19 Feb 2020 14:51:22 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Recherche=20dans=20les=20r=C3=A8?= =?UTF-8?q?gles:=20affiche=20les=20r=C3=A8gles=20en=20lien=20avec=20la=20p?= =?UTF-8?q?age=20courrante=20d'abord?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/components/SearchBar.tsx | 36 ++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/source/components/SearchBar.tsx b/source/components/SearchBar.tsx index 5ff468176..c494fabbe 100644 --- a/source/components/SearchBar.tsx +++ b/source/components/SearchBar.tsx @@ -70,10 +70,44 @@ export default function SearchBar({ let onMouseOverHandler = () => setFocusElem(-1) + const getDottedName = (href: String) => { + const currentSlug = decodeURI(href.substring(href.lastIndexOf('/') + 1)) + return ( + [ + { + slugs: ['salarié', 'assimilé-salarié'], + dottedName: 'contrat salarié' + }, + { + slugs: ['indépendant', 'auto-entrepreneur'], + dottedName: 'dirigeant' + } + ].find( + item => item.slugs.find(slug => slug === currentSlug) !== undefined + )?.dottedName || '' + ) + } + let renderOptions = (rules?: Array) => { + const currentPage = getDottedName(window.location.href) let options = (rules && sortBy(rule => rule.dottedName, rules)) || take(5)(results) - return + let currentOptions: Array> = [] + let notCurrentOptions: Array> = [] + options.forEach(option => { + if (option.dottedName.startsWith(currentPage)) { + currentOptions.push(option) + } else { + notCurrentOptions.push(option) + } + }) + return ( +
    + {[...currentOptions, ...notCurrentOptions].map((option, idx) => + renderOption(option, idx) + )} +
+ ) } let renderOption = (option: Option, idx: number) => {