Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.
TypeScript ai-agentai-resume-analyzerapplication-trackerapplication-tracking-systematscareerjob-applicationjob-automationjob-huntingjob-searchjob-seeker-toolsjob-trackerjob-trackingjobsearchjobseekersmcpollamaresumeresume-reviewself-hosted
perf(contacts): lazy-load the contact dialog pickers and drop the duplicate roles fetch
Khuram Niaz9b01e35803c0
diff --git a/__tests__/job.actions.spec.ts b/__tests__/job.actions.spec.tsindex 1912ba0..12f28c3 100644--- a/__tests__/job.actions.spec.ts+++ b/__tests__/job.actions.spec.ts@@ -764,6 +764,23 @@ describe("jobActions", () => {},},tags: true,+ contactLinks: {+ include: {+ Role: true,+ Contact: {+ select: {+ id: true,+ name: true,+ title: true,+ email: true,+ phone: true,+ linkedinUrl: true,+ Company: { select: { id: true, label: true } },+ },+ },+ },+ orderBy: { createdAt: "asc" },+ },},});});diff --git a/src/components/AddContact.tsx b/src/components/AddContact.tsxindex b342c7a..6c97189 100644--- a/src/components/AddContact.tsx+++ b/src/components/AddContact.tsx@@ -23,6 +23,7 @@ import { Textarea } from "./ui/textarea";import { Combobox } from "./ComboBox";import { DatePicker } from "./DatePicker";import { FormDialogFooter } from "./FormDialogFooter";+import Loading from "./Loading";import { toastActionResult } from "@/lib/toast";import { createContact, updateContact } from "@/actions/contact.actions";import {@@ -43,6 +44,7 @@ type AddContactProps = {roles: ContactRole[];prefillName?: string;hideTrigger?: boolean;+ pickersLoading?: boolean;onSaved?: (contact: ContactRef) => void;};@@ -88,6 +90,7 @@ function AddContact({roles,prefillName,hideTrigger,+ pickersLoading,onSaved,}: AddContactProps) {const [isPending, startTransition] = useTransition();@@ -203,6 +206,8 @@ function AddContact({<DialogHeader><DialogTitle>{pageTitle}</DialogTitle></DialogHeader>+ {pickersLoading && <Loading />}+ {!pickersLoading && (<Form {...form}><formonSubmit={form.handleSubmit(onSubmit)}@@ -457,6 +462,7 @@ function AddContact({/></form></Form>+ )}</DialogContent></Dialog></>diff --git a/src/components/admin/ContactsContainer.tsx b/src/components/admin/ContactsContainer.tsxindex 72bba4c..5d96c37 100644--- a/src/components/admin/ContactsContainer.tsx+++ b/src/components/admin/ContactsContainer.tsx@@ -1,5 +1,5 @@"use client";-import { useEffect, useState } from "react";+import { useCallback, useEffect, useRef, useState } from "react";import { Loader } from "lucide-react";import { Card, CardContent, CardTitle } from "../ui/card";import { ResponsiveCardHeader } from "../ResponsiveCardHeader";@@ -25,27 +25,35 @@ function ContactsContainer() {const [companies, setCompanies] = useState<Company[]>([]);const [locations, setLocations] = useState<JobLocation[]>([]);const [roles, setRoles] = useState<ContactRole[]>([]);+ const [pickersLoading, setPickersLoading] = useState(false);+ const pickersRequested = useRef(false);const list = useContactsList(searchTerm, roleId);- // The tab is a client component with no server parent to pass these down,- // and the Library's other tabs should not pay for this one's pickers.+ // Roles feed the role filter beside the search box, so the tab needs themuseEffect(() => {- Promise.all([- getAllCompanies(),- getAllJobLocations(),- getAllContactRoles(),- ]).then(([companyList, locationList, roleList]) => {- if (Array.isArray(companyList)) setCompanies(companyList);- if (Array.isArray(locationList)) setLocations(locationList);- if (Array.isArray(roleList)) setRoles(roleList);- });+ getAllContactRoles().then((res) => Array.isArray(res) && setRoles(res));+ }, []);++ // Company and location options are only ever seen inside the dialog, so+ // switching to this tab should not pay for them+ const openDialog = useCallback((open: boolean) => {+ setDialogOpen(open);+ if (!open || pickersRequested.current) return;+ pickersRequested.current = true;+ setPickersLoading(true);+ Promise.all([getAllCompanies(), getAllJobLocations()])+ .then(([companyList, locationList]) => {+ if (Array.isArray(companyList)) setCompanies(companyList);+ if (Array.isArray(locationList)) setLocations(locationList);+ })+ .finally(() => setPickersLoading(false));}, []);const onEditContact = async (contactId: string) => {const contact = await getContactById(contactId);setEditContact(contact);- setDialogOpen(true);+ openDialog(true);};return (@@ -63,7 +71,11 @@ function ContactsContainer() {)}</div><div className="flex flex-wrap items-center justify-end gap-2 sm:ml-auto">- <ContactRoleFilter roleId={roleId} onRoleChange={setRoleId} />+ <ContactRoleFilter+ roles={roles}+ roleId={roleId}+ onRoleChange={setRoleId}+ /><SearchInputvalue={searchTerm}onChange={setSearchTerm}@@ -74,7 +86,8 @@ function ContactsContainer() {reloadContacts={list.reload}resetEditContact={() => setEditContact(null)}dialogOpen={dialogOpen}- setDialogOpen={setDialogOpen}+ setDialogOpen={openDialog}+ pickersLoading={pickersLoading}companies={companies}locations={locations}roles={roles}diff --git a/src/components/admin/contacts-container/ContactRoleFilter.tsx b/src/components/admin/contacts-container/ContactRoleFilter.tsxindex 5724db3..9a6b506 100644--- a/src/components/admin/contacts-container/ContactRoleFilter.tsx+++ b/src/components/admin/contacts-container/ContactRoleFilter.tsx@@ -1,6 +1,5 @@"use client";-import { useEffect, useState } from "react";import {Select,SelectContent,@@ -8,24 +7,18 @@ import {SelectTrigger,SelectValue,} from "@/components/ui/select";-import { getAllContactRoles } from "@/actions/contactRole.actions";import type { ContactRole } from "@/models/contact.model";// Select cannot hold an empty-string value, so all-roles gets a sentinelconst ALL = "all";type Props = {+ roles: ContactRole[];roleId?: string;onRoleChange: (roleId?: string) => void;};-export function ContactRoleFilter({ roleId, onRoleChange }: Props) {- const [roles, setRoles] = useState<ContactRole[]>([]);-- useEffect(() => {- getAllContactRoles().then((res) => Array.isArray(res) && setRoles(res));- }, []);-+export function ContactRoleFilter({ roles, roleId, onRoleChange }: Props) {return (<Selectvalue={roleId ?? ALL}