import { SitePathsContext } from 'Components/utils/withSitePaths' import { encodeRuleName, parentName } from 'Engine/rules.js' import { pick, sortBy, take } from 'ramda' import React, { useContext, useEffect, useState } from 'react' import Highlighter from 'react-highlight-words' import { useTranslation } from 'react-i18next' import { Link, Redirect } from 'react-router-dom' import Worker from 'worker-loader!./SearchBar.worker.js' import { capitalise0 } from '../utils' const worker = new Worker() export default function SearchBar({ rules, showDefaultList, finally: finallyCallback }) { const sitePaths = useContext(SitePathsContext) const [input, setInput] = useState('') const [selectedOption, setSelectedOption] = useState(null) const [results, setResults] = useState([]) const { i18n } = useTranslation() useEffect(() => { worker.postMessage({ rules: rules.map( pick(['title', 'espace', 'description', 'name', 'dottedName']) ) }) worker.onmessage = ({ data: results }) => setResults(results) }, [rules]) let renderOptions = rules => { let options = (rules && sortBy(rule => rule.dottedName, rules)) || take(5)(results) return