diff --git a/Lab5/Bookfill/src/components/search/Search.jsx b/Lab5/Bookfill/src/components/search/Search.jsx
index 1756c19..5c14935 100644
--- a/Lab5/Bookfill/src/components/search/Search.jsx
+++ b/Lab5/Bookfill/src/components/search/Search.jsx
@@ -2,7 +2,7 @@ import PropTypes from 'prop-types';
import { Heart } from 'react-bootstrap-icons';
import '../lines/table/LinesTableRow.css';
-const Direction = ({ index, line, onAddCart }) => {
+const Search = ({ index, line, onAddCart }) => {
const handleAnchorClick = (event, action) => {
event.preventDefault();
action();
@@ -11,7 +11,6 @@ const Direction = ({ index, line, onAddCart }) => {
{index + 1} |
{line.book_name} |
- {line.type.name} |
{line.author_name} |
{parseFloat(line.price).toFixed(2)} |
![{line.book_name}]({line.image}) |
@@ -20,10 +19,10 @@ const Direction = ({ index, line, onAddCart }) => {
);
};
-Direction.propTypes = {
+Search.propTypes = {
index: PropTypes.number,
line: PropTypes.object,
onAddCart: PropTypes.func,
};
-export default Direction;
+export default Search;
diff --git a/Lab5/Bookfill/src/components/search/Searchs.jsx b/Lab5/Bookfill/src/components/search/Searchs.jsx
index bb75eb9..1614aca 100644
--- a/Lab5/Bookfill/src/components/search/Searchs.jsx
+++ b/Lab5/Bookfill/src/components/search/Searchs.jsx
@@ -1,16 +1,13 @@
import { useState } from 'react';
import TableDirect from './TableSearch.jsx';
-import Select from '../input/Select.jsx';
-import Direction from './Search.jsx';
-import useLines from '../lines/hooks/LinesHook';
+import Search from './Search.jsx';
+import useSearch from './searchHooks/SearchHooks';
import useCart from '../cart/CartHook';
import Input from '../input/Input.jsx';
-import useTypeFilter from '../lines/hooks/LinesFilterHook';
-const Directions = () => {
- const { types, currentFilter, handleFilterChange } = useTypeFilter();
- const { lines } = useLines(currentFilter);
+const Searchs = () => {
const [searchValue, setSearchValue] = useState('');
+ const { lines } = useSearch(searchValue);
const { addToCart } = useCart();
return (
@@ -18,22 +15,15 @@ const Directions = () => {
setSearchValue(e.target.value)}
type='text' required />
-
{
lines.map((line, index) => {
- if (searchValue === ''
- || line.book_name?.toLowerCase().includes(searchValue.toLowerCase())
- || line.author?.toLowerCase().includes(searchValue.toLowerCase())) {
- return addToCart(line)} />;
- }
- return null;
+ return addToCart(line)} />;
})
}
@@ -42,4 +32,4 @@ const Directions = () => {
);
};
-export default Directions;
+export default Searchs;
diff --git a/Lab5/Bookfill/src/components/search/TableSearch.jsx b/Lab5/Bookfill/src/components/search/TableSearch.jsx
index 7a89a01..991f6b8 100644
--- a/Lab5/Bookfill/src/components/search/TableSearch.jsx
+++ b/Lab5/Bookfill/src/components/search/TableSearch.jsx
@@ -1,14 +1,13 @@
import PropTypes from 'prop-types';
import { Table } from 'react-bootstrap';
-const TableDirect = ({ children }) => {
+const TableSearch = ({ children }) => {
return (
№ |
Name |
- Category |
Author |
Price |
@@ -20,8 +19,8 @@ const TableDirect = ({ children }) => {
);
};
-TableDirect.propTypes = {
+TableSearch.propTypes = {
children: PropTypes.node,
};
-export default TableDirect;
+export default TableSearch;
diff --git a/Lab5/Bookfill/src/components/search/searchHooks/SearchHooks.js b/Lab5/Bookfill/src/components/search/searchHooks/SearchHooks.js
new file mode 100644
index 0000000..15d64da
--- /dev/null
+++ b/Lab5/Bookfill/src/components/search/searchHooks/SearchHooks.js
@@ -0,0 +1,23 @@
+import { useEffect, useState } from 'react';
+import LinesApiService from '../../lines/service/LinesApiService';
+
+const useSearch = (searchValue) => {
+ const [lines, setLines] = useState([]);
+
+ const getLines = async () => {
+ const expand = `?q=${searchValue}`;
+ const data = await LinesApiService.getAll(expand);
+ setLines(data ?? []);
+ };
+
+ useEffect(() => {
+ getLines();
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [searchValue]);
+
+ return {
+ lines,
+ };
+};
+
+export default useSearch;
diff --git a/Lab5/Bookfill/src/pages/Search.jsx b/Lab5/Bookfill/src/pages/Search.jsx
index 1ff86d9..82f8d82 100644
--- a/Lab5/Bookfill/src/pages/Search.jsx
+++ b/Lab5/Bookfill/src/pages/Search.jsx
@@ -1,10 +1,10 @@
import './pages.css';
-import Directions from '../components/search/Searchs.jsx';
+import Searchs from '../components/search/Searchs.jsx';
const Search = () => {
return (
<>
-
+
>
);
};