-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: неудачный переход на новый роутер Next 13 (tRPC еще не готов)
- Loading branch information
Showing
16 changed files
with
210 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"use client" | ||
|
||
import {FC, useEffect} from "react" | ||
import {logger} from "@gooditworks/monitoring" | ||
|
||
type Props = { | ||
error: Error | ||
} | ||
|
||
const ErrorPage: FC<Props> = ({error}) => { | ||
useEffect(() => { | ||
// eslint-disable-next-line no-console | ||
console.error(error) | ||
|
||
logger.captureException(error) | ||
}, [error]) | ||
|
||
return ( | ||
<div> | ||
<h2>Something went wrong!</h2> | ||
<pre>{error.message}</pre> | ||
</div> | ||
) | ||
} | ||
|
||
export default ErrorPage |
2 changes: 2 additions & 0 deletions
2
src/pages/example/counter.tsx → src/app/example/counter/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
"use client" | ||
|
||
import {FC} from "react" | ||
|
||
import useCounter from "hooks/useCounter" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {FC} from "react" | ||
|
||
import Greeting from "components/Greeting" | ||
|
||
const GreetingPage: FC = () => ( | ||
<div> | ||
<Greeting /> | ||
</div> | ||
) | ||
|
||
export default GreetingPage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {FC, ReactNode} from "react" | ||
|
||
import {TRPCClientProvider} from "datasources/trpc" | ||
|
||
import "styles/globals.css" | ||
|
||
type Props = { | ||
children: ReactNode | ||
} | ||
|
||
const RootLayout: FC<Props> = ({children}) => ( | ||
<TRPCClientProvider>{children}</TRPCClientProvider> | ||
) | ||
|
||
export default RootLayout |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
"use client" | ||
|
||
// based on https://github.com/trpc/next-13/blob/main/client/trpcClient.tsx | ||
// TODO wait for complete Next 13 support in tRPC and migrate | ||
|
||
import {FC, ReactNode, useState} from "react" | ||
import {httpBatchLink} from "@trpc/client" | ||
import {createTRPCReact} from "@trpc/react-query" | ||
import {QueryClient, QueryClientProvider} from "@tanstack/react-query" | ||
import superjson from "superjson" | ||
|
||
import type {AppRouter} from "server/routers" | ||
|
||
const getBaseUrl = () => { | ||
if (typeof window !== "undefined") { | ||
return "" | ||
} | ||
|
||
const vercelUrl = process.env.VERCEL_URL | ||
const port = process.env.PORT ?? 3000 | ||
|
||
if (vercelUrl) { | ||
return `https://${vercelUrl}` | ||
} | ||
|
||
return `http://localhost:${port}` | ||
} | ||
|
||
const trpc = createTRPCReact<AppRouter>({ | ||
unstable_overrides: { | ||
useMutation: { | ||
async onSuccess(opts) { | ||
await opts.originalFn() | ||
await opts.queryClient.invalidateQueries() | ||
} | ||
} | ||
} | ||
}) | ||
|
||
type Props = { | ||
children: ReactNode | ||
} | ||
|
||
const TRPCClientProvider: FC<Props> = ({children}) => { | ||
const [queryClient] = useState(() => new QueryClient()) | ||
const [trpcClient] = useState(() => { | ||
const baseUrl = getBaseUrl() | ||
const trpcUrl = `${baseUrl}/api/trpc` | ||
|
||
const links = [httpBatchLink({url: trpcUrl})] | ||
|
||
return trpc.createClient({ | ||
transformer: superjson, | ||
links | ||
}) | ||
}) | ||
|
||
return ( | ||
<trpc.Provider client={trpcClient} queryClient={queryClient}> | ||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
</trpc.Provider> | ||
) | ||
} | ||
|
||
export default trpc | ||
export {TRPCClientProvider} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.