Skip to content

Commit 2631f85

Browse files
committed
WIP
1 parent 209ed85 commit 2631f85

File tree

3 files changed

+53
-45
lines changed

3 files changed

+53
-45
lines changed

packages/trpc-ui/src/react-app/Root.tsx

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import {
1010
useHeaders,
1111
} from "@src/react-app/components/contexts/HeadersContext";
1212
import { HotKeysContextProvider } from "@src/react-app/components/contexts/HotKeysContext";
13-
import { SiteNavigationContextProvider } from "@src/react-app/components/contexts/SiteNavigationContext";
13+
import {
14+
SiteNavigationContextProvider,
15+
useSiteNavigationContext,
16+
} from "@src/react-app/components/contexts/SiteNavigationContext";
1417

1518
import { useLocalStorage } from "@src/react-app/components/hooks/useLocalStorage";
1619
import type { RenderOptions } from "@src/render";
@@ -52,11 +55,15 @@ export function RootComponent({
5255
<SiteNavigationContextProvider>
5356
<HotKeysContextProvider>
5457
<RenderOptionsProvider options={options} router={parsedRouter}>
55-
{/* <SearchOverlay> */}
56-
<div className="relative flex h-full w-full flex-1 flex-col">
57-
<AppInnards rootRouter={rootRouter} options={options} />
58-
</div>
59-
{/* </SearchOverlay> */}
58+
<SearchOverlay>
59+
<div className="relative flex h-full w-full flex-1 flex-col">
60+
<AppInnards
61+
rootRouter={rootRouter}
62+
options={options}
63+
parsedRouter={parsedRouter}
64+
/>
65+
</div>
66+
</SearchOverlay>
6067
</RenderOptionsProvider>
6168
</HotKeysContextProvider>
6269
</SiteNavigationContextProvider>
@@ -69,8 +76,10 @@ export function RootComponent({
6976
function AppInnards({
7077
rootRouter,
7178
options,
79+
parsedRouter,
7280
}: {
7381
rootRouter: ParsedRouter;
82+
parsedRouter: ParsedTRPCRouter;
7483
options: RenderOptions;
7584
}) {
7685
const { router } = useRenderOptions();
@@ -79,24 +88,24 @@ function AppInnards({
7988
"trpc-panel.show-minimap",
8089
true,
8190
);
82-
// const { openAndNavigateTo } = useSiteNavigationContext();
91+
const { openAndNavigateTo } = useSiteNavigationContext();
8392

8493
const [path] = useQueryState("path", parseAsArrayOf(parseAsString, "."));
8594

86-
// useEffect(() => {
87-
// openAndNavigateTo(path ?? [], true);
88-
// }, []);
95+
useEffect(() => {
96+
openAndNavigateTo(path ?? [], true);
97+
}, []);
8998
const allPaths = useAllPaths();
9099

91100
return (
92101
<div className="relative flex flex-1 flex-col">
93102
<TopBar open={sidebarOpen} setOpen={setSidebarOpen} />
94103
<div className="flex flex-1 flex-row bg-mainBackground">
95-
{/* <SideNav
96-
rootRouter={rootRouter}
104+
<SideNav
97105
open={sidebarOpen}
98106
setOpen={setSidebarOpen}
99-
/> */}
107+
parsedRoouter={parsedRouter}
108+
/>
100109
<div
101110
className="flex flex-1 flex-col items-center overflow-scroll"
102111
style={{

packages/trpc-ui/src/react-app/components/SearchInputOverlay.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function SearchInput() {
4848
const searchText = useSearch((s) => s.searchText);
4949
const setSearchText = useSearch((s) => s.setSearchText);
5050
const finish = useSearch((s) => s.finish);
51-
// const { openAndNavigateTo } = useSiteNavigationContext();
51+
const { openAndNavigateTo } = useSiteNavigationContext();
5252
const paths = useAllPaths();
5353
const results = useFuzzySort({
5454
paths: paths.pathsArray,
@@ -128,7 +128,7 @@ function SearchInput() {
128128
function pathSelectedHandler(index: number) {
129129
const selected = results[index];
130130
if (!selected) return;
131-
// openAndNavigateTo(selected.target.split("."), true);
131+
openAndNavigateTo(selected.target.split("."), true);
132132
finish();
133133
}
134134

packages/trpc-ui/src/react-app/components/SideNav.tsx

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,53 @@ import {
88
import { colorSchemeForNode } from "@src/react-app/components/style-utils";
99
import React, { useCallback } from "react";
1010
import type { ParsedRouter } from "../../parse/parseRouter";
11+
import type {
12+
ParsedTRPCRouter,
13+
Router,
14+
RouterOrProcedure,
15+
} from "@src/parseV2/types";
16+
import { useCollapsableIsShowing } from "@src/react-app/components/contexts/SiteNavigationContext";
1117
export function SideNav({
12-
rootRouter,
18+
// rootRouter,
1319
open,
14-
}: // setOpen,
15-
{
20+
parsedRoouter,
21+
}: {
1622
open: boolean;
17-
rootRouter: ParsedRouter;
23+
// rootRouter: ParsedRouter;
24+
parsedRoouter: ParsedTRPCRouter;
1825
setOpen: (value: boolean) => void;
1926
}) {
2027
return open ? (
2128
<div
2229
style={{ maxHeight: "calc(100vh - 4rem)" }}
2330
className="flex min-w-[16rem] flex-col items-start space-y-2 overflow-scroll border-r-2 border-r-panelBorder bg-actuallyWhite p-2 pr-4 shadow-sm"
2431
>
25-
<SideNavItem node={rootRouter} path={[]} />
32+
{Object.entries(parsedRoouter).map(([key, routerOrProcedure]) => {
33+
return <SideNavItem node={routerOrProcedure} key={key} />;
34+
})}
2635
</div>
2736
) : null;
2837
}
2938

39+
//* Fix
3040
function SideNavItem({
3141
node,
32-
path,
42+
// path,
3343
}: {
34-
node: ParsedRouter | ParsedProcedure;
35-
path: string[];
44+
node: RouterOrProcedure;
45+
// path: string[];
3646
}) {
37-
// const { markForScrollTo } = useSiteNavigationContext();
38-
// const shown = useCollapsableIsShowing(path) || path.length === 0;
39-
const shown = false;
47+
const { markForScrollTo } = useSiteNavigationContext();
48+
const shown = useCollapsableIsShowing(node.path) || node.path.length === 0;
4049

41-
// const onClick = useCallback(function onClick() {
42-
// collapsables.toggle(path);
43-
// markForScrollTo(path);
44-
// }, []);
50+
const onClick = useCallback(function onClick() {
51+
collapsables.toggle(node.path);
52+
markForScrollTo(node.path);
53+
}, []);
4554

4655
return (
4756
<>
48-
{path.length > 0 && (
57+
{node.path.length > 0 && (
4958
<button
5059
type="button"
5160
className={`flex w-full flex-row items-center justify-between font-bold ${
@@ -55,10 +64,10 @@ function SideNavItem({
5564
>
5665
<span className="flex flex-row items-start">
5766
<ItemTypeIcon colorScheme={colorSchemeForNode(node)} />
58-
{path[path.length - 1]}
67+
{node.path[node.path.length - 1]}
5968
</span>
6069

61-
{node.nodeType === "router" ? (
70+
{node.type === "router" ? (
6271
<Chevron
6372
className={"ml-2 h-3 w-3 " + ""}
6473
direction={shown ? "down" : "right"}
@@ -68,20 +77,10 @@ function SideNavItem({
6877
)}
6978
</button>
7079
)}
71-
{shown && node.nodeType === "router" && (
80+
{shown && node.type === "router" && (
7281
<div className="flex flex-col items-start space-y-2 self-stretch pl-2">
7382
{Object.entries(node.children).map(([key, node]) => {
74-
return (
75-
<SideNavItem
76-
path={
77-
node.nodeType === "procedure"
78-
? node.pathFromRootRouter
79-
: node.path
80-
}
81-
node={node}
82-
key={key}
83-
/>
84-
);
83+
return <SideNavItem node={node} key={key} />;
8584
})}
8685
</div>
8786
)}

0 commit comments

Comments
 (0)