Skip to content

Commit

Permalink
chore: minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Franqsanz committed Nov 3, 2023
1 parent 80be1f0 commit 0d1478d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
9 changes: 0 additions & 9 deletions src/components/cards/MoreBooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,12 @@ export default function MoreBooks({ currentBookId }: ReleatedBooksType) {
const { data, refetch } = useMoreBooks();
const moreBooks = useRefetchLocation(currentBookId, data, refetch);

// const moreBooks = data.filter((book: any) => {
// if (book.pathUrl === currentBookId) {
// refetch();
// }

// return book.pathUrl !== currentBookId;
// });

return (
<>
<ContainerRCard>
{moreBooks.map(({ id, title, authors, pathUrl }: CardType) => (
<React.Fragment key={id}>
<RelatedCard
id={id}
title={title}
authors={authors}
pathUrl={pathUrl}
Expand Down
1 change: 0 additions & 1 deletion src/components/cards/RelatedBooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export default function RelatedBooks({ currentBookId, id }: ReleatedBooksType) {
{relatedBooks.map(({ id, title, authors, pathUrl }: CardType) => (
<React.Fragment key={id}>
<RelatedCard
id={id}
title={title}
authors={authors}
pathUrl={pathUrl}
Expand Down
10 changes: 5 additions & 5 deletions src/hooks/useRefetchLocation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { useLocation } from 'react-router-dom';

export function useRefetchLocation(currentBookId, data, refetch) {
const location = useLocation();
const [previousPathname, setPreviousPathname] = useState(location.pathname);
const pathname = location.pathname;
const [previousPathname, setPreviousPathname] = useState(pathname);
const [relatedBooks, setRelatedBooks] = useState([]);

useEffect(() => {
Expand All @@ -13,11 +14,10 @@ export function useRefetchLocation(currentBookId, data, refetch) {

setRelatedBooks(filteredBooks);

if (location.pathname !== previousPathname) {
if (pathname !== previousPathname) {
refetch();
setPreviousPathname(location.pathname);
setPreviousPathname(pathname);
}
}, [data, currentBookId, location.pathname, refetch, previousPathname]);

}, [data, currentBookId, pathname, refetch, previousPathname]);
return relatedBooks;
}

1 comment on commit 0d1478d

@vercel
Copy link

@vercel vercel bot commented on 0d1478d Nov 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

xbu – ./

xbu-franqsanz.vercel.app
xbu-git-main-franqsanz.vercel.app
xbu.vercel.app

Please sign in to comment.