Perf: Optimize event-types page (#2436)

* Perf: Optimize event-types page

* Memoize layout in Shell

* setQueryState without awaiting mutate for optimistic update

* Update Shell.tsx

* Fix types

* Update auth-index.test.ts

Co-authored-by: zomars <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2022-04-14 21:49:51 +00:00
1 parent 3c6ac395cc
commit 699d910ab4
6 files changed
+203 -129

No files matched your search

+41
View File
@@ -9,8 +9,21 @@ import {
import { Alert } from "@calcom/ui/Alert";
import { trpc } from "@lib/trpc";
import Loader from "@components/Loader";
import type { AppRouter } from "@server/routers/_app";
import type { TRPCClientErrorLike } from "@trpc/client";
import type { UseTRPCQueryOptions } from "@trpc/react";
// import type { inferProcedures } from "@trpc/react/src/createReactQueryHooks";
import type {
inferHandlerInput,
inferProcedureInput,
inferProcedureOutput,
ProcedureRecord,
} from "@trpc/server";
type ErrorLike = {
message: string;
};
@@ -72,3 +85,31 @@ export function QueryCell<TData, TError extends ErrorLike>(
// impossible state
return null;
}
type inferProcedures<TObj extends ProcedureRecord<any, any, any, any, any, any>> = {
[TPath in keyof TObj]: {
input: inferProcedureInput<TObj[TPath]>;
output: inferProcedureOutput<TObj[TPath]>;
};
};
type TQueryValues = inferProcedures<AppRouter["_def"]["queries"]>;
type TQueries = AppRouter["_def"]["queries"];
type TError = TRPCClientErrorLike<AppRouter>;
const withQuery = <TPath extends keyof TQueryValues & string>(
pathAndInput: [path: TPath, ...args: inferHandlerInput<TQueries[TPath]>],
params?: UseTRPCQueryOptions<TPath, TQueryValues[TPath]["input"], TQueryValues[TPath]["output"], TError>
) => {
return function WithQuery(
opts: Omit<
Partial<QueryCellOptionsWithEmpty<TQueryValues[TPath]["output"], TError>> &
QueryCellOptionsNoEmpty<TQueryValues[TPath]["output"], TError>,
"query"
>
) {
const query = trpc.useQuery(pathAndInput, params);
return <QueryCell query={query} {...opts} />;
};
};
export { withQuery };