Skip to content

Commit

Permalink
cleanup & index routes
Browse files Browse the repository at this point in the history
  • Loading branch information
mosch committed Jan 27, 2025
1 parent 4ee0a1b commit 1b0103a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Outlet, useParams } from "react-router";
import { Outlet } from "react-router";
import { joinPath } from "../../util/joinPath.js";
import type { GraphQLClient } from "./client/GraphQLClient.js";
import { GraphQLProvider } from "./client/GraphQLContext.js";
Expand All @@ -8,16 +8,16 @@ import { type OasPluginConfig } from "./interfaces.js";
export const OpenApiRoute = ({
basePath,
versions,
version,
config,
client,
}: {
basePath: string;
version?: string;
versions: string[];
config: OasPluginConfig;
client: GraphQLClient;
}) => {
const { version } = useParams<"version">();

const input =
config.type === "file"
? {
Expand Down
31 changes: 10 additions & 21 deletions packages/zudoku/src/lib/plugins/openapi/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import slugify from "@sindresorhus/slugify";
import { useQuery } from "@tanstack/react-query";
import { CirclePlayIcon, LogInIcon } from "lucide-react";
import { matchPath, RouteObject } from "react-router";
import { matchPath, redirect, RouteObject } from "react-router";
import type { SidebarItem } from "../../../config/validators/SidebarSchema.js";
import { useAuth } from "../../authentication/hook.js";
import { ColorMap } from "../../components/navigation/SidebarBadge.js";
Expand Down Expand Up @@ -137,9 +137,10 @@ export const openApiPlugin = (config: OpenApiPluginOptions): ZudokuPlugin => {
}

try {
const version =
versions.find((v) => path.startsWith(joinUrl(basePath, v))) ??
Object.keys(config.input).at(0);
const urlVersion = versions.find((v) =>
path.startsWith(joinUrl(basePath, v)),
);
const version = urlVersion ?? Object.keys(config.input).at(0);

const data = await client.fetch(GetCategoriesQuery, {
type: config.type,
Expand Down Expand Up @@ -173,7 +174,7 @@ export const openApiPlugin = (config: OpenApiPluginOptions): ZudokuPlugin => {
.map<SidebarItem>((tag) => {
const categoryLink = joinUrl(
basePath,
version,
urlVersion,
tag.name ? slugify(tag.name) : "~endpoints",
);
return {
Expand All @@ -187,17 +188,6 @@ export const openApiPlugin = (config: OpenApiPluginOptions): ZudokuPlugin => {
collapsible: false,
collapsed: true,
items: path === categoryLink ? items : [],
// TODO left in for single page APIs
// items: tag.operations.map((operation) => ({
// type: "link",
// label: operation.summary ?? operation.path,
// href: `#${operation.slug}`,
// badge: {
// label: operation.method,
// color: MethodColorMap[operation.method.toLowerCase()]!,
// invert: true,
// },
// })),
};
});

Expand All @@ -220,10 +210,11 @@ export const openApiPlugin = (config: OpenApiPluginOptions): ZudokuPlugin => {
return {
path: versionPath,
async lazy() {
const { OpenApiRoute } = await import("./Route.js");
const { OpenApiRoute } = await import("./OpenApiRoute.js");
return {
element: (
<OpenApiRoute
version={version ?? undefined}
basePath={basePath}
versions={versions}
client={client}
Expand All @@ -235,10 +226,8 @@ export const openApiPlugin = (config: OpenApiPluginOptions): ZudokuPlugin => {
children: [
{
index: true,
async lazy() {
// const { OperationList } = await import("./OperationList.js");
return { element: <div>im the new index page</div> };
// return { element: <OperationList /> };
loader: () => {
return redirect(joinUrl(versionPath, tagPages.at(0)?.path));
},
},
{
Expand Down

0 comments on commit 1b0103a

Please sign in to comment.