Comp AI CRM is an open source, CRM designed for AI agents. Agentic-first CRM.
TypeScript
Refactor query prefetching in Companies, Contacts, and Deals pages to… (#71)
Lewis Carhartbb15e01d672a
diff --git a/apps/app/app/(app)/[slug]/companies/page.tsx b/apps/app/app/(app)/[slug]/companies/page.tsxindex ac2a6900..ab53f7a6 100644--- a/apps/app/app/(app)/[slug]/companies/page.tsx+++ b/apps/app/app/(app)/[slug]/companies/page.tsx@@ -56,10 +56,12 @@ async function Companies({const trpc = getServerTrpc();const queryClient = getServerQueryClient();- await queryClient.prefetchQuery(- trpc.companies.list.queryOptions(companiesSearchParams.toInput(values)),- );- void queryClient.prefetchQuery(trpc.users.list.queryOptions());+ await Promise.all([+ queryClient.prefetchQuery(+ trpc.companies.list.queryOptions(companiesSearchParams.toInput(values)),+ ),+ queryClient.prefetchQuery(trpc.users.list.queryOptions()),+ ]);return (<HydrateClient>diff --git a/apps/app/app/(app)/[slug]/contacts/page.tsx b/apps/app/app/(app)/[slug]/contacts/page.tsxindex 6a154079..f1e2801b 100644--- a/apps/app/app/(app)/[slug]/contacts/page.tsx+++ b/apps/app/app/(app)/[slug]/contacts/page.tsx@@ -54,13 +54,13 @@ async function Contacts({const trpc = getServerTrpc();const queryClient = getServerQueryClient();- await queryClient.prefetchQuery(- trpc.contacts.list.queryOptions(contactsSearchParams.toInput(values)),- );- void queryClient.prefetchQuery(trpc.users.list.queryOptions());- void queryClient.prefetchQuery(- trpc.companies.options.queryOptions({ q: "" }),- );+ await Promise.all([+ queryClient.prefetchQuery(+ trpc.contacts.list.queryOptions(contactsSearchParams.toInput(values)),+ ),+ queryClient.prefetchQuery(trpc.users.list.queryOptions()),+ queryClient.prefetchQuery(trpc.companies.options.queryOptions({ q: "" })),+ ]);return (<HydrateClient>diff --git a/apps/app/app/(app)/[slug]/deals/page.tsx b/apps/app/app/(app)/[slug]/deals/page.tsxindex eba64c08..1b6bbfd5 100644--- a/apps/app/app/(app)/[slug]/deals/page.tsx+++ b/apps/app/app/(app)/[slug]/deals/page.tsx@@ -56,13 +56,13 @@ async function Deals({const trpc = getServerTrpc();const queryClient = getServerQueryClient();- await queryClient.prefetchQuery(- trpc.deals.list.queryOptions(dealsSearchParams.toInput(values)),- );- void queryClient.prefetchQuery(trpc.users.list.queryOptions());- void queryClient.prefetchQuery(- trpc.companies.options.queryOptions({ q: "" }),- );+ await Promise.all([+ queryClient.prefetchQuery(+ trpc.deals.list.queryOptions(dealsSearchParams.toInput(values)),+ ),+ queryClient.prefetchQuery(trpc.users.list.queryOptions()),+ queryClient.prefetchQuery(trpc.companies.options.queryOptions({ q: "" })),+ ]);return (<HydrateClient>diff --git a/apps/app/lib/trpc/query-client.ts b/apps/app/lib/trpc/query-client.tsindex 2aa0831b..82a8cc50 100644--- a/apps/app/lib/trpc/query-client.ts+++ b/apps/app/lib/trpc/query-client.ts@@ -1,17 +1,9 @@-import {- defaultShouldDehydrateQuery,- QueryClient,-} from "@tanstack/react-query";+import { QueryClient } from "@tanstack/react-query";export function makeQueryClient(): QueryClient {return new QueryClient({defaultOptions: {queries: { staleTime: 30_000 },- dehydrate: {- shouldDehydrateQuery: (query) =>- defaultShouldDehydrateQuery(query) ||- query.state.status === "pending",- },},});}diff --git a/packages/ui/src/components/select.tsx b/packages/ui/src/components/select.tsxindex 56de822c..1306cdaf 100644--- a/packages/ui/src/components/select.tsx+++ b/packages/ui/src/components/select.tsx@@ -76,8 +76,9 @@ function SelectTrigger({function SelectContent({className,children,- position = "item-aligned",- align = "center",+ position = "popper",+ align = "start",+ sideOffset = 4,...props}: React.ComponentProps<typeof SelectPrimitive.Content>) {return (@@ -87,21 +88,17 @@ function SelectContent({data-align-trigger={position === "item-aligned"}className={cn("relative z-50 max-h-(--radix-select-content-available-height) min-w-36 origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-lg bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[align-trigger=true]:animate-none data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",- position === "popper" &&- "data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",className,)}position={position}align={align}+ sideOffset={position === "popper" ? sideOffset : undefined}{...props}><SelectScrollUpButton /><SelectPrimitive.Viewportdata-position={position}- className={cn(- "data-[position=popper]:h-(--radix-select-trigger-height) data-[position=popper]:w-full data-[position=popper]:min-w-(--radix-select-trigger-width)",- position === "popper" && "",- )}+ className="data-[position=popper]:w-full data-[position=popper]:min-w-(--radix-select-trigger-width)">{children}</SelectPrimitive.Viewport>