Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
layerok committed Nov 8, 2024
1 parent 752e773 commit 92e2933
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/examples/basic/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { DataRouteMatch } from "react-router-dom";
import { RouterTabModel } from "src/lib/tabs/useRouterTabs.tsx";
import { Params } from "react-router-dom";

export type TabHandle = {
key: any;
title: (match: DataRouteMatch) => string;
insertAt?: (models: RouterTabModel[]) => number;
key: string;
title: (props: { params: Params }) => string;
};

export type Handle = {
Expand Down
40 changes: 40 additions & 0 deletions src/examples/basic/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { DataRouteMatch, RouteObject, UIMatch } from "react-router-dom";

Check failure on line 1 in src/examples/basic/utils.ts

View workflow job for this annotation

GitHub Actions / Build

Module '"src/lib/tabs"' has no exported member 'flattenRoutes'.

Check failure on line 1 in src/examples/basic/utils.ts

View workflow job for this annotation

GitHub Actions / Build

Module '"src/lib/tabs/useRouterTabs.tsx"' has no exported member 'InsertMethod'.

Check failure on line 1 in src/examples/basic/utils.ts

View workflow job for this annotation

GitHub Actions / Build

Parameter 'route' implicitly has an 'any' type.

Check failure on line 1 in src/examples/basic/utils.ts

View workflow job for this annotation

GitHub Actions / Build

Type 'TabConfig' is not generic.

Check failure on line 1 in src/examples/basic/utils.ts

View workflow job for this annotation

GitHub Actions / Build

Parameter 'route' implicitly has an 'any' type.
import { Handle, TabHandle } from "./types";
import { flattenRoutes } from "src/lib/tabs";
import { InsertMethod, TabConfig } from "src/lib/tabs/useRouterTabs.tsx";

export const convertRouteTreeToConfig = (tree: RouteObject[], key: string) => {
const flatRoutes = flattenRoutes(tree);

const matchedRoutes = flatRoutes.filter((route) => {
return (route.handle as Handle)?.tabs.find((tab) => tab.key === key);
});

const config: TabConfig<any>[] = matchedRoutes.map((route) => {
const handle = route.handle as Handle;
const tabMeta = handle.tabs.find((tab) => (tab.key = key));

return {
title: tabMeta!.title,
routeId: route.id!,
insertMethod: InsertMethod.Prepend,
};
});
return config;
};

export const getTabHandle =
(key: string) =>
(match: DataRouteMatch): TabHandle | undefined => {
return (match.route?.handle as Handle | undefined)?.tabs.find(
(tabHandle: TabHandle) => tabHandle.key === key,
);
};

export const getTabHandleUI =
(key: string) =>
(match: UIMatch<any, Handle>): TabHandle | undefined => {
return match?.handle?.tabs.find(
(tabHandle: TabHandle) => tabHandle.key === key,
);
};

0 comments on commit 92e2933

Please sign in to comment.