🔎 Glorious universal library search first draft
This commit is contained in:
71
src/client/components/GlobalSearchBar/SearchBar.tsx
Normal file
71
src/client/components/GlobalSearchBar/SearchBar.tsx
Normal file
@@ -0,0 +1,71 @@
|
||||
import { debounce, isEmpty, isUndefined, map } from "lodash";
|
||||
import React, { ReactElement, useCallback, useState } from "react";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import Card from "../Carda";
|
||||
|
||||
import { searchIssue } from "../../actions/fileops.actions";
|
||||
import MetadataPanel from "../shared/MetadataPanel";
|
||||
|
||||
interface ISearchBarProps {
|
||||
data: any;
|
||||
}
|
||||
|
||||
export const SearchBar = (data: ISearchBarProps): ReactElement => {
|
||||
const dispatch = useDispatch();
|
||||
const searchResults = useSelector(
|
||||
(state: RootState) => state.fileOps.librarySearchResultsFormatted,
|
||||
);
|
||||
|
||||
const performSearch = useCallback(
|
||||
(e) => {
|
||||
dispatch(
|
||||
searchIssue(
|
||||
{
|
||||
query: {
|
||||
volumeName: e.target.value,
|
||||
},
|
||||
},
|
||||
{
|
||||
pagination: {
|
||||
size: 25,
|
||||
from: 0,
|
||||
},
|
||||
type: "volumeName",
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
[data],
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<div className="control has-icons-right">
|
||||
<input
|
||||
className="input mt-2"
|
||||
placeholder="Search Library"
|
||||
onChange={(e) => performSearch(e)}
|
||||
/>
|
||||
|
||||
<span className="icon is-right mt-2">
|
||||
<i className="fa-solid fa-magnifying-glass"></i>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{!isEmpty(searchResults) ? (
|
||||
<div
|
||||
className="columns box is-multiline"
|
||||
style={{
|
||||
padding: 4,
|
||||
position: "absolute",
|
||||
width: 360,
|
||||
margin: "60px 0 0 350px",
|
||||
}}
|
||||
>
|
||||
{map(searchResults, (result) => (
|
||||
<MetadataPanel data={result} />
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
</>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user