From 9c68bcd2c4a3e62b6f677dd4820db8d033a80394 Mon Sep 17 00:00:00 2001 From: Isaac Way Date: Sun, 23 Apr 2023 14:20:20 -0500 Subject: [PATCH] Performance improvements --- packages/trpc-panel/src/react-app/Root.tsx | 8 +- .../components/CollapsableSection.tsx | 21 ++- .../src/react-app/components/SideNav.tsx | 32 +++-- .../contexts/SiteNavigationContext.tsx | 121 ++++++++++++------ .../form/ProcedureForm/DescriptionSection.tsx | 32 ++--- 5 files changed, 140 insertions(+), 74 deletions(-) diff --git a/packages/trpc-panel/src/react-app/Root.tsx b/packages/trpc-panel/src/react-app/Root.tsx index 946e8fe..c230470 100644 --- a/packages/trpc-panel/src/react-app/Root.tsx +++ b/packages/trpc-panel/src/react-app/Root.tsx @@ -30,8 +30,8 @@ export function RootComponent({ }) { return ( - - + + @@ -41,8 +41,8 @@ export function RootComponent({ - - + + ); } diff --git a/packages/trpc-panel/src/react-app/components/CollapsableSection.tsx b/packages/trpc-panel/src/react-app/components/CollapsableSection.tsx index a9c2a17..2530113 100644 --- a/packages/trpc-panel/src/react-app/components/CollapsableSection.tsx +++ b/packages/trpc-panel/src/react-app/components/CollapsableSection.tsx @@ -1,14 +1,22 @@ import React, { MutableRefObject, ReactNode, useEffect, useRef } from "react"; import { Chevron } from "@src/react-app/components/Chevron"; -import { useSiteNavigationContext } from "@src/react-app/components/contexts/SiteNavigationContext"; +import { + collapsables, + useCollapsableIsShowing, + useSiteNavigationContext, +} from "@src/react-app/components/contexts/SiteNavigationContext"; import { backgroundColor, solidColorBg, solidColorBorder, } from "@src/react-app/components/style-utils"; -export type ColorSchemeType = "query" | "mutation" | "router" | "neutral" | "subscription"; - +export type ColorSchemeType = + | "query" + | "mutation" + | "router" + | "neutral" + | "subscription"; export function CollapsableSection({ titleElement, fullPath, @@ -24,8 +32,9 @@ export function CollapsableSection({ isRoot?: boolean; focusOnScrollRef?: MutableRefObject; }) { - const { has, togglePath, scrollToPathIfMatches } = useSiteNavigationContext(); - const shown = has(fullPath); + const { scrollToPathIfMatches } = useSiteNavigationContext(); + const shown = useCollapsableIsShowing(fullPath); + const containerRef = useRef(null); useEffect(() => { if (shown && containerRef.current) { @@ -59,7 +68,7 @@ export function CollapsableSection({ > {collapsable ? (