feat: setup full Next.js toolchain and core dependencies
- Add runtime deps: react-query, react-hook-form+zod, zustand, ky, openapi-fetch, better-auth, react-markdown, shiki, recharts, next-themes, nuqs, sonner, cmdk, vaul, embla-carousel-react, motion, date-fns, tailwind-merge, clsx, cva - Add dev tooling: vitest, testing-library, playwright, prettier(+tailwind plugin), husky, lint-staged, jsdom - Wire providers (QueryClient, Theme, NuqsAdapter, Tooltip, Sonner) into layout - Add vitest/playwright/prettier configs + lint-staged pre-commit hook - Add lib/query-client + lib/http (ky) helpers and sample unit test - Fix react-hooks/set-state-in-effect lint errors (use-mobile useSyncExternalStore, carousel async init) - Remove committed Next-generated types/ duplicates (regenerated under .next/types)
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
export function cn(...classes: Array<string | false | null | undefined>): string {
|
||||
return classes.filter(Boolean).join(" ");
|
||||
}
|
||||
|
||||
describe("cn", () => {
|
||||
it("joins truthy values", () => {
|
||||
expect(cn("a", "b", "c")).toBe("a b c");
|
||||
});
|
||||
|
||||
it("drops falsy values", () => {
|
||||
expect(cn("a", false, null, undefined, "b")).toBe("a b");
|
||||
});
|
||||
|
||||
it("returns empty string for no classes", () => {
|
||||
expect(cn()).toBe("");
|
||||
});
|
||||
});
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
import ky from "ky";
|
||||
|
||||
/**
|
||||
* Typed HTTP client built on ky.
|
||||
* Use openapi-fetch alongside this when you have a generated OpenAPI
|
||||
* schema (see openapi-fetch docs: `createClient<paths>({ baseUrl })`).
|
||||
*/
|
||||
export const apiClient = ky.create({
|
||||
prefix: "/api",
|
||||
timeout: 15_000,
|
||||
retry: {
|
||||
limit: 2,
|
||||
methods: ["get"],
|
||||
statusCodes: [408, 429, 500, 502, 503, 504],
|
||||
},
|
||||
});
|
||||
|
||||
export const http = {
|
||||
get: <T>(url: string, init?: RequestInit) => apiClient.get(url, init).json<T>(),
|
||||
post: <T>(url: string, body?: unknown, init?: RequestInit) =>
|
||||
apiClient.post(url, { json: body, ...init }).json<T>(),
|
||||
put: <T>(url: string, body?: unknown, init?: RequestInit) =>
|
||||
apiClient.put(url, { json: body, ...init }).json<T>(),
|
||||
patch: <T>(url: string, body?: unknown, init?: RequestInit) =>
|
||||
apiClient.patch(url, { json: body, ...init }).json<T>(),
|
||||
delete: <T>(url: string, init?: RequestInit) => apiClient.delete(url, init).json<T>(),
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
import { isServer, QueryClient } from "@tanstack/react-query";
|
||||
|
||||
function makeQueryClient() {
|
||||
return new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
staleTime: 60 * 1000,
|
||||
gcTime: 5 * 60 * 1000,
|
||||
refetchOnWindowFocus: false,
|
||||
retry: 1,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
let browserQueryClient: QueryClient | undefined = undefined;
|
||||
|
||||
export function getQueryClient() {
|
||||
if (isServer) {
|
||||
// Server: fresh client per request so caches never leak between users.
|
||||
return makeQueryClient();
|
||||
}
|
||||
// Browser: single shared client so the cache survives route changes.
|
||||
if (!browserQueryClient) {
|
||||
browserQueryClient = makeQueryClient();
|
||||
}
|
||||
return browserQueryClient;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { cn } from "cn";
|
||||
Reference in New Issue
Block a user