Álvaro Valenzuela Valdes commited on
Commit
b7ad7a5
·
1 Parent(s): f7a5c63

Fix: Reset scroll position when switching tabs by using a ref on the content area

Browse files
Files changed (1) hide show
  1. frontend/app/page.tsx +6 -2
frontend/app/page.tsx CHANGED
@@ -1,6 +1,6 @@
1
  "use client";
2
 
3
- import { useEffect, useMemo, useState } from "react";
4
  import Dashboard from "../components/Dashboard";
5
  import TenderSearch from "../components/TenderSearch";
6
  import CompanyProfile from "../components/CompanyProfile";
@@ -51,6 +51,7 @@ export default function HomePage() {
51
  const [status, setStatus] = useState("listening");
52
  const [searchKeyword, setSearchKeyword] = useState("");
53
  const [lang, setLang] = useState<Language>("en");
 
54
 
55
  const t = translations[lang];
56
 
@@ -58,6 +59,9 @@ export default function HomePage() {
58
  // Scroll to top when tab changes
59
  useEffect(() => {
60
  window.scrollTo(0, 0);
 
 
 
61
  }, [activeTab]);
62
 
63
  useEffect(() => {
@@ -236,7 +240,7 @@ export default function HomePage() {
236
  </header>
237
 
238
  {/* Content Area */}
239
- <div className="flex-1 overflow-y-auto pr-2 custom-scrollbar pb-12">
240
  {activeTab === "Dashboard" && (
241
  <Dashboard
242
  tendersFound={tenders.length}
 
1
  "use client";
2
 
3
+ import { useEffect, useMemo, useState, useRef } from "react";
4
  import Dashboard from "../components/Dashboard";
5
  import TenderSearch from "../components/TenderSearch";
6
  import CompanyProfile from "../components/CompanyProfile";
 
51
  const [status, setStatus] = useState("listening");
52
  const [searchKeyword, setSearchKeyword] = useState("");
53
  const [lang, setLang] = useState<Language>("en");
54
+ const contentRef = useRef<HTMLDivElement>(null);
55
 
56
  const t = translations[lang];
57
 
 
59
  // Scroll to top when tab changes
60
  useEffect(() => {
61
  window.scrollTo(0, 0);
62
+ if (contentRef.current) {
63
+ contentRef.current.scrollTo(0, 0);
64
+ }
65
  }, [activeTab]);
66
 
67
  useEffect(() => {
 
240
  </header>
241
 
242
  {/* Content Area */}
243
+ <div ref={contentRef} className="flex-1 overflow-y-auto pr-2 custom-scrollbar pb-12">
244
  {activeTab === "Dashboard" && (
245
  <Dashboard
246
  tendersFound={tenders.length}