mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
add solid
This commit is contained in:
30
apps/cli/templates/api/orpc/web/solid/src/utils/orpc.ts.hbs
Normal file
30
apps/cli/templates/api/orpc/web/solid/src/utils/orpc.ts.hbs
Normal file
@@ -0,0 +1,30 @@
|
||||
import { createORPCClient } from "@orpc/client";
|
||||
import { RPCLink } from "@orpc/client/fetch";
|
||||
import { createORPCSolidQueryUtils } from "@orpc/solid-query";
|
||||
import { QueryCache, QueryClient } from "@tanstack/solid-query";
|
||||
import type { appRouter } from "../../../server/src/routers/index";
|
||||
import type { RouterClient } from "@orpc/server";
|
||||
|
||||
export const queryClient = new QueryClient({
|
||||
queryCache: new QueryCache({
|
||||
onError: (error) => {
|
||||
console.error(`Error: ${error.message}`);
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
export const link = new RPCLink({
|
||||
url: `${import.meta.env.VITE_SERVER_URL}/rpc`,
|
||||
{{#if auth}}
|
||||
fetch(url, options) {
|
||||
return fetch(url, {
|
||||
...options,
|
||||
credentials: "include",
|
||||
});
|
||||
},
|
||||
{{/if}}
|
||||
});
|
||||
|
||||
export const client: RouterClient<typeof appRouter> = createORPCClient(link);
|
||||
|
||||
export const orpc = createORPCSolidQueryUtils(client);
|
||||
@@ -0,0 +1,132 @@
|
||||
import { authClient } from "@/lib/auth-client";
|
||||
import { createForm } from "@tanstack/solid-form";
|
||||
import { useNavigate } from "@tanstack/solid-router";
|
||||
import { z } from "zod";
|
||||
import { For } from "solid-js";
|
||||
|
||||
export default function SignInForm({
|
||||
onSwitchToSignUp,
|
||||
}: {
|
||||
onSwitchToSignUp: () => void;
|
||||
}) {
|
||||
const navigate = useNavigate({
|
||||
from: "/",
|
||||
});
|
||||
|
||||
const form = createForm(() => ({
|
||||
defaultValues: {
|
||||
email: "",
|
||||
password: "",
|
||||
},
|
||||
onSubmit: async ({ value }) => {
|
||||
await authClient.signIn.email(
|
||||
{
|
||||
email: value.email,
|
||||
password: value.password,
|
||||
},
|
||||
{
|
||||
onSuccess: () => {
|
||||
navigate({
|
||||
to: "/dashboard",
|
||||
});
|
||||
console.log("Sign in successful");
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error(error.error.message);
|
||||
},
|
||||
},
|
||||
);
|
||||
},
|
||||
validators: {
|
||||
onSubmit: z.object({
|
||||
email: z.string().email("Invalid email address"),
|
||||
password: z.string().min(8, "Password must be at least 8 characters"),
|
||||
}),
|
||||
},
|
||||
}));
|
||||
|
||||
return (
|
||||
<div class="mx-auto w-full mt-10 max-w-md p-6">
|
||||
<h1 class="mb-6 text-center text-3xl font-bold">Welcome Back</h1>
|
||||
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
void form.handleSubmit();
|
||||
}}
|
||||
class="space-y-4"
|
||||
>
|
||||
<div>
|
||||
<form.Field name="email">
|
||||
{(field) => (
|
||||
<div class="space-y-2">
|
||||
<label for={field().name}>Email</label>
|
||||
<input
|
||||
id={field().name}
|
||||
name={field().name}
|
||||
type="email"
|
||||
value={field().state.value}
|
||||
onBlur={field().handleBlur}
|
||||
onInput={(e) => field().handleChange(e.currentTarget.value)} // Use onInput and currentTarget
|
||||
class="w-full rounded border p-2" // Example basic styling
|
||||
/>
|
||||
<For each={field().state.meta.errors}>
|
||||
{(error) => (
|
||||
<p class="text-sm text-red-600">{error?.message}</p>
|
||||
)}
|
||||
</For>
|
||||
</div>
|
||||
)}
|
||||
</form.Field>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<form.Field name="password">
|
||||
{(field) => (
|
||||
<div class="space-y-2">
|
||||
<label for={field().name}>Password</label>
|
||||
<input
|
||||
id={field().name}
|
||||
name={field().name}
|
||||
type="password"
|
||||
value={field().state.value}
|
||||
onBlur={field().handleBlur}
|
||||
onInput={(e) => field().handleChange(e.currentTarget.value)}
|
||||
class="w-full rounded border p-2"
|
||||
/>
|
||||
<For each={field().state.meta.errors}>
|
||||
{(error) => (
|
||||
<p class="text-sm text-red-600">{error?.message}</p>
|
||||
)}
|
||||
</For>
|
||||
</div>
|
||||
)}
|
||||
</form.Field>
|
||||
</div>
|
||||
|
||||
<form.Subscribe>
|
||||
{(state) => (
|
||||
<button
|
||||
type="submit"
|
||||
class="w-full rounded bg-indigo-600 p-2 text-white hover:bg-indigo-700 disabled:opacity-50"
|
||||
disabled={!state().canSubmit || state().isSubmitting}
|
||||
>
|
||||
{state().isSubmitting ? "Submitting..." : "Sign In"}
|
||||
</button>
|
||||
)}
|
||||
</form.Subscribe>
|
||||
</form>
|
||||
|
||||
<div class="mt-4 text-center">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onSwitchToSignUp}
|
||||
class="text-sm text-indigo-600 hover:text-indigo-800 hover:underline" // Example basic styling
|
||||
>
|
||||
Need an account? Sign Up
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
import { authClient } from "@/lib/auth-client";
|
||||
import { createForm } from "@tanstack/solid-form";
|
||||
import { useNavigate } from "@tanstack/solid-router";
|
||||
import { z } from "zod";
|
||||
import { For } from "solid-js";
|
||||
|
||||
export default function SignUpForm({
|
||||
onSwitchToSignIn,
|
||||
}: {
|
||||
onSwitchToSignIn: () => void;
|
||||
}) {
|
||||
const navigate = useNavigate({
|
||||
from: "/",
|
||||
});
|
||||
|
||||
const form = createForm(() => ({
|
||||
defaultValues: {
|
||||
email: "",
|
||||
password: "",
|
||||
name: "",
|
||||
},
|
||||
onSubmit: async ({ value }) => {
|
||||
await authClient.signUp.email(
|
||||
{
|
||||
email: value.email,
|
||||
password: value.password,
|
||||
name: value.name,
|
||||
},
|
||||
{
|
||||
onSuccess: () => {
|
||||
navigate({
|
||||
to: "/dashboard",
|
||||
});
|
||||
console.log("Sign up successful");
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error(error.error.message);
|
||||
},
|
||||
},
|
||||
);
|
||||
},
|
||||
validators: {
|
||||
onSubmit: z.object({
|
||||
name: z.string().min(2, "Name must be at least 2 characters"),
|
||||
email: z.string().email("Invalid email address"),
|
||||
password: z.string().min(8, "Password must be at least 8 characters"),
|
||||
}),
|
||||
},
|
||||
}));
|
||||
|
||||
return (
|
||||
<div class="mx-auto w-full mt-10 max-w-md p-6">
|
||||
<h1 class="mb-6 text-center text-3xl font-bold">Create Account</h1>
|
||||
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
void form.handleSubmit();
|
||||
}}
|
||||
class="space-y-4"
|
||||
>
|
||||
<div>
|
||||
<form.Field name="name">
|
||||
{(field) => (
|
||||
<div class="space-y-2">
|
||||
<label for={field().name}>Name</label>
|
||||
<input
|
||||
id={field().name}
|
||||
name={field().name}
|
||||
value={field().state.value}
|
||||
onBlur={field().handleBlur}
|
||||
onInput={(e) => field().handleChange(e.currentTarget.value)}
|
||||
class="w-full rounded border p-2"
|
||||
/>
|
||||
<For each={field().state.meta.errors}>
|
||||
{(error) => (
|
||||
<p class="text-sm text-red-600">{error?.message}</p>
|
||||
)}
|
||||
</For>
|
||||
</div>
|
||||
)}
|
||||
</form.Field>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<form.Field name="email">
|
||||
{(field) => (
|
||||
<div class="space-y-2">
|
||||
<label for={field().name}>Email</label>
|
||||
<input
|
||||
id={field().name}
|
||||
name={field().name}
|
||||
type="email"
|
||||
value={field().state.value}
|
||||
onBlur={field().handleBlur}
|
||||
onInput={(e) => field().handleChange(e.currentTarget.value)}
|
||||
class="w-full rounded border p-2"
|
||||
/>
|
||||
<For each={field().state.meta.errors}>
|
||||
{(error) => (
|
||||
<p class="text-sm text-red-600">{error?.message}</p>
|
||||
)}
|
||||
</For>
|
||||
</div>
|
||||
)}
|
||||
</form.Field>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<form.Field name="password">
|
||||
{(field) => (
|
||||
<div class="space-y-2">
|
||||
<label for={field().name}>Password</label>
|
||||
<input
|
||||
id={field().name}
|
||||
name={field().name}
|
||||
type="password"
|
||||
value={field().state.value}
|
||||
onBlur={field().handleBlur}
|
||||
onInput={(e) => field().handleChange(e.currentTarget.value)}
|
||||
class="w-full rounded border p-2"
|
||||
/>
|
||||
<For each={field().state.meta.errors}>
|
||||
{(error) => (
|
||||
<p class="text-sm text-red-600">{error?.message}</p>
|
||||
)}
|
||||
</For>
|
||||
</div>
|
||||
)}
|
||||
</form.Field>
|
||||
</div>
|
||||
|
||||
<form.Subscribe>
|
||||
{(state) => (
|
||||
<button
|
||||
type="submit"
|
||||
class="w-full rounded bg-indigo-600 p-2 text-white hover:bg-indigo-700 disabled:opacity-50"
|
||||
disabled={!state().canSubmit || state().isSubmitting}
|
||||
>
|
||||
{state().isSubmitting ? "Submitting..." : "Sign Up"}
|
||||
</button>
|
||||
)}
|
||||
</form.Subscribe>
|
||||
</form>
|
||||
|
||||
<div class="mt-4 text-center">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onSwitchToSignIn}
|
||||
class="text-sm text-indigo-600 hover:text-indigo-800 hover:underline"
|
||||
>
|
||||
Already have an account? Sign In
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { authClient } from "@/lib/auth-client";
|
||||
import { useNavigate, Link } from "@tanstack/solid-router";
|
||||
import { createSignal, Show } from "solid-js";
|
||||
|
||||
export default function UserMenu() {
|
||||
const navigate = useNavigate();
|
||||
const session = authClient.useSession();
|
||||
const [isMenuOpen, setIsMenuOpen] = createSignal(false);
|
||||
|
||||
return (
|
||||
<div class="relative inline-block text-left">
|
||||
<Show when={session().isPending}>
|
||||
<div class="h-9 w-24 animate-pulse rounded" />
|
||||
</Show>
|
||||
|
||||
<Show when={!session().isPending && !session().data}>
|
||||
<Link to="/login" class="inline-block border rounded px-4 text-sm">
|
||||
Sign In
|
||||
</Link>
|
||||
</Show>
|
||||
|
||||
<Show when={!session().isPending && session().data}>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-block border rounded px-4 text-sm"
|
||||
onClick={() => setIsMenuOpen(!isMenuOpen())}
|
||||
>
|
||||
{session().data?.user.name}
|
||||
</button>
|
||||
|
||||
<Show when={isMenuOpen()}>
|
||||
<div class="absolute right-0 mt-2 w-56 rounded p-1 shadow-sm">
|
||||
<div class="px-4 text-sm">{session().data?.user.email}</div>
|
||||
<button
|
||||
class="mt-1 w-full border rounded px-4 text-center text-sm"
|
||||
onClick={() => {
|
||||
setIsMenuOpen(false);
|
||||
authClient.signOut({
|
||||
fetchOptions: {
|
||||
onSuccess: () => {
|
||||
navigate({ to: "/" });
|
||||
},
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
Sign Out
|
||||
</button>
|
||||
</div>
|
||||
</Show>
|
||||
</Show>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
5
apps/cli/templates/auth/web/solid/src/lib/auth-client.ts
Normal file
5
apps/cli/templates/auth/web/solid/src/lib/auth-client.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { createAuthClient } from "better-auth/solid";
|
||||
|
||||
export const authClient = createAuthClient({
|
||||
baseURL: import.meta.env.VITE_SERVER_URL,
|
||||
});
|
||||
38
apps/cli/templates/auth/web/solid/src/routes/dashboard.tsx
Normal file
38
apps/cli/templates/auth/web/solid/src/routes/dashboard.tsx
Normal file
@@ -0,0 +1,38 @@
|
||||
import { authClient } from "@/lib/auth-client";
|
||||
import { orpc } from "@/utils/orpc";
|
||||
import { useQuery } from "@tanstack/solid-query";
|
||||
import { createFileRoute } from "@tanstack/solid-router";
|
||||
import { createEffect, Show } from "solid-js";
|
||||
|
||||
export const Route = createFileRoute("/dashboard")({
|
||||
component: RouteComponent,
|
||||
});
|
||||
|
||||
function RouteComponent() {
|
||||
const session = authClient.useSession();
|
||||
const navigate = Route.useNavigate();
|
||||
|
||||
const privateData = useQuery(() => orpc.privateData.queryOptions());
|
||||
|
||||
createEffect(() => {
|
||||
if (!session().data && !session().isPending) {
|
||||
navigate({
|
||||
to: "/login",
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Show when={session().isPending}>
|
||||
<div>Loading...</div>
|
||||
</Show>
|
||||
|
||||
<Show when={!session().isPending && session().data}>
|
||||
<h1>Dashboard</h1>
|
||||
<p>Welcome {session().data?.user.name}</p>
|
||||
<p>privateData: {privateData.data?.message}</p>
|
||||
</Show>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
23
apps/cli/templates/auth/web/solid/src/routes/login.tsx
Normal file
23
apps/cli/templates/auth/web/solid/src/routes/login.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
import SignInForm from "@/components/sign-in-form";
|
||||
import SignUpForm from "@/components/sign-up-form";
|
||||
import { createFileRoute } from "@tanstack/solid-router";
|
||||
import { createSignal, Match, Switch } from "solid-js";
|
||||
|
||||
export const Route = createFileRoute("/login")({
|
||||
component: RouteComponent,
|
||||
});
|
||||
|
||||
function RouteComponent() {
|
||||
const [showSignIn, setShowSignIn] = createSignal(false);
|
||||
|
||||
return (
|
||||
<Switch>
|
||||
<Match when={showSignIn()}>
|
||||
<SignInForm onSwitchToSignUp={() => setShowSignIn(false)} />
|
||||
</Match>
|
||||
<Match when={!showSignIn()}>
|
||||
<SignUpForm onSwitchToSignIn={() => setShowSignIn(true)} />
|
||||
</Match>
|
||||
</Switch>
|
||||
);
|
||||
}
|
||||
@@ -6,5 +6,5 @@ generator client {
|
||||
|
||||
datasource db {
|
||||
provider = "sqlite"
|
||||
url = "file:../local.db"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
132
apps/cli/templates/examples/todo/web/solid/src/routes/todos.tsx
Normal file
132
apps/cli/templates/examples/todo/web/solid/src/routes/todos.tsx
Normal file
@@ -0,0 +1,132 @@
|
||||
import { createFileRoute } from "@tanstack/solid-router";
|
||||
import { Loader2, Trash2 } from "lucide-solid";
|
||||
import { createSignal, For, Show } from "solid-js";
|
||||
import { orpc } from "@/utils/orpc";
|
||||
import { useQuery, useMutation } from "@tanstack/solid-query";
|
||||
|
||||
export const Route = createFileRoute("/todos")({
|
||||
component: TodosRoute,
|
||||
});
|
||||
|
||||
function TodosRoute() {
|
||||
const [newTodoText, setNewTodoText] = createSignal("");
|
||||
|
||||
const todos = useQuery(() => orpc.todo.getAll.queryOptions());
|
||||
|
||||
const createMutation = useMutation(() =>
|
||||
orpc.todo.create.mutationOptions({
|
||||
onSuccess: () => {
|
||||
todos.refetch();
|
||||
setNewTodoText("");
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
const toggleMutation = useMutation(() =>
|
||||
orpc.todo.toggle.mutationOptions({
|
||||
onSuccess: () => todos.refetch(),
|
||||
}),
|
||||
);
|
||||
|
||||
const deleteMutation = useMutation(() =>
|
||||
orpc.todo.delete.mutationOptions({
|
||||
onSuccess: () => todos.refetch(),
|
||||
}),
|
||||
);
|
||||
|
||||
const handleAddTodo = (e: Event) => {
|
||||
e.preventDefault();
|
||||
if (newTodoText().trim()) {
|
||||
createMutation.mutate({ text: newTodoText() });
|
||||
}
|
||||
};
|
||||
|
||||
const handleToggleTodo = (id: number, completed: boolean) => {
|
||||
toggleMutation.mutate({ id, completed: !completed });
|
||||
};
|
||||
|
||||
const handleDeleteTodo = (id: number) => {
|
||||
deleteMutation.mutate({ id });
|
||||
};
|
||||
|
||||
return (
|
||||
<div class="mx-auto w-full max-w-md py-10">
|
||||
<div class="rounded-lg border p-6 shadow-sm">
|
||||
<div class="mb-4">
|
||||
<h2 class="text-xl font-semibold">Todo List</h2>
|
||||
<p class="text-sm">Manage your tasks efficiently</p>
|
||||
</div>
|
||||
<div>
|
||||
<form
|
||||
onSubmit={handleAddTodo}
|
||||
class="mb-6 flex items-center space-x-2"
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
value={newTodoText()}
|
||||
onInput={(e) => setNewTodoText(e.currentTarget.value)}
|
||||
placeholder="Add a new task..."
|
||||
disabled={createMutation.isPending}
|
||||
class="w-full rounded-md border p-2 text-sm"
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={createMutation.isPending || !newTodoText().trim()}
|
||||
class="rounded-md bg-blue-600 px-4 py-2 text-sm text-white disabled:opacity-50"
|
||||
>
|
||||
<Show when={createMutation.isPending} fallback="Add">
|
||||
<Loader2 class="h-4 w-4 animate-spin" />
|
||||
</Show>
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<Show when={todos.isLoading}>
|
||||
<div class="flex justify-center py-4">
|
||||
<Loader2 class="h-6 w-6 animate-spin" />
|
||||
</div>
|
||||
</Show>
|
||||
|
||||
<Show when={!todos.isLoading && todos.data?.length === 0}>
|
||||
<p class="py-4 text-center">No todos yet. Add one above!</p>
|
||||
</Show>
|
||||
|
||||
<Show when={!todos.isLoading}>
|
||||
<ul class="space-y-2">
|
||||
<For each={todos.data}>
|
||||
{(todo) => (
|
||||
<li class="flex items-center justify-between rounded-md border p-2">
|
||||
<div class="flex items-center space-x-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={todo.completed}
|
||||
onChange={() =>
|
||||
handleToggleTodo(todo.id, todo.completed)
|
||||
}
|
||||
id={`todo-${todo.id}`}
|
||||
class="h-4 w-4"
|
||||
/>
|
||||
<label
|
||||
for={`todo-${todo.id}`}
|
||||
class={todo.completed ? "line-through" : ""}
|
||||
>
|
||||
{todo.text}
|
||||
</label>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleDeleteTodo(todo.id)}
|
||||
aria-label="Delete todo"
|
||||
class="ml-2 rounded-md p-1"
|
||||
>
|
||||
<Trash2 class="h-4 w-4" />
|
||||
</button>
|
||||
</li>
|
||||
)}
|
||||
</For>
|
||||
</ul>
|
||||
</Show>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
{{! Import VitePWA only if 'pwa' addon is selected }}
|
||||
{{#if (includes addons "pwa")}}
|
||||
import { VitePWA } from "vite-plugin-pwa";
|
||||
{{/if}}
|
||||
@@ -12,24 +11,21 @@ export default defineConfig({
|
||||
tailwindcss(),
|
||||
reactRouter(),
|
||||
tsconfigPaths(),
|
||||
{{! Add VitePWA plugin config only if 'pwa' addon is selected }}
|
||||
{{#if (includes addons "pwa")}}
|
||||
VitePWA({
|
||||
registerType: "autoUpdate",
|
||||
manifest: {
|
||||
// Use context variables for better naming
|
||||
name: "{{projectName}}",
|
||||
short_name: "{{projectName}}",
|
||||
description: "{{projectName}} - PWA Application",
|
||||
theme_color: "#0c0c0c",
|
||||
// Add more manifest options as needed
|
||||
},
|
||||
pwaAssets: {
|
||||
disabled: false, // Set to false to enable asset generation
|
||||
config: true, // Use pwa-assets.config.ts
|
||||
disabled: false,
|
||||
config: true,
|
||||
},
|
||||
devOptions: {
|
||||
enabled: true, // Enable PWA features in dev mode
|
||||
enabled: true,
|
||||
},
|
||||
}),
|
||||
{{/if}}
|
||||
|
||||
@@ -16,19 +16,17 @@ export default defineConfig({
|
||||
VitePWA({
|
||||
registerType: "autoUpdate",
|
||||
manifest: {
|
||||
// Use context variables for better naming
|
||||
name: "{{projectName}}",
|
||||
short_name: "{{projectName}}",
|
||||
description: "{{projectName}} - PWA Application",
|
||||
theme_color: "#0c0c0c",
|
||||
// Add more manifest options as needed
|
||||
},
|
||||
pwaAssets: {
|
||||
disabled: false, // Set to false to enable asset generation
|
||||
config: true, // Use pwa-assets.config.ts
|
||||
disabled: false,
|
||||
config: true,
|
||||
},
|
||||
devOptions: {
|
||||
enabled: true, // Enable PWA features in dev mode
|
||||
enabled: true,
|
||||
},
|
||||
}),
|
||||
{{/if}}
|
||||
|
||||
7
apps/cli/templates/frontend/solid/_gitignore
Normal file
7
apps/cli/templates/frontend/solid/_gitignore
Normal file
@@ -0,0 +1,7 @@
|
||||
node_modules
|
||||
.DS_Store
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
.env
|
||||
.env.*
|
||||
13
apps/cli/templates/frontend/solid/index.html
Normal file
13
apps/cli/templates/frontend/solid/index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
33
apps/cli/templates/frontend/solid/package.json
Normal file
33
apps/cli/templates/frontend/solid/package.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "web",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite --port 3001",
|
||||
"build": "vite build && tsc",
|
||||
"serve": "vite preview",
|
||||
"test": "vitest run"
|
||||
},
|
||||
"dependencies": {
|
||||
"@orpc/client": "^1.1.1",
|
||||
"@orpc/server": "^1.1.1",
|
||||
"@orpc/solid-query": "^1.1.1",
|
||||
"@tailwindcss/vite": "^4.0.6",
|
||||
"@tanstack/router-plugin": "^1.109.2",
|
||||
"@tanstack/solid-form": "^1.9.0",
|
||||
"@tanstack/solid-query": "^5.75.0",
|
||||
"@tanstack/solid-query-devtools": "^5.75.0",
|
||||
"@tanstack/solid-router": "^1.110.0",
|
||||
"@tanstack/solid-router-devtools": "^1.109.2",
|
||||
"better-auth": "^1.2.7",
|
||||
"lucide-solid": "^0.507.0",
|
||||
"solid-js": "^1.9.4",
|
||||
"tailwindcss": "^4.0.6",
|
||||
"zod": "^3.24.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.7.2",
|
||||
"vite": "^6.0.11",
|
||||
"vite-plugin-solid": "^2.11.2"
|
||||
}
|
||||
}
|
||||
3
apps/cli/templates/frontend/solid/public/robots.txt
Normal file
3
apps/cli/templates/frontend/solid/public/robots.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
||||
@@ -0,0 +1,38 @@
|
||||
import { Link } from "@tanstack/solid-router";
|
||||
{{#if auth}}
|
||||
import UserMenu from "./user-menu";
|
||||
{{/if}}
|
||||
import { For } from "solid-js";
|
||||
|
||||
export default function Header() {
|
||||
const links = [
|
||||
{ to: "/", label: "Home" },
|
||||
{{#if auth}}
|
||||
{ to: "/dashboard", label: "Dashboard" },
|
||||
{{/if}}
|
||||
{{#if (includes examples "todo")}}
|
||||
{ to: "/todos", label: "Todos" },
|
||||
{{/if}}
|
||||
{{#if (includes examples "ai")}}
|
||||
{ to: "/ai", label: "AI Chat" },
|
||||
{{/if}}
|
||||
];
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div class="flex flex-row items-center justify-between px-2 py-1">
|
||||
<nav class="flex gap-4 text-lg">
|
||||
<For each={links}>
|
||||
{(link) => <Link to={link.to}>{link.label}</Link>}
|
||||
</For>
|
||||
</nav>
|
||||
<div class="flex items-center gap-2">
|
||||
{{#if auth}}
|
||||
<UserMenu />
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Loader2 } from "lucide-solid";
|
||||
|
||||
export default function Loader() {
|
||||
return (
|
||||
<div class="flex h-full items-center justify-center pt-8">
|
||||
<Loader2 class="animate-spin" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
32
apps/cli/templates/frontend/solid/src/main.tsx.hbs
Normal file
32
apps/cli/templates/frontend/solid/src/main.tsx.hbs
Normal file
@@ -0,0 +1,32 @@
|
||||
import { RouterProvider, createRouter } from "@tanstack/solid-router";
|
||||
import { render } from "solid-js/web";
|
||||
import { routeTree } from "./routeTree.gen";
|
||||
import "./styles.css";
|
||||
import { QueryClientProvider } from "@tanstack/solid-query";
|
||||
import { queryClient } from "./utils/orpc";
|
||||
|
||||
const router = createRouter({
|
||||
routeTree,
|
||||
defaultPreload: "intent",
|
||||
scrollRestoration: true,
|
||||
defaultPreloadStaleTime: 0,
|
||||
});
|
||||
|
||||
declare module "@tanstack/solid-router" {
|
||||
interface Register {
|
||||
router: typeof router;
|
||||
}
|
||||
}
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<RouterProvider router={router} />
|
||||
</QueryClientProvider>
|
||||
);
|
||||
}
|
||||
|
||||
const rootElement = document.getElementById("app");
|
||||
if (rootElement) {
|
||||
render(() => <App />, rootElement);
|
||||
}
|
||||
21
apps/cli/templates/frontend/solid/src/routes/__root.tsx.hbs
Normal file
21
apps/cli/templates/frontend/solid/src/routes/__root.tsx.hbs
Normal file
@@ -0,0 +1,21 @@
|
||||
import Header from "@/components/header";
|
||||
import { Outlet, createRootRouteWithContext } from "@tanstack/solid-router";
|
||||
import { TanStackRouterDevtools } from "@tanstack/solid-router-devtools";
|
||||
import { SolidQueryDevtools } from "@tanstack/solid-query-devtools";
|
||||
|
||||
export const Route = createRootRouteWithContext()({
|
||||
component: RootComponent,
|
||||
});
|
||||
|
||||
function RootComponent() {
|
||||
return (
|
||||
<>
|
||||
<div class="grid grid-rows-[auto_1fr] h-svh">
|
||||
<Header />
|
||||
<Outlet />
|
||||
</div>
|
||||
<SolidQueryDevtools />
|
||||
<TanStackRouterDevtools />
|
||||
</>
|
||||
);
|
||||
}
|
||||
65
apps/cli/templates/frontend/solid/src/routes/index.tsx.hbs
Normal file
65
apps/cli/templates/frontend/solid/src/routes/index.tsx.hbs
Normal file
@@ -0,0 +1,65 @@
|
||||
import { createFileRoute } from "@tanstack/solid-router";
|
||||
import { useQuery } from "@tanstack/solid-query";
|
||||
import { orpc } from "../utils/orpc";
|
||||
import { Match, Switch } from "solid-js";
|
||||
|
||||
export const Route = createFileRoute("/")({
|
||||
component: App,
|
||||
});
|
||||
|
||||
const TITLE_TEXT = `
|
||||
██████╗ ███████╗████████╗████████╗███████╗██████╗
|
||||
██╔══██╗██╔════╝╚══██╔══╝╚══██╔══╝██╔════╝██╔══██╗
|
||||
██████╔╝█████╗ ██║ ██║ █████╗ ██████╔╝
|
||||
██╔══██╗██╔══╝ ██║ ██║ ██╔══╝ ██╔══██╗
|
||||
██████╔╝███████╗ ██║ ██║ ███████╗██║ ██║
|
||||
╚═════╝ ╚══════╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝
|
||||
|
||||
████████╗ ███████╗████████╗ █████╗ ██████╗██╗ ██╗
|
||||
╚══██╔══╝ ██╔════╝╚══██╔══╝██╔══██╗██╔════╝██║ ██╔╝
|
||||
██║ ███████╗ ██║ ███████║██║ █████╔╝
|
||||
██║ ╚════██║ ██║ ██╔══██║██║ ██╔═██╗
|
||||
██║ ███████║ ██║ ██║ ██║╚██████╗██║ ██╗
|
||||
╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝
|
||||
`;
|
||||
|
||||
function App() {
|
||||
const healthCheck = useQuery(() => orpc.healthCheck.queryOptions());
|
||||
|
||||
return (
|
||||
<div class="container mx-auto max-w-3xl px-4 py-2">
|
||||
<pre class="overflow-x-auto font-mono text-sm">{TITLE_TEXT}</pre>
|
||||
<div class="grid gap-6">
|
||||
<section class="rounded-lg border p-4">
|
||||
<h2 class="mb-2 font-medium">API Status</h2>
|
||||
<Switch>
|
||||
<Match when={healthCheck.isPending}>
|
||||
<div class="flex items-center gap-2">
|
||||
<div class="h-2 w-2 rounded-full bg-gray-500 animate-pulse" />{" "}
|
||||
<span class="text-sm text-muted-foreground">Checking...</span>
|
||||
</div>
|
||||
</Match>
|
||||
<Match when={healthCheck.isError}>
|
||||
<div class="flex items-center gap-2">
|
||||
<div class="h-2 w-2 rounded-full bg-red-500" />
|
||||
<span class="text-sm text-muted-foreground">Disconnected</span>
|
||||
</div>
|
||||
</Match>
|
||||
<Match when={healthCheck.isSuccess}>
|
||||
<div class="flex items-center gap-2">
|
||||
<div
|
||||
class={`h-2 w-2 rounded-full ${healthCheck.data ? "bg-green-500" : "bg-red-500"}`}
|
||||
/>
|
||||
<span class="text-sm text-muted-foreground">
|
||||
{healthCheck.data
|
||||
? "Connected"
|
||||
: "Disconnected (Success but no data)"}
|
||||
</span>
|
||||
</div>
|
||||
</Match>
|
||||
</Switch>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
132
apps/cli/templates/frontend/solid/src/routes/todos.tsx
Normal file
132
apps/cli/templates/frontend/solid/src/routes/todos.tsx
Normal file
@@ -0,0 +1,132 @@
|
||||
import { createFileRoute } from "@tanstack/solid-router";
|
||||
import { Loader2, Trash2 } from "lucide-solid";
|
||||
import { createSignal, For, Show } from "solid-js";
|
||||
import { orpc } from "@/utils/orpc";
|
||||
import { useQuery, useMutation } from "@tanstack/solid-query";
|
||||
|
||||
export const Route = createFileRoute("/todos")({
|
||||
component: TodosRoute,
|
||||
});
|
||||
|
||||
function TodosRoute() {
|
||||
const [newTodoText, setNewTodoText] = createSignal("");
|
||||
|
||||
const todos = useQuery(() => orpc.todo.getAll.queryOptions());
|
||||
|
||||
const createMutation = useMutation(() =>
|
||||
orpc.todo.create.mutationOptions({
|
||||
onSuccess: () => {
|
||||
todos.refetch();
|
||||
setNewTodoText("");
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
const toggleMutation = useMutation(() =>
|
||||
orpc.todo.toggle.mutationOptions({
|
||||
onSuccess: () => todos.refetch(),
|
||||
}),
|
||||
);
|
||||
|
||||
const deleteMutation = useMutation(() =>
|
||||
orpc.todo.delete.mutationOptions({
|
||||
onSuccess: () => todos.refetch(),
|
||||
}),
|
||||
);
|
||||
|
||||
const handleAddTodo = (e: Event) => {
|
||||
e.preventDefault();
|
||||
if (newTodoText().trim()) {
|
||||
createMutation.mutate({ text: newTodoText() });
|
||||
}
|
||||
};
|
||||
|
||||
const handleToggleTodo = (id: number, completed: boolean) => {
|
||||
toggleMutation.mutate({ id, completed: !completed });
|
||||
};
|
||||
|
||||
const handleDeleteTodo = (id: number) => {
|
||||
deleteMutation.mutate({ id });
|
||||
};
|
||||
|
||||
return (
|
||||
<div class="mx-auto w-full max-w-md py-10">
|
||||
<div class="rounded-lg border p-6 shadow-sm">
|
||||
<div class="mb-4">
|
||||
<h2 class="text-xl font-semibold">Todo List</h2>
|
||||
<p class="text-sm">Manage your tasks efficiently</p>
|
||||
</div>
|
||||
<div>
|
||||
<form
|
||||
onSubmit={handleAddTodo}
|
||||
class="mb-6 flex items-center space-x-2"
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
value={newTodoText()}
|
||||
onInput={(e) => setNewTodoText(e.currentTarget.value)}
|
||||
placeholder="Add a new task..."
|
||||
disabled={createMutation.isPending}
|
||||
class="w-full rounded-md border p-2 text-sm"
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={createMutation.isPending || !newTodoText().trim()}
|
||||
class="rounded-md bg-blue-600 px-4 py-2 text-sm text-white disabled:opacity-50"
|
||||
>
|
||||
<Show when={createMutation.isPending} fallback="Add">
|
||||
<Loader2 class="h-4 w-4 animate-spin" />
|
||||
</Show>
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<Show when={todos.isLoading}>
|
||||
<div class="flex justify-center py-4">
|
||||
<Loader2 class="h-6 w-6 animate-spin" />
|
||||
</div>
|
||||
</Show>
|
||||
|
||||
<Show when={!todos.isLoading && todos.data?.length === 0}>
|
||||
<p class="py-4 text-center">No todos yet. Add one above!</p>
|
||||
</Show>
|
||||
|
||||
<Show when={!todos.isLoading}>
|
||||
<ul class="space-y-2">
|
||||
<For each={todos.data}>
|
||||
{(todo) => (
|
||||
<li class="flex items-center justify-between rounded-md border p-2">
|
||||
<div class="flex items-center space-x-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={todo.completed}
|
||||
onChange={() =>
|
||||
handleToggleTodo(todo.id, todo.completed)
|
||||
}
|
||||
id={`todo-${todo.id}`}
|
||||
class="h-4 w-4"
|
||||
/>
|
||||
<label
|
||||
for={`todo-${todo.id}`}
|
||||
class={todo.completed ? "line-through" : ""}
|
||||
>
|
||||
{todo.text}
|
||||
</label>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleDeleteTodo(todo.id)}
|
||||
aria-label="Delete todo"
|
||||
class="ml-2 rounded-md p-1"
|
||||
>
|
||||
<Trash2 class="h-4 w-4" />
|
||||
</button>
|
||||
</li>
|
||||
)}
|
||||
</For>
|
||||
</ul>
|
||||
</Show>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
5
apps/cli/templates/frontend/solid/src/styles.css
Normal file
5
apps/cli/templates/frontend/solid/src/styles.css
Normal file
@@ -0,0 +1,5 @@
|
||||
@import "tailwindcss";
|
||||
|
||||
body {
|
||||
@apply bg-neutral-950 text-neutral-100;
|
||||
}
|
||||
29
apps/cli/templates/frontend/solid/tsconfig.json
Normal file
29
apps/cli/templates/frontend/solid/tsconfig.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"include": ["**/*.ts", "**/*.tsx"],
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"jsx": "preserve",
|
||||
"jsxImportSource": "solid-js",
|
||||
"module": "ESNext",
|
||||
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
||||
"types": ["vite/client"],
|
||||
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"noEmit": true,
|
||||
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true,
|
||||
|
||||
"rootDirs": ["."],
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
}
|
||||
}
|
||||
39
apps/cli/templates/frontend/solid/vite.config.js.hbs
Normal file
39
apps/cli/templates/frontend/solid/vite.config.js.hbs
Normal file
@@ -0,0 +1,39 @@
|
||||
import { defineConfig } from "vite";
|
||||
import { TanStackRouterVite } from "@tanstack/router-plugin/vite";
|
||||
import solidPlugin from "vite-plugin-solid";
|
||||
import tailwindcss from "@tailwindcss/vite";
|
||||
import path from "node:path";
|
||||
{{#if (includes addons "pwa")}}
|
||||
import { VitePWA } from "vite-plugin-pwa";
|
||||
{{/if}}
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
TanStackRouterVite({ target: "solid", autoCodeSplitting: true }),
|
||||
solidPlugin(),
|
||||
tailwindcss(),
|
||||
{{#if (includes addons "pwa")}}
|
||||
VitePWA({
|
||||
registerType: "autoUpdate",
|
||||
manifest: {
|
||||
name: "{{projectName}}",
|
||||
short_name: "{{projectName}}",
|
||||
description: "{{projectName}} - PWA Application",
|
||||
theme_color: "#0c0c0c",
|
||||
},
|
||||
pwaAssets: {
|
||||
disabled: false,
|
||||
config: true,
|
||||
},
|
||||
devOptions: {
|
||||
enabled: true,
|
||||
},
|
||||
}),
|
||||
{{/if}}
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
"@": path.resolve(__dirname, "./src"),
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user