Skip to content

Commit

Permalink
solution
Browse files Browse the repository at this point in the history
  • Loading branch information
LBondarchuk committed Jul 15, 2023
1 parent 137e4d6 commit 5bf523b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/components/pages/DetailsPage/ProductDetailsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { useEffect, useMemo, useState } from 'react';
import {
useEffect, useMemo, useRef, useState,
} from 'react';
import { useParams } from 'react-router-dom';
import classnames from 'classnames';
import { Product } from '../../../utils/types/Product';
Expand All @@ -18,6 +20,7 @@ type Props = {
export const ProductDetailsPage: React.FC<Props> = ({ products }) => {
const [details, setDetails] = useState<Details>();
const { id } = useParams();
const refPrevId = useRef('');
const [isLoading, setIsLoading] = useState(false);

const currentProduct = useMemo(() => {
Expand All @@ -30,7 +33,13 @@ export const ProductDetailsPage: React.FC<Props> = ({ products }) => {
}, 100);

getDetails(id)
.then((response) => setDetails(response))
.then((response) => {
setDetails(response);
refPrevId.current = window.location.hash;
})
.catch(() => {
(window.location.hash = refPrevId.current);
})
.finally(() => {
clearInterval(Id);
setIsLoading(false);
Expand Down
3 changes: 2 additions & 1 deletion src/utils/searchActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const SortList = (list: Product[], sortBy: string | null) => {
const filterByQuery = (list: Product[], query: string) => {
return list.filter(product => product.name
.toLocaleLowerCase()
.replaceAll(' ', '').includes(query.toLocaleLowerCase()));
.replaceAll(' ', '').includes(query.toLocaleLowerCase()
.replaceAll(' ', '')));
};

const sliceProductList = (list: Product[], page: string, perPage: string) => {
Expand Down

0 comments on commit 5bf523b

Please sign in to comment.