mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
fix: backend none templates (#241)
This commit is contained in:
@@ -8,24 +8,20 @@ import { routeTree } from "./routeTree.gen";
|
||||
import Loader from "./components/loader";
|
||||
import "./index.css";
|
||||
{{else}}
|
||||
import {
|
||||
QueryCache,
|
||||
QueryClient,
|
||||
QueryClientProvider,
|
||||
} from "@tanstack/react-query";
|
||||
import { createRouter as createTanstackRouter } from "@tanstack/react-router";
|
||||
import Loader from "./components/loader";
|
||||
import "./index.css";
|
||||
import { routeTree } from "./routeTree.gen";
|
||||
{{#if (eq api "trpc")}}
|
||||
import { QueryCache, QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { createTRPCClient, httpBatchLink } from "@trpc/client";
|
||||
import { createTRPCOptionsProxy } from "@trpc/tanstack-react-query";
|
||||
import { toast } from "sonner";
|
||||
import type { AppRouter } from "../../server/src/routers";
|
||||
import { TRPCProvider } from "./utils/trpc";
|
||||
{{/if}}
|
||||
{{#if (eq api "orpc")}}
|
||||
import { orpc, ORPCContext, queryClient } from "./utils/orpc";
|
||||
{{else if (eq api "orpc")}}
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { orpc, ORPCContext, queryClient as orpcQueryClient } from "./utils/orpc";
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
@@ -62,7 +58,6 @@ export function createRouter() {
|
||||
}),
|
||||
queryClient,
|
||||
);
|
||||
|
||||
return router;
|
||||
}
|
||||
{{else}}
|
||||
@@ -103,6 +98,8 @@ const trpc = createTRPCOptionsProxy({
|
||||
client: trpcClient,
|
||||
queryClient: queryClient,
|
||||
});
|
||||
{{else if (eq api "orpc")}}
|
||||
const queryClient = orpcQueryClient;
|
||||
{{/if}}
|
||||
|
||||
export const createRouter = () => {
|
||||
@@ -112,33 +109,37 @@ export const createRouter = () => {
|
||||
defaultPreloadStaleTime: 0,
|
||||
{{#if (eq api "trpc")}}
|
||||
context: { trpc, queryClient },
|
||||
{{/if}}
|
||||
{{#if (eq api "orpc")}}
|
||||
{{else if (eq api "orpc")}}
|
||||
context: { orpc, queryClient },
|
||||
{{else}}
|
||||
context: { },
|
||||
{{/if}}
|
||||
defaultPendingComponent: () => <Loader />,
|
||||
defaultNotFoundComponent: () => <div>Not Found</div>,
|
||||
{{#if (eq api "trpc")}}
|
||||
Wrap: ({ children }) => (
|
||||
<QueryClientProvider client={queryClient}>
|
||||
{{#if (eq api "trpc")}}
|
||||
<TRPCProvider trpcClient={trpcClient} queryClient={queryClient}>
|
||||
{children}
|
||||
</TRPCProvider>
|
||||
{{/if}}
|
||||
{{#if (eq api "orpc")}}
|
||||
</QueryClientProvider>
|
||||
),
|
||||
{{else if (eq api "orpc")}}
|
||||
Wrap: ({ children }) => (
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<ORPCContext.Provider value={orpc}>
|
||||
{children}
|
||||
</ORPCContext.Provider>
|
||||
{{/if}}
|
||||
</QueryClientProvider>
|
||||
),
|
||||
{{else}}
|
||||
Wrap: ({ children }) => <>{children}</>,
|
||||
{{/if}}
|
||||
});
|
||||
|
||||
return router;
|
||||
};
|
||||
{{/if}}
|
||||
|
||||
// Register the router instance for type safety
|
||||
declare module "@tanstack/react-router" {
|
||||
interface Register {
|
||||
router: ReturnType<typeof createRouter>;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { Toaster } from "@/components/ui/sonner";
|
||||
{{#unless (eq backend "convex")}} {{#unless (eq api "none")}}
|
||||
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
||||
{{/unless}} {{/unless}}
|
||||
import {
|
||||
HeadContent,
|
||||
Outlet,
|
||||
@@ -10,7 +12,9 @@ import {
|
||||
import { TanStackRouterDevtools } from "@tanstack/react-router-devtools";
|
||||
import Header from "../components/header";
|
||||
import appCss from "../index.css?url";
|
||||
{{#unless (and (eq api "none") (not (eq backend "convex"))}}
|
||||
import type { QueryClient } from "@tanstack/react-query";
|
||||
{{/unless}}
|
||||
import Loader from "@/components/loader";
|
||||
|
||||
{{#if (eq backend "convex")}}
|
||||
@@ -25,12 +29,14 @@ export interface RouterAppContext {
|
||||
trpc: TRPCOptionsProxy<AppRouter>;
|
||||
queryClient: QueryClient;
|
||||
}
|
||||
{{/if}}
|
||||
{{#if (eq api "orpc")}}
|
||||
{{else if (eq api "orpc")}}
|
||||
import type { orpc } from "@/utils/orpc";
|
||||
export interface RouterAppContext {
|
||||
orpc: typeof orpc;
|
||||
queryClient: QueryClient;
|
||||
}
|
||||
{{else}}
|
||||
export interface RouterAppContext {
|
||||
}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
@@ -75,7 +81,11 @@ function RootDocument() {
|
||||
</div>
|
||||
<Toaster richColors />
|
||||
<TanStackRouterDevtools position="bottom-left" />
|
||||
{{#unless (eq backend "convex")}}
|
||||
{{#unless (eq api "none")}}
|
||||
<ReactQueryDevtools position="bottom" buttonPosition="bottom-right" />
|
||||
{{/unless}}
|
||||
{{/unless}}
|
||||
<Scripts />
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -3,14 +3,14 @@ import { createFileRoute } from "@tanstack/react-router";
|
||||
import { convexQuery } from "@convex-dev/react-query";
|
||||
import { useSuspenseQuery } from "@tanstack/react-query";
|
||||
import { api } from "@{{projectName}}/backend/convex/_generated/api.js";
|
||||
{{else}}
|
||||
{{else if (or (eq api "trpc") (eq api "orpc"))}}
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
{{#if (eq api "trpc")}}
|
||||
import { useTRPC } from "@/utils/trpc";
|
||||
{{/if}}
|
||||
{{#if (eq api "orpc")}}
|
||||
import { useORPC } from "@/utils/orpc";
|
||||
{{/if}}
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
{{/if}}
|
||||
|
||||
export const Route = createFileRoute("/")({
|
||||
@@ -36,15 +36,12 @@ const TITLE_TEXT = `
|
||||
function HomeComponent() {
|
||||
{{#if (eq backend "convex")}}
|
||||
const healthCheck = useSuspenseQuery(convexQuery(api.healthCheck.get, {}));
|
||||
{{else}}
|
||||
{{#if (eq api "trpc")}}
|
||||
{{else if (eq api "trpc")}}
|
||||
const trpc = useTRPC();
|
||||
const healthCheck = useQuery(trpc.healthCheck.queryOptions());
|
||||
{{/if}}
|
||||
{{#if (eq api "orpc")}}
|
||||
{{else if (eq api "orpc")}}
|
||||
const orpc = useORPC();
|
||||
const healthCheck = useQuery(orpc.healthCheck.queryOptions());
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
return (
|
||||
@@ -53,8 +50,8 @@ function HomeComponent() {
|
||||
<div className="grid gap-6">
|
||||
<section className="rounded-lg border p-4">
|
||||
<h2 className="mb-2 font-medium">API Status</h2>
|
||||
{{#if (eq backend "convex")}}
|
||||
<div className="flex items-center gap-2">
|
||||
{{#if (eq backend "convex")}}
|
||||
<div
|
||||
className={`h-2 w-2 rounded-full ${healthCheck.data === "OK" ? "bg-green-500" : healthCheck.isLoading ? "bg-orange-400" : "bg-red-500"}`}
|
||||
/>
|
||||
@@ -65,19 +62,23 @@ function HomeComponent() {
|
||||
? "Connected"
|
||||
: "Error"}
|
||||
</span>
|
||||
{{else}}
|
||||
<div
|
||||
className={`h-2 w-2 rounded-full ${healthCheck.data ? "bg-green-500" : "bg-red-500"}`}
|
||||
/>
|
||||
<span className="text-muted-foreground text-sm">
|
||||
{healthCheck.isLoading
|
||||
? "Checking..."
|
||||
: healthCheck.data
|
||||
? "Connected"
|
||||
: "Disconnected"}
|
||||
</span>
|
||||
{{/if}}
|
||||
</div>
|
||||
{{else}}
|
||||
{{#unless (eq api "none")}}
|
||||
<div className="flex items-center gap-2">
|
||||
<div
|
||||
className={`h-2 w-2 rounded-full ${healthCheck.data ? "bg-green-500" : "bg-red-500"}`}
|
||||
/>
|
||||
<span className="text-muted-foreground text-sm">
|
||||
{healthCheck.isLoading
|
||||
? "Checking..."
|
||||
: healthCheck.data
|
||||
? "Connected"
|
||||
: "Disconnected"}
|
||||
</span>
|
||||
</div>
|
||||
{{/unless}}
|
||||
{{/if}}
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user