From 2aab9b246f8daadbbb320a355478a79d86e79633 Mon Sep 17 00:00:00 2001 From: Justin Wong <58980435+FatKidddd@users.noreply.github.com> Date: Wed, 26 Jul 2023 21:06:58 +0800 Subject: [PATCH] Fixed profile tab header bug (#155) --- .../components/profile.tsx | 65 ++++--------------- 1 file changed, 14 insertions(+), 51 deletions(-) diff --git a/src/features/organisation-profile/components/profile.tsx b/src/features/organisation-profile/components/profile.tsx index 7258ccf..33daa98 100644 --- a/src/features/organisation-profile/components/profile.tsx +++ b/src/features/organisation-profile/components/profile.tsx @@ -12,7 +12,7 @@ import { AccordionPanel, Image, } from "@chakra-ui/react"; -import { useEffect, useRef, useState } from "react"; +import { useEffect, useState } from "react"; import { GetIconForSocials } from "../../../utilities/icon-mappings"; import "../scss/profile.scss"; import { Organisation } from "../../../data/model/organisation"; @@ -52,8 +52,6 @@ export enum ETabLabel { const renderTabContent = ( label: ETabLabel, content: any, - tabsHeight: number, - isScrollDown: boolean ) => { switch (label) { case ETabLabel.OUR_STORY: @@ -78,15 +76,11 @@ const renderTabContent = ( }} >
{!!contentMenu && contentMenu.map( @@ -371,57 +365,26 @@ const Profile: React.FC<{ org?: Organisation }> = ({ org }) => { // TODO retrieve organisation ID based on selected option const orgId = org?.id ?? ""; const [profileData, setProfileData] = useState([]); - const tabsHeightRef = useRef(null); - const [tabsHeight, setTabsHeight] = useState(1200); - const [isScrollDown, setIsScrollDown] = useState(true); - let prevScrollPosition = window.pageYOffset; // this uses concept of JS closures -- while handleScroll() runs, it will use stale value of prevScrollPosition - const handleScroll = () => { - if (tabsHeightRef.current) { - const height = - tabsHeightRef.current.getBoundingClientRect().top - - 0.08 * window.innerHeight; // 0.08 vh correspond to nav bar height - setTabsHeight(height); - - const currentScrollPosition = window.pageYOffset; - prevScrollPosition > currentScrollPosition - ? setIsScrollDown(false) - : setIsScrollDown(true); - prevScrollPosition = currentScrollPosition; - } - }; - - const getData = async () => { - await getOrganisationProfileData(orgId).then((data) => + useEffect(() => { + getOrganisationProfileData(orgId).then((data) => setProfileData(data) ); - }; - - useEffect(() => { - window.addEventListener("scroll", handleScroll); - getData(); - return () => window.removeEventListener("scroll", handleScroll); }, []); return ( {profileData.map((tab, index) => ( = ({ org }) => { {profileData.map((tab, index) => ( - {renderTabContent(tab.label, tab.content, tabsHeight, isScrollDown)} + {renderTabContent(tab.label, tab.content)} ))}