Skip to content

Commit

Permalink
added reset pagination if user change recipes, small changes in css
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartek-Wieckowski committed Sep 5, 2023
1 parent 6027dc2 commit 7ac092f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/components/list/List.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from "react";
import { useEffect, useState } from "react";
import { useGlobal } from "../../context/GlobalContext";
import imagePaths from "../../utils/images";
import ErrorMsg from "../error-msg/ErrorMsg";
Expand All @@ -8,9 +8,16 @@ import { Link, useLocation } from "react-router-dom";

const List = () => {
const [currentPage, setCurrentPage] = useState(1);

const { recipes, isLoading, error } = useGlobal();

const location = useLocation();

useEffect(() => {
setCurrentPage(1)
}, [recipes])


const itemsPerPage = 10;
const indexOfLastItem = currentPage * itemsPerPage;
const indexOfFirstItem = indexOfLastItem - itemsPerPage;
Expand All @@ -31,7 +38,7 @@ const List = () => {
<div className="preview__data">
<h4 className="preview__title">{recipe.title}</h4>
<p className="preview__publisher">{recipe.publisher}</p>
<div className="preview__user-generated">
<div className="preview__user-generated" style={{display:"none"}}>
<img src={imagePaths.user} alt="user" />
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion src/components/list/list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@
}

.pagination-wrapper{
margin-top: auto;
padding: 0 3.5rem;

&__btn {
Expand Down

0 comments on commit 7ac092f

Please sign in to comment.