From 87192755a261ee9c99361c08d1593e6c0dbfaff3 Mon Sep 17 00:00:00 2001 From: Gabriele Granello Date: Thu, 9 Jan 2025 09:54:23 +0100 Subject: [PATCH] Track the page reference --- app/components/ui/Dashboard.tsx | 40 ++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/app/components/ui/Dashboard.tsx b/app/components/ui/Dashboard.tsx index 3fe0a7ea..3f125159 100644 --- a/app/components/ui/Dashboard.tsx +++ b/app/components/ui/Dashboard.tsx @@ -1,4 +1,4 @@ -import React, { useRef } from "react"; +import React, { useRef, useState } from "react"; import GraphCard from "./GraphCard"; import { Household } from "@/app/models/Household"; @@ -8,6 +8,9 @@ interface DashboardProps { const Dashboard: React.FC = ({ data }) => { const scrollContainerRef = useRef(null); + const [currentPage, setCurrentPage] = useState(0); + const totalPages = 6; + const handleNext = () => { if (scrollContainerRef.current) { scrollContainerRef.current.scrollBy({ @@ -15,6 +18,16 @@ const Dashboard: React.FC = ({ data }) => { behavior: "smooth", }); } + setCurrentPage((prev) => Math.min(prev + 1, totalPages - 1)); + }; + + const handleScroll = () => { + if (scrollContainerRef.current) { + const scrollTop = scrollContainerRef.current.scrollTop; + const pageHeight = window.innerHeight; + const newPage = Math.round(scrollTop / pageHeight); + setCurrentPage(newPage); + } }; // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -22,7 +35,11 @@ const Dashboard: React.FC = ({ data }) => { return (
-
+
Not much @@ -35,15 +52,16 @@ const Dashboard: React.FC = ({ data }) => {
- -
- -
+ {currentPage < totalPages - 1 && ( +
+ +
+ )}
); };