From 914dc645dbf16b43e6a9bb4f5b227ccba89caca2 Mon Sep 17 00:00:00 2001 From: Sulaiman Hamouda Date: Mon, 29 Jul 2024 16:00:20 -0400 Subject: [PATCH] Fix code formatting and quality --- .../src/sidebar/CollapseSidebarContext.tsx | 47 ++++++++----------- .../src/sidebar/nodes/SidebarSectionNode.tsx | 4 +- 2 files changed, 21 insertions(+), 30 deletions(-) diff --git a/packages/ui/app/src/sidebar/CollapseSidebarContext.tsx b/packages/ui/app/src/sidebar/CollapseSidebarContext.tsx index 4b3e206dd1..28c9e9f87a 100644 --- a/packages/ui/app/src/sidebar/CollapseSidebarContext.tsx +++ b/packages/ui/app/src/sidebar/CollapseSidebarContext.tsx @@ -1,15 +1,6 @@ import { FernNavigation } from "@fern-api/fdr-sdk"; import { useAtomValue } from "jotai"; -import { - FC, - PropsWithChildren, - RefObject, - createContext, - useCallback, - useContext, - useMemo, - useState -} from "react"; +import { FC, PropsWithChildren, RefObject, createContext, useCallback, useContext, useMemo, useState } from "react"; import { noop } from "ts-essentials"; import { useCallbackOne } from "use-memo-one"; import { CURRENT_NODE_ATOM, CURRENT_NODE_ID_ATOM, useAtomEffect, useSidebarNodes } from "../atoms"; @@ -83,7 +74,7 @@ export const CollapseSidebarProvider: FC< // }), // [registerListener, scrollContainerRef], // ); - + const { parentIdMap, parentToChildrenMap } = useMemo(() => { const parentIdMap = new Map(); const parentToChildrenMap = new Map(); @@ -112,26 +103,26 @@ export const CollapseSidebarProvider: FC< }, [sidebar]); const initializeExpandedSections = (): FernNavigation.NodeId[] => { - if(selectedNodeId == null) { - return [] + if (selectedNodeId == null) { + return []; } else { - if(sidebar) { - const selectedNodes: FernNavigation.NodeId[] = [] - FernNavigation.utils.traverseNavigation(sidebar, (node, _index, parents) => { - if(FernNavigation.isSection(node) && node.type === "section") { - if(!node?.collapsed) { - selectedNodes.push(...[node.id, ...(parentIdMap.get(node.id) ?? [])]) + if (sidebar) { + const selectedNodes: FernNavigation.NodeId[] = []; + FernNavigation.utils.traverseNavigation(sidebar, (node, _index, parents) => { + if (FernNavigation.isSection(node) && node.type === "section") { + if (!node?.collapsed) { + selectedNodes.push(...[node.id, ...(parentIdMap.get(node.id) ?? [])]); + } } - } - }) - return selectedNodes - } else { - return [selectedNodeId, ...(parentIdMap.get(selectedNodeId) ?? [])] - }} - } + }); + return selectedNodes; + } else { + return [selectedNodeId, ...(parentIdMap.get(selectedNodeId) ?? [])]; + } + } + }; - const [expanded, setExpanded] = useState(() => initializeExpandedSections() - ); + const [expanded, setExpanded] = useState(() => initializeExpandedSections()); const checkExpanded = useCallback( (expandableId: FernNavigation.NodeId) => diff --git a/packages/ui/app/src/sidebar/nodes/SidebarSectionNode.tsx b/packages/ui/app/src/sidebar/nodes/SidebarSectionNode.tsx index f557feba49..6e59777811 100644 --- a/packages/ui/app/src/sidebar/nodes/SidebarSectionNode.tsx +++ b/packages/ui/app/src/sidebar/nodes/SidebarSectionNode.tsx @@ -41,9 +41,9 @@ export function SidebarSectionNode({ node, className, depth }: SidebarSectionNod return null; } - const expanded = selectedNodeId === node.id || checkExpanded(node.id) || (childSelected && node.overviewPageId != null) + const expanded = + selectedNodeId === node.id || checkExpanded(node.id) || (childSelected && node.overviewPageId != null) const showIndicator = childSelected && !expanded; - return (