From 7ac092fa38ff37c85a0389d7734a728886abb373 Mon Sep 17 00:00:00 2001 From: Bartek Wieckowski Date: Tue, 5 Sep 2023 14:04:46 +0200 Subject: [PATCH] added reset pagination if user change recipes, small changes in css --- src/components/list/List.jsx | 11 +++++++++-- src/components/list/list.scss | 1 - 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/components/list/List.jsx b/src/components/list/List.jsx index bae8e63..09cb101 100644 --- a/src/components/list/List.jsx +++ b/src/components/list/List.jsx @@ -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"; @@ -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; @@ -31,7 +38,7 @@ const List = () => {

{recipe.title}

{recipe.publisher}

-
+
user
diff --git a/src/components/list/list.scss b/src/components/list/list.scss index fc3bdf7..68f098e 100644 --- a/src/components/list/list.scss +++ b/src/components/list/list.scss @@ -117,7 +117,6 @@ } .pagination-wrapper{ - margin-top: auto; padding: 0 3.5rem; &__btn {