Skip to content

Commit 92e2933

Browse files
committed
resolve conflicts
1 parent 752e773 commit 92e2933

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

src/examples/basic/types.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { DataRouteMatch } from "react-router-dom";
2-
import { RouterTabModel } from "src/lib/tabs/useRouterTabs.tsx";
1+
import { Params } from "react-router-dom";
32

43
export type TabHandle = {
5-
key: any;
6-
title: (match: DataRouteMatch) => string;
7-
insertAt?: (models: RouterTabModel[]) => number;
4+
key: string;
5+
title: (props: { params: Params }) => string;
86
};
97

108
export type Handle = {

src/examples/basic/utils.ts

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { DataRouteMatch, RouteObject, UIMatch } from "react-router-dom";
2+
import { Handle, TabHandle } from "./types";
3+
import { flattenRoutes } from "src/lib/tabs";
4+
import { InsertMethod, TabConfig } from "src/lib/tabs/useRouterTabs.tsx";
5+
6+
export const convertRouteTreeToConfig = (tree: RouteObject[], key: string) => {
7+
const flatRoutes = flattenRoutes(tree);
8+
9+
const matchedRoutes = flatRoutes.filter((route) => {
10+
return (route.handle as Handle)?.tabs.find((tab) => tab.key === key);
11+
});
12+
13+
const config: TabConfig<any>[] = matchedRoutes.map((route) => {
14+
const handle = route.handle as Handle;
15+
const tabMeta = handle.tabs.find((tab) => (tab.key = key));
16+
17+
return {
18+
title: tabMeta!.title,
19+
routeId: route.id!,
20+
insertMethod: InsertMethod.Prepend,
21+
};
22+
});
23+
return config;
24+
};
25+
26+
export const getTabHandle =
27+
(key: string) =>
28+
(match: DataRouteMatch): TabHandle | undefined => {
29+
return (match.route?.handle as Handle | undefined)?.tabs.find(
30+
(tabHandle: TabHandle) => tabHandle.key === key,
31+
);
32+
};
33+
34+
export const getTabHandleUI =
35+
(key: string) =>
36+
(match: UIMatch<any, Handle>): TabHandle | undefined => {
37+
return match?.handle?.tabs.find(
38+
(tabHandle: TabHandle) => tabHandle.key === key,
39+
);
40+
};

0 commit comments

Comments
 (0)