Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | 258x 258x 258x 258x 1x 1x 1x 1x 258x 2x 1x 258x 1x | import { AsyncTypeahead } from "react-bootstrap-typeahead";
import { Form } from "react-bootstrap";
import { useState } from "react";
import { useNavigate } from "react-router";
import axios from "axios";
import "react-bootstrap-typeahead/css/Typeahead.css";
export default function MenuItemDropdown() {
const [isLoading, setIsLoading] = useState(false);
const [options, setOptions] = useState([]);
const navigate = useNavigate();
const handleSearch = async (query) => {
setIsLoading(true);
const response = await axios.get("/api/diningcommons/menuitem/search", {
params: { query },
});
setOptions(response.data);
setIsLoading(false);
};
const handleSelectionChange = (selected) => {
if (selected.length > 0) {
navigate(`/reviews/${selected[0].id}`);
}
};
return (
<Form.Group controlId="menuItemSearch">
<AsyncTypeahead
id="menuItemSearch-typeahead"
options={options}
labelKey="name"
placeholder="Search menu items"
onChange={handleSelectionChange}
highlightOnlyResult
isLoading={isLoading}
onSearch={handleSearch}
renderMenuItemChildren={(item) => (
<div className="text-wrap">
<div>{item.name}</div>
<small className="text-muted">{item.diningCommonsCode}</small>
</div>
)}
inputProps={{
"aria-label": "Search menu items",
"data-testid": "MenuItemDropdown",
}}
/>
</Form.Group>
);
}
|