Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize cooler metrics network requests #3229

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions src/views/Lending/Cooler/index.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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<string | undefined>(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);
};

Expand Down Expand Up @@ -63,12 +60,12 @@ export const Cooler = () => {
//hides the tab underline sliding animation in while <Zoom> is loading
TabIndicatorProps={{ style: { display: "none" } }}
>
<Tab label="Positions" href={`#/lending/cooler?${getSearchParamsWithTab(0)}`} />
<Tab label="Metrics" href={`#/lending/cooler?${getSearchParamsWithTab(1)}`} />
<Tab label="Positions" href={`#/lending/cooler?${getSearchParamsWithTab(0)}`} value="positions" />
<Tab label="Metrics" href={`#/lending/cooler?${getSearchParamsWithTab(1)}`} value="metrics" />
</Tabs>

{tabIndex === 0 && <CoolerPositions />}
{tabIndex === 1 && <CoolerDashboard />}
{tabIndex === "positions" && <CoolerPositions />}
{tabIndex === "metrics" && <CoolerDashboard />}
</Box>
</div>
);
Expand Down
Loading