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) => {