import React, { useState, useEffect } from 'react' import { Card } from 'react-bootstrap'; import { getSearchResults } from './TabulatorData'; import '../jqueryloader' const Search = () => { const [searchTerm, updateSearchTerm] = useState(''); const [filteredResults, updateFilteredResults] = useState([]); const [searchResults, updateSearchResults] = useState([]); const [displayResults, updateDisplayResults] = useState(false); const [focusIndex, updateFocusIndex] = useState(-1); const linkRefs = []; const keys = { ENTER: 13, UP: 38, DOWN: 40 }; useEffect(() => { const getSearchResult = () => { // ⚠️ This is where you should pull data in from your server const searchResultsResponse = getSearchResults(); updateSearchResults(searchResultsResponse); }; getSearchResult(); }, []); const updateSearch = e => { var input = e.target?.value; updateSearchTerm(e.target.value); updateFilteredResults(searchResults.filter(result =>{ if(input?.length >= 3){ return result.title.match(new RegExp(e.target.value, 'gi')) } })) }; const hideAutoSuggest = e => { e.persist(); if (e.relatedTarget && e.relatedTarget.className === 'autosuggest-link') { return false; } updateDisplayResults(true); updateFocusIndex(-1); }; const showAutoSuggest = () => { updateDisplayResults(false); }; const handleInput = (e) =>{ var input = e.target?.value; $('.search-suggestions').css('display', 'block'); if(input?.length === 0){ $('.search-suggestions').css('display', 'none'); } } const handleNavigation = e => { switch (e.keyCode) { case keys.ENTER: if (focusIndex !== -1) { window.open(linkRefs[focusIndex].href); } hideAutoSuggest(e); break; case keys.UP: if (focusIndex > -1) { updateFocusIndex(focusIndex - 1); } break; case keys.DOWN: if (focusIndex < filteredResults.length - 1) { updateFocusIndex(focusIndex + 1); } break; } }; const SearchResults = () => { const Message = ({ text }) => (
{currentText}{untilNextText}