updated codegen, added client query generation, etc.
This commit is contained in:
parent
864f37a652
commit
9518787206
17 changed files with 5244 additions and 445 deletions
|
|
@ -1,37 +1,36 @@
|
|||
import "@client/assets/styles/index.css";
|
||||
import "@client/assets/styles/nerd-fonts-icons.css";
|
||||
import { StrictMode } from "react";
|
||||
import ReactDOM from "react-dom/client";
|
||||
import { Provider } from "@client/components/ui/provider";
|
||||
import { RouterProvider, createRouter } from "@tanstack/react-router";
|
||||
import { ApolloClient, InMemoryCache, ApolloProvider } from "@apollo/client";
|
||||
import '@client/assets/styles/index.css';
|
||||
import '@client/assets/styles/nerd-fonts-icons.css';
|
||||
import { StrictMode } from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import { Provider } from '@client/components/ui/provider';
|
||||
import { RouterProvider, createRouter } from '@tanstack/react-router';
|
||||
import { ApolloClient, InMemoryCache, ApolloProvider } from '@apollo/client';
|
||||
|
||||
// TanStackRouter - Import the generated route tree
|
||||
import { routeTree } from "./routeTree.gen";
|
||||
import { routeTree } from './routeTree.gen';
|
||||
|
||||
// Create a new router instance
|
||||
const router = createRouter({ routeTree });
|
||||
|
||||
// Register the router instance for type safety
|
||||
declare module "@tanstack/react-router" {
|
||||
declare module '@tanstack/react-router' {
|
||||
interface Register {
|
||||
router: typeof router;
|
||||
}
|
||||
}
|
||||
|
||||
// Apollo
|
||||
const HOST = import.meta.env.VITE_HOST || "localhost";
|
||||
const PORT = import.meta.env.VITE_PORT || "3000";
|
||||
const HOST = import.meta.env.VITE_HOST || 'localhost';
|
||||
const PORT = import.meta.env.VITE_PORT || '3000';
|
||||
const uri = `http://${HOST}:${PORT}/graphql`;
|
||||
console.log(uri);
|
||||
|
||||
const client = new ApolloClient({
|
||||
uri,
|
||||
cache: new InMemoryCache(),
|
||||
connectToDevTools: true,
|
||||
connectToDevTools: true
|
||||
});
|
||||
|
||||
const rootElement = document.getElementById("root")!;
|
||||
const rootElement = document.getElementById('root')!;
|
||||
if (!rootElement.innerHTML) {
|
||||
const root = ReactDOM.createRoot(rootElement);
|
||||
root.render(
|
||||
|
|
@ -41,6 +40,6 @@ if (!rootElement.innerHTML) {
|
|||
<RouterProvider router={router} />
|
||||
</Provider>
|
||||
</ApolloProvider>
|
||||
</StrictMode>,
|
||||
</StrictMode>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { Button, HStack, Stack } from "@chakra-ui/react";
|
||||
import { Button, Stack } from "@chakra-ui/react";
|
||||
import { createRootRoute, Link, Outlet } from "@tanstack/react-router";
|
||||
import React from "react";
|
||||
|
||||
|
|
@ -17,14 +17,20 @@ const TanStackRouterDevtools =
|
|||
export const Route = createRootRoute({
|
||||
component: () => (
|
||||
<Stack padding={3}>
|
||||
<HStack>
|
||||
<Stack flexDirection={"row"} justifyContent={"space-between"}>
|
||||
<Link to="/">
|
||||
<Button>Home</Button>
|
||||
</Link>
|
||||
<Link to="/about">
|
||||
<Button>About</Button>
|
||||
</Link>
|
||||
</HStack>
|
||||
|
||||
<Stack flexDirection={"row"}>
|
||||
<Link to="/login">
|
||||
<Button>Sign in</Button>
|
||||
</Link>
|
||||
<Link to="/register">
|
||||
<Button>Sign up</Button>
|
||||
</Link>
|
||||
</Stack>
|
||||
</Stack>
|
||||
<hr style={{ padding: "4px" }} />
|
||||
<Outlet />
|
||||
<TanStackRouterDevtools />
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
import { Text, Icon, Stack } from "@chakra-ui/react";
|
||||
import { createLazyFileRoute } from "@tanstack/react-router";
|
||||
|
||||
export const Route = createLazyFileRoute("/about")({
|
||||
component: About,
|
||||
});
|
||||
|
||||
function About() {
|
||||
return (
|
||||
<Stack flexDirection={"row"} alignItems={"center"}>
|
||||
<Text>Hello from About!</Text>
|
||||
<Text>And NerdFonts!</Text>
|
||||
<Icon>
|
||||
<i className="nf nf-fa-heart" />
|
||||
</Icon>
|
||||
<Icon>
|
||||
<i className="nf nf-custom-vim" />
|
||||
</Icon>
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,14 +1,16 @@
|
|||
import { Text, Stack } from "@chakra-ui/react";
|
||||
import { createLazyFileRoute } from "@tanstack/react-router";
|
||||
import { Text, Stack } from '@chakra-ui/react';
|
||||
import { createFileRoute } from '@tanstack/react-router';
|
||||
|
||||
import { gql, useQuery } from "@apollo/client";
|
||||
import { gql, useQuery } from '@apollo/client';
|
||||
|
||||
export const Route = createLazyFileRoute("/")({
|
||||
component: Index,
|
||||
import { BooksManyQuery } from '@generated/types';
|
||||
|
||||
export const Route = createFileRoute('/')({
|
||||
component: Index
|
||||
});
|
||||
|
||||
function Index() {
|
||||
const { data } = useQuery(getBooksQuery);
|
||||
const { data } = useQuery<BooksManyQuery>(getBooksQuery);
|
||||
|
||||
return (
|
||||
<Stack>
|
||||
71
app/client/pages/login.tsx
Normal file
71
app/client/pages/login.tsx
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import { gql, useQuery } from '@apollo/client';
|
||||
import { Heading, Input, Stack } from '@chakra-ui/react';
|
||||
import { Button } from '@client/components/ui/button';
|
||||
import { Field } from '@client/components/ui/field';
|
||||
import { createFileRoute } from '@tanstack/react-router';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { valibotResolver } from '@hookform/resolvers/valibot';
|
||||
import * as v from 'valibot';
|
||||
|
||||
export const Route = createFileRoute('/login')({
|
||||
component: LoginComponent
|
||||
});
|
||||
|
||||
function LoginComponent() {
|
||||
// const { data } = useQuery(getBooksQuery);
|
||||
|
||||
return (
|
||||
<Stack flexDirection={'column'} justifyContent={'center'} alignItems={'center'}>
|
||||
<Heading>Login</Heading>
|
||||
<Login />
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
|
||||
interface FormValues {
|
||||
email: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
function Login() {
|
||||
const schema = v.pipe(
|
||||
v.object({
|
||||
email: v.pipe(v.string(), v.nonEmpty('Email is required'), v.email('Invalid email')),
|
||||
password: v.pipe(v.string(), v.nonEmpty('Password is required'))
|
||||
})
|
||||
);
|
||||
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
formState: { errors }
|
||||
} = useForm<FormValues>({ resolver: valibotResolver(schema) });
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit(data => alert(data))}>
|
||||
<Stack>
|
||||
<Field label="Email" invalid={errors.email != null} errorText={errors.email?.message}>
|
||||
<Input {...register('email')} />
|
||||
</Field>
|
||||
<Field
|
||||
label="Password"
|
||||
invalid={errors.password != null}
|
||||
errorText={errors.password?.message}
|
||||
>
|
||||
<Input {...register('password')} />
|
||||
</Field>
|
||||
<Button type="submit">Sign in</Button>
|
||||
</Stack>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
/* const getBooksQuery = gql`
|
||||
query BooksMany {
|
||||
booksMany {
|
||||
id
|
||||
author
|
||||
title
|
||||
}
|
||||
}
|
||||
`; */
|
||||
99
app/client/pages/register.tsx
Normal file
99
app/client/pages/register.tsx
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
import { gql, useQuery } from '@apollo/client';
|
||||
import { Heading, Input, Stack } from '@chakra-ui/react';
|
||||
import { Button } from '@client/components/ui/button';
|
||||
import { Field } from '@client/components/ui/field';
|
||||
import { createFileRoute } from '@tanstack/react-router';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { valibotResolver } from '@hookform/resolvers/valibot';
|
||||
import * as v from 'valibot';
|
||||
|
||||
export const Route = createFileRoute('/register')({
|
||||
component: RegisterComponent
|
||||
});
|
||||
|
||||
function RegisterComponent() {
|
||||
// const { data } = useQuery(getBooksQuery);
|
||||
|
||||
return (
|
||||
<Stack flexDirection={'column'} justifyContent={'center'} alignItems={'center'}>
|
||||
<Heading>Sign up</Heading>
|
||||
<Register />
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
|
||||
interface FormValues {
|
||||
email: string;
|
||||
username: string;
|
||||
password: string;
|
||||
confirm_password: string;
|
||||
}
|
||||
|
||||
function Register() {
|
||||
const schema = v.pipe(
|
||||
v.object({
|
||||
email: v.pipe(v.string(), v.nonEmpty('Email is required'), v.email('Invalid email')),
|
||||
username: v.pipe(v.string(), v.nonEmpty('Username is required')),
|
||||
password: v.pipe(
|
||||
v.string(),
|
||||
v.nonEmpty('Password is required'),
|
||||
v.minLength(8, 'Needs to be at least 8 characters')
|
||||
),
|
||||
confirm_password: v.pipe(v.string(), v.nonEmpty('Confirm your password'))
|
||||
}),
|
||||
v.forward(
|
||||
v.check(input => input.password === input.confirm_password, 'Passwords do not match'),
|
||||
['confirm_password']
|
||||
)
|
||||
);
|
||||
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
formState: { errors }
|
||||
} = useForm<FormValues>({ resolver: valibotResolver(schema) });
|
||||
|
||||
const onSubmit = handleSubmit(data => console.log(data));
|
||||
|
||||
return (
|
||||
<form onSubmit={onSubmit}>
|
||||
<Stack>
|
||||
<Field label="Email" invalid={errors.email != null} errorText={errors.email?.message}>
|
||||
<Input {...register('email')} />
|
||||
</Field>
|
||||
<Field
|
||||
label="Username"
|
||||
invalid={errors.username != null}
|
||||
errorText={errors.username?.message}
|
||||
>
|
||||
<Input {...register('username')} />
|
||||
</Field>
|
||||
<Field
|
||||
label="Password"
|
||||
invalid={errors.password != null}
|
||||
errorText={errors.password?.message}
|
||||
>
|
||||
<Input {...register('password')} />
|
||||
</Field>
|
||||
<Field
|
||||
label="Confirm password"
|
||||
invalid={errors.confirm_password != null}
|
||||
errorText={errors.confirm_password?.message}
|
||||
>
|
||||
<Input {...register('confirm_password')} />
|
||||
</Field>
|
||||
<Button type="submit">Submit</Button>
|
||||
</Stack>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
/* const getBooksQuery = gql`
|
||||
query BooksMany {
|
||||
booksMany {
|
||||
id
|
||||
author
|
||||
title
|
||||
}
|
||||
}
|
||||
`; */
|
||||
|
|
@ -13,12 +13,13 @@ import { createFileRoute } from '@tanstack/react-router'
|
|||
// Import Routes
|
||||
|
||||
import { Route as rootRoute } from './pages/__root'
|
||||
import { Route as RegisterImport } from './pages/register'
|
||||
import { Route as LoginImport } from './pages/login'
|
||||
import { Route as IndexImport } from './pages/index'
|
||||
|
||||
// Create Virtual Routes
|
||||
|
||||
const BookLazyImport = createFileRoute('/book')()
|
||||
const AboutLazyImport = createFileRoute('/about')()
|
||||
const IndexLazyImport = createFileRoute('/')()
|
||||
|
||||
// Create/Update Routes
|
||||
|
||||
|
|
@ -28,17 +29,23 @@ const BookLazyRoute = BookLazyImport.update({
|
|||
getParentRoute: () => rootRoute,
|
||||
} as any).lazy(() => import('./pages/book.lazy').then((d) => d.Route))
|
||||
|
||||
const AboutLazyRoute = AboutLazyImport.update({
|
||||
id: '/about',
|
||||
path: '/about',
|
||||
const RegisterRoute = RegisterImport.update({
|
||||
id: '/register',
|
||||
path: '/register',
|
||||
getParentRoute: () => rootRoute,
|
||||
} as any).lazy(() => import('./pages/about.lazy').then((d) => d.Route))
|
||||
} as any)
|
||||
|
||||
const IndexLazyRoute = IndexLazyImport.update({
|
||||
const LoginRoute = LoginImport.update({
|
||||
id: '/login',
|
||||
path: '/login',
|
||||
getParentRoute: () => rootRoute,
|
||||
} as any)
|
||||
|
||||
const IndexRoute = IndexImport.update({
|
||||
id: '/',
|
||||
path: '/',
|
||||
getParentRoute: () => rootRoute,
|
||||
} as any).lazy(() => import('./pages/index.lazy').then((d) => d.Route))
|
||||
} as any)
|
||||
|
||||
// Populate the FileRoutesByPath interface
|
||||
|
||||
|
|
@ -48,14 +55,21 @@ declare module '@tanstack/react-router' {
|
|||
id: '/'
|
||||
path: '/'
|
||||
fullPath: '/'
|
||||
preLoaderRoute: typeof IndexLazyImport
|
||||
preLoaderRoute: typeof IndexImport
|
||||
parentRoute: typeof rootRoute
|
||||
}
|
||||
'/about': {
|
||||
id: '/about'
|
||||
path: '/about'
|
||||
fullPath: '/about'
|
||||
preLoaderRoute: typeof AboutLazyImport
|
||||
'/login': {
|
||||
id: '/login'
|
||||
path: '/login'
|
||||
fullPath: '/login'
|
||||
preLoaderRoute: typeof LoginImport
|
||||
parentRoute: typeof rootRoute
|
||||
}
|
||||
'/register': {
|
||||
id: '/register'
|
||||
path: '/register'
|
||||
fullPath: '/register'
|
||||
preLoaderRoute: typeof RegisterImport
|
||||
parentRoute: typeof rootRoute
|
||||
}
|
||||
'/book': {
|
||||
|
|
@ -71,42 +85,47 @@ declare module '@tanstack/react-router' {
|
|||
// Create and export the route tree
|
||||
|
||||
export interface FileRoutesByFullPath {
|
||||
'/': typeof IndexLazyRoute
|
||||
'/about': typeof AboutLazyRoute
|
||||
'/': typeof IndexRoute
|
||||
'/login': typeof LoginRoute
|
||||
'/register': typeof RegisterRoute
|
||||
'/book': typeof BookLazyRoute
|
||||
}
|
||||
|
||||
export interface FileRoutesByTo {
|
||||
'/': typeof IndexLazyRoute
|
||||
'/about': typeof AboutLazyRoute
|
||||
'/': typeof IndexRoute
|
||||
'/login': typeof LoginRoute
|
||||
'/register': typeof RegisterRoute
|
||||
'/book': typeof BookLazyRoute
|
||||
}
|
||||
|
||||
export interface FileRoutesById {
|
||||
__root__: typeof rootRoute
|
||||
'/': typeof IndexLazyRoute
|
||||
'/about': typeof AboutLazyRoute
|
||||
'/': typeof IndexRoute
|
||||
'/login': typeof LoginRoute
|
||||
'/register': typeof RegisterRoute
|
||||
'/book': typeof BookLazyRoute
|
||||
}
|
||||
|
||||
export interface FileRouteTypes {
|
||||
fileRoutesByFullPath: FileRoutesByFullPath
|
||||
fullPaths: '/' | '/about' | '/book'
|
||||
fullPaths: '/' | '/login' | '/register' | '/book'
|
||||
fileRoutesByTo: FileRoutesByTo
|
||||
to: '/' | '/about' | '/book'
|
||||
id: '__root__' | '/' | '/about' | '/book'
|
||||
to: '/' | '/login' | '/register' | '/book'
|
||||
id: '__root__' | '/' | '/login' | '/register' | '/book'
|
||||
fileRoutesById: FileRoutesById
|
||||
}
|
||||
|
||||
export interface RootRouteChildren {
|
||||
IndexLazyRoute: typeof IndexLazyRoute
|
||||
AboutLazyRoute: typeof AboutLazyRoute
|
||||
IndexRoute: typeof IndexRoute
|
||||
LoginRoute: typeof LoginRoute
|
||||
RegisterRoute: typeof RegisterRoute
|
||||
BookLazyRoute: typeof BookLazyRoute
|
||||
}
|
||||
|
||||
const rootRouteChildren: RootRouteChildren = {
|
||||
IndexLazyRoute: IndexLazyRoute,
|
||||
AboutLazyRoute: AboutLazyRoute,
|
||||
IndexRoute: IndexRoute,
|
||||
LoginRoute: LoginRoute,
|
||||
RegisterRoute: RegisterRoute,
|
||||
BookLazyRoute: BookLazyRoute,
|
||||
}
|
||||
|
||||
|
|
@ -121,15 +140,19 @@ export const routeTree = rootRoute
|
|||
"filePath": "__root.tsx",
|
||||
"children": [
|
||||
"/",
|
||||
"/about",
|
||||
"/login",
|
||||
"/register",
|
||||
"/book"
|
||||
]
|
||||
},
|
||||
"/": {
|
||||
"filePath": "index.lazy.tsx"
|
||||
"filePath": "index.tsx"
|
||||
},
|
||||
"/about": {
|
||||
"filePath": "about.lazy.tsx"
|
||||
"/login": {
|
||||
"filePath": "login.tsx"
|
||||
},
|
||||
"/register": {
|
||||
"filePath": "register.tsx"
|
||||
},
|
||||
"/book": {
|
||||
"filePath": "book.lazy.tsx"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue