chore(trading): avoid portfolio and market page re-rendering on sidebar view change (#5499)
This commit is contained in:
parent
8b94a75ba4
commit
ec837854cf
@ -9,8 +9,6 @@ import { TradeGrid } from './trade-grid';
|
|||||||
import { TradePanels } from './trade-panels';
|
import { TradePanels } from './trade-panels';
|
||||||
import { useNavigate, useParams } from 'react-router-dom';
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
import { Links } from '../../lib/links';
|
import { Links } from '../../lib/links';
|
||||||
import { ViewType, useSidebar } from '../../components/sidebar';
|
|
||||||
import { useGetCurrentRouteId } from '../../lib/hooks/use-get-current-route-id';
|
|
||||||
import { useT, ns } from '../../lib/use-t';
|
import { useT, ns } from '../../lib/use-t';
|
||||||
import { Trans } from 'react-i18next';
|
import { Trans } from 'react-i18next';
|
||||||
|
|
||||||
@ -61,9 +59,6 @@ export const MarketPage = () => {
|
|||||||
const t = useT();
|
const t = useT();
|
||||||
const { marketId } = useParams();
|
const { marketId } = useParams();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const currentRouteId = useGetCurrentRouteId();
|
|
||||||
const { setViews, getView } = useSidebar();
|
|
||||||
const view = getView(currentRouteId);
|
|
||||||
const { screenSize } = useScreenDimensions();
|
const { screenSize } = useScreenDimensions();
|
||||||
const largeScreen = ['lg', 'xl', 'xxl', 'xxxl'].includes(screenSize);
|
const largeScreen = ['lg', 'xl', 'xxl', 'xxxl'].includes(screenSize);
|
||||||
const update = useGlobalStore((store) => store.update);
|
const update = useGlobalStore((store) => store.update);
|
||||||
@ -77,12 +72,6 @@ export const MarketPage = () => {
|
|||||||
}
|
}
|
||||||
}, [update, lastMarketId, data?.id]);
|
}, [update, lastMarketId, data?.id]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (largeScreen && view === undefined) {
|
|
||||||
setViews({ type: ViewType.Order }, currentRouteId);
|
|
||||||
}
|
|
||||||
}, [setViews, view, currentRouteId, largeScreen]);
|
|
||||||
|
|
||||||
const pinnedAsset = data && getAsset(data);
|
const pinnedAsset = data && getAsset(data);
|
||||||
|
|
||||||
const tradeView = useMemo(() => {
|
const tradeView = useMemo(() => {
|
||||||
|
@ -4,9 +4,26 @@ import {
|
|||||||
SidebarButton,
|
SidebarButton,
|
||||||
SidebarDivider,
|
SidebarDivider,
|
||||||
ViewType,
|
ViewType,
|
||||||
|
useSidebar,
|
||||||
} from '../../components/sidebar';
|
} from '../../components/sidebar';
|
||||||
import { useGetCurrentRouteId } from '../../lib/hooks/use-get-current-route-id';
|
import { useGetCurrentRouteId } from '../../lib/hooks/use-get-current-route-id';
|
||||||
import { useT } from '../../lib/use-t';
|
import { useT } from '../../lib/use-t';
|
||||||
|
import { useScreenDimensions } from '@vegaprotocol/react-helpers';
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
|
||||||
|
const ViewInitializer = () => {
|
||||||
|
const currentRouteId = useGetCurrentRouteId();
|
||||||
|
const { setViews, getView } = useSidebar();
|
||||||
|
const view = getView(currentRouteId);
|
||||||
|
const { screenSize } = useScreenDimensions();
|
||||||
|
const largeScreen = ['lg', 'xl', 'xxl', 'xxxl'].includes(screenSize);
|
||||||
|
useEffect(() => {
|
||||||
|
if (largeScreen && view === undefined) {
|
||||||
|
setViews({ type: ViewType.Order }, currentRouteId);
|
||||||
|
}
|
||||||
|
}, [setViews, view, currentRouteId, largeScreen]);
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
export const MarketsSidebar = () => {
|
export const MarketsSidebar = () => {
|
||||||
const t = useT();
|
const t = useT();
|
||||||
@ -37,6 +54,7 @@ export const MarketsSidebar = () => {
|
|||||||
path=":marketId"
|
path=":marketId"
|
||||||
element={
|
element={
|
||||||
<>
|
<>
|
||||||
|
<ViewInitializer />
|
||||||
<SidebarDivider />
|
<SidebarDivider />
|
||||||
<SidebarButton
|
<SidebarButton
|
||||||
view={ViewType.Order}
|
view={ViewType.Order}
|
||||||
|
@ -39,11 +39,21 @@ const WithdrawalsIndicator = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Portfolio = () => {
|
const SidebarViewInitializer = () => {
|
||||||
const t = useT();
|
|
||||||
const currentRouteId = useGetCurrentRouteId();
|
const currentRouteId = useGetCurrentRouteId();
|
||||||
const { getView, setViews } = useSidebar();
|
const { getView, setViews } = useSidebar();
|
||||||
const view = getView(currentRouteId);
|
const view = getView(currentRouteId);
|
||||||
|
// Make transfer sidebar open by default
|
||||||
|
useEffect(() => {
|
||||||
|
if (view === undefined) {
|
||||||
|
setViews({ type: ViewType.Transfer }, currentRouteId);
|
||||||
|
}
|
||||||
|
}, [view, setViews, currentRouteId]);
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Portfolio = () => {
|
||||||
|
const t = useT();
|
||||||
|
|
||||||
const { updateTitle } = usePageTitleStore((store) => ({
|
const { updateTitle } = usePageTitleStore((store) => ({
|
||||||
updateTitle: store.updateTitle,
|
updateTitle: store.updateTitle,
|
||||||
@ -53,17 +63,11 @@ export const Portfolio = () => {
|
|||||||
updateTitle(titlefy([t('Portfolio')]));
|
updateTitle(titlefy([t('Portfolio')]));
|
||||||
}, [updateTitle, t]);
|
}, [updateTitle, t]);
|
||||||
|
|
||||||
// Make transfer sidebar open by default
|
|
||||||
useEffect(() => {
|
|
||||||
if (view === undefined) {
|
|
||||||
setViews({ type: ViewType.Transfer }, currentRouteId);
|
|
||||||
}
|
|
||||||
}, [view, setViews, currentRouteId]);
|
|
||||||
|
|
||||||
const [sizes, handleOnLayoutChange] = usePaneLayout({ id: 'portfolio' });
|
const [sizes, handleOnLayoutChange] = usePaneLayout({ id: 'portfolio' });
|
||||||
const wrapperClasses = 'p-0.5 h-full max-h-full flex flex-col';
|
const wrapperClasses = 'p-0.5 h-full max-h-full flex flex-col';
|
||||||
return (
|
return (
|
||||||
<div className={wrapperClasses}>
|
<div className={wrapperClasses}>
|
||||||
|
<SidebarViewInitializer />
|
||||||
<ResizableGrid vertical onChange={handleOnLayoutChange}>
|
<ResizableGrid vertical onChange={handleOnLayoutChange}>
|
||||||
<ResizableGridPanel minSize={75}>
|
<ResizableGridPanel minSize={75}>
|
||||||
<PortfolioGridChild>
|
<PortfolioGridChild>
|
||||||
|
Loading…
Reference in New Issue
Block a user