mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-05-18 13:47:08 +02:00
Split codebase (#455)
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import { QueryClientProvider } from "@tanstack/react-query";
|
||||
import { createRootRoute, Outlet } from "@tanstack/react-router";
|
||||
import { type } from "@tauri-apps/plugin-os";
|
||||
import classNames from "classnames";
|
||||
import { Provider as JotaiProvider } from "jotai";
|
||||
import { LazyMotion, MotionConfig } from "motion/react";
|
||||
import { lazy, Suspense } from "react";
|
||||
import { GlobalHooks } from "../components/GlobalHooks";
|
||||
import RouteError from "../components/RouteError";
|
||||
import { jotaiStore } from "../lib/jotai";
|
||||
import { queryClient } from "../lib/queryClient";
|
||||
|
||||
const Toasts = lazy(() => import("../components/Toasts").then((m) => ({ default: m.Toasts })));
|
||||
const Dialogs = lazy(() => import("../components/Dialogs").then((m) => ({ default: m.Dialogs })));
|
||||
|
||||
export const Route = createRootRoute({
|
||||
component: RouteComponent,
|
||||
errorComponent: RouteError,
|
||||
});
|
||||
|
||||
const motionFeatures = () => import("framer-motion").then((mod) => mod.domAnimation);
|
||||
|
||||
function RouteComponent() {
|
||||
return (
|
||||
<JotaiProvider store={jotaiStore}>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<LazyMotion strict features={motionFeatures}>
|
||||
<MotionConfig transition={{ duration: 0.1 }}>
|
||||
<Suspense>
|
||||
<Toasts />
|
||||
<Dialogs />
|
||||
</Suspense>
|
||||
<Layout />
|
||||
<GlobalHooks />
|
||||
</MotionConfig>
|
||||
</LazyMotion>
|
||||
</QueryClientProvider>
|
||||
</JotaiProvider>
|
||||
);
|
||||
}
|
||||
|
||||
function Layout() {
|
||||
return (
|
||||
<div
|
||||
className={classNames("w-full h-full", type() === "linux" && "border border-border-subtle")}
|
||||
>
|
||||
<Outlet />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
import { RedirectToLatestWorkspace } from "../components/RedirectToLatestWorkspace";
|
||||
|
||||
export const Route = createFileRoute("/")({
|
||||
component: RouteComponent,
|
||||
});
|
||||
|
||||
function RouteComponent() {
|
||||
return <RedirectToLatestWorkspace />;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
import { Workspace } from "../../../components/Workspace";
|
||||
|
||||
type WorkspaceSearchSchema = {
|
||||
environment_id?: string | null;
|
||||
cookie_jar_id?: string | null;
|
||||
} & (
|
||||
| {
|
||||
request_id: string;
|
||||
}
|
||||
| {
|
||||
folder_id: string;
|
||||
}
|
||||
// oxlint-disable-next-line no-restricted-types -- Needed to support empty
|
||||
| {}
|
||||
);
|
||||
|
||||
export const Route = createFileRoute("/workspaces/$workspaceId/")({
|
||||
component: RouteComponent,
|
||||
validateSearch: (search: Record<string, unknown>): WorkspaceSearchSchema => {
|
||||
const base: Pick<WorkspaceSearchSchema, "environment_id" | "cookie_jar_id"> = {
|
||||
environment_id: search.environment_id as string,
|
||||
cookie_jar_id: search.cookie_jar_id as string,
|
||||
};
|
||||
|
||||
const requestId = search.request_id as string | undefined;
|
||||
const folderId = search.folder_id as string | undefined;
|
||||
if (requestId != null) {
|
||||
return { ...base, request_id: requestId };
|
||||
}
|
||||
if (folderId) {
|
||||
return { ...base, folder_id: folderId };
|
||||
}
|
||||
return base;
|
||||
},
|
||||
});
|
||||
|
||||
function RouteComponent() {
|
||||
return <Workspace />;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { createFileRoute, Navigate, useParams } from "@tanstack/react-router";
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
// IMPORTANT: This is a deprecated route. Since the active request is optional, it was
|
||||
// moved from a path param to a query parameter. This route does a redirect to the
|
||||
// parent, while preserving the active request.
|
||||
|
||||
export const Route = createFileRoute("/workspaces/$workspaceId/requests/$requestId")({
|
||||
component: RouteComponent,
|
||||
});
|
||||
|
||||
function RouteComponent() {
|
||||
const { workspaceId, requestId } = useParams({
|
||||
from: "/workspaces/$workspaceId/requests/$requestId",
|
||||
});
|
||||
return (
|
||||
<Navigate
|
||||
to="/workspaces/$workspaceId"
|
||||
params={{ workspaceId }}
|
||||
search={(prev) => ({ ...prev, requestId })}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
import type { SettingsTab } from "../../../components/Settings/Settings";
|
||||
import Settings from "../../../components/Settings/Settings";
|
||||
|
||||
interface SettingsSearchSchema {
|
||||
tab?: SettingsTab;
|
||||
}
|
||||
|
||||
export const Route = createFileRoute("/workspaces/$workspaceId/settings")({
|
||||
component: RouteComponent,
|
||||
validateSearch: (search: Record<string, unknown>): SettingsSearchSchema => ({
|
||||
tab: (search.tab ?? "general") as SettingsTab,
|
||||
}),
|
||||
});
|
||||
|
||||
function RouteComponent() {
|
||||
return <Settings />;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
import { RedirectToLatestWorkspace } from "../../components/RedirectToLatestWorkspace";
|
||||
|
||||
export const Route = createFileRoute("/workspaces/")({
|
||||
component: RouteComponent,
|
||||
});
|
||||
|
||||
function RouteComponent() {
|
||||
return <RedirectToLatestWorkspace />;
|
||||
}
|
||||
Reference in New Issue
Block a user