Skip to content

Commit

Permalink
Fix code formatting and quality
Browse files Browse the repository at this point in the history
  • Loading branch information
sulaiman-fern committed Jul 29, 2024
1 parent c3687e0 commit 914dc64
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 30 deletions.
47 changes: 19 additions & 28 deletions packages/ui/app/src/sidebar/CollapseSidebarContext.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -83,7 +74,7 @@ export const CollapseSidebarProvider: FC<
// }),
// [registerListener, scrollContainerRef],
// );

const { parentIdMap, parentToChildrenMap } = useMemo(() => {
const parentIdMap = new Map<FernNavigation.NodeId, FernNavigation.NodeId[]>();
const parentToChildrenMap = new Map<FernNavigation.NodeId, FernNavigation.NodeId[]>();
Expand Down Expand Up @@ -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) => {

Check failure on line 111 in packages/ui/app/src/sidebar/CollapseSidebarContext.tsx

View workflow job for this annotation

GitHub Actions / lint

'parents' is defined but never used. Allowed unused args must match /^_/u
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<FernNavigation.NodeId[]>(() => initializeExpandedSections()
);
const [expanded, setExpanded] = useState<FernNavigation.NodeId[]>(() => initializeExpandedSections());

const checkExpanded = useCallback(
(expandableId: FernNavigation.NodeId) =>
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/app/src/sidebar/nodes/SidebarSectionNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check failure on line 45 in packages/ui/app/src/sidebar/nodes/SidebarSectionNode.tsx

View workflow job for this annotation

GitHub Actions / lint

Missing semicolon
const showIndicator = childSelected && !expanded;

return (
<SidebarSlugLink
nodeId={node.id}
Expand Down

0 comments on commit 914dc64

Please sign in to comment.