From 288ea8cb85185877d1ab02f09e02f8427f8b2e1c Mon Sep 17 00:00:00 2001 From: brightiron Date: Tue, 22 Oct 2024 21:20:50 -0500 Subject: [PATCH 1/2] optimize tab rendering for network requests --- src/views/Lending/Cooler/index.tsx | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/views/Lending/Cooler/index.tsx b/src/views/Lending/Cooler/index.tsx index 2ce6653e18..2455a40fa8 100644 --- a/src/views/Lending/Cooler/index.tsx +++ b/src/views/Lending/Cooler/index.tsx @@ -1,4 +1,4 @@ -import { Box, Link, Tab, Tabs, useMediaQuery, useTheme } from "@mui/material"; +import { Box, Link, Tab, Tabs } from "@mui/material"; import { Icon } from "@olympusdao/component-library"; import { useEffect, useState } from "react"; import { Link as RouterLink, useSearchParams } from "react-router-dom"; @@ -10,19 +10,16 @@ import { CoolerPositions } from "src/views/Lending/Cooler/positions/Positions"; const PARAM_TAB = "tab"; export const Cooler = () => { - const theme = useTheme(); - const mobile = useMediaQuery(theme.breakpoints.down("sm")); - - const [tabIndex, setTabIndex] = useState(0); + const [tabIndex, setTabIndex] = useState(undefined); const [searchParams] = useSearchParams(); + const queryTab = searchParams.get(PARAM_TAB); // When the page loads, this causes the tab to be set to the correct value useEffect(() => { - const queryTab = searchParams.get(PARAM_TAB); - setTabIndex(queryTab ? (queryTab === "metrics" ? 1 : 0) : 0); - }, [searchParams]); + setTabIndex(queryTab === "metrics" ? "metrics" : "positions"); + }, [queryTab]); - const handleTabChange = (event: React.SyntheticEvent, newValue: number) => { + const handleTabChange = (event: React.SyntheticEvent, newValue: string) => { setTabIndex(newValue); }; @@ -63,12 +60,12 @@ export const Cooler = () => { //hides the tab underline sliding animation in while is loading TabIndicatorProps={{ style: { display: "none" } }} > - - + + - {tabIndex === 0 && } - {tabIndex === 1 && } + {tabIndex === "positions" && } + {tabIndex === "metrics" && } ); From d742d48bb12c9aca1c82cd53d4a168239cdc528f Mon Sep 17 00:00:00 2001 From: Jem <0x0xJem@gmail.com> Date: Mon, 28 Oct 2024 10:38:12 +0400 Subject: [PATCH 2/2] retrigger checks