import { debounce, isEmpty, map } from "lodash"; import React, { ReactElement, useCallback, useState } from "react"; import axios from "axios"; import Card from "../shared/Carda"; import MetadataPanel from "../shared/MetadataPanel"; import { SEARCH_SERVICE_BASE_URI } from "../../constants/endpoints"; import type { GlobalSearchBarProps } from "../../types"; export const SearchBar = (data: GlobalSearchBarProps): ReactElement => { const [searchResults, setSearchResults] = useState[]>([]); const performSearch = useCallback( debounce(async (e) => { const response = await axios({ url: `${SEARCH_SERVICE_BASE_URI}/searchIssue`, method: "POST", data: { query: { volumeName: e.target.value }, pagination: { size: 25, from: 0 }, type: "volumeName", trigger: "globalSearchBar", }, }); setSearchResults(response.data?.hits ?? []); }, 500), [data], ); return ( <>
performSearch(e)} /> {/* TODO: Switch to Solar icon */}
{!isEmpty(searchResults) ? (
{map(searchResults, (result, idx) => ( ))}
) : null} ); };