Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | 11x 11x 6x 2x 6x 4x 4x 3x 1x 8x 8x 3x 1x 21x 3x 21x 3x 21x 3x 21x 3x 21x 3x 21x 3x 3x 3x 2x 1x 2x 6x 6x 5x 2x 5x 2x 4x 4x 3x 1x 3x 1x 4x 4x 3x 2x 5x 5x 5x 5x 5x 3x 3x 2x 1x 2x 1x 2x 1x | import { queryClient } from "../query-client";
import { queryKeys } from "../query-keys";
import { proApi, taxonomyApi, websiteApi, authApi, notificationsApi } from "../api";
import { projectsApi } from "../api/pro/projects";
import { getCachedProId, STALE_5MIN, STALE_1HR } from "./shared";
import { prefetchCrmKanban, prefetchCrmAnalytics } from "./crm-loaders";
export function prefetchProjects() {
const proId = getCachedProId();
if (!proId) return;
queryClient.ensureQueryData({
queryKey: queryKeys.projects.list(proId),
queryFn: () => proApi.listProjects(proId).then((r) => r.data || []),
staleTime: STALE_5MIN,
});
// The portfolio list reads the COUNTED variant (`useProjectsWithPhotoCount`)
// because the photo figure is printed on every chip and the no-photos chip —
// the one state that gets an action — has to know the count is zero rather
// than infer it from a missing cover. The two are separate cache entries by
// design (a plain list must not be poisoned with a counted payload), so the
// loader warms both: the plain one for the dashboard and the studio profile,
// the counted one for `/projects`. `ensureQueryData` is a no-op when either
// is already fresh, so an intent-prefetch on a warm cache still costs zero
// requests.
queryClient.ensureQueryData({
queryKey: [...queryKeys.projects.list(proId), "withPhotoCount"] as const,
queryFn: () =>
projectsApi
.list(proId, undefined, { includePhotoCount: true })
.then((r) => r.data || []),
staleTime: STALE_5MIN,
});
}
export function prefetchProjectDetail(projectId: string) {
const proId = getCachedProId();
if (!proId) return;
queryClient.ensureQueryData({
queryKey: queryKeys.projects.detail(proId, projectId),
queryFn: () =>
proApi.getProject(proId, projectId).then((r) => r.data),
staleTime: STALE_5MIN,
});
// project_photos table removed — no prefetch needed
}
export function prefetchAnalytics() {
const proId = getCachedProId();
if (!proId) return;
queryClient.ensureQueryData({
queryKey: queryKeys.pro.stats(proId),
queryFn: () => proApi.getProStats(proId).then((r) => r.data),
staleTime: 1000 * 60 * 2,
});
}
export function prefetchTaxonomy() {
queryClient.ensureQueryData({
queryKey: queryKeys.taxonomy.businessTypes(),
queryFn: () => taxonomyApi.getBusinessTypes().then((r) => r.data || []),
staleTime: STALE_1HR,
});
queryClient.ensureQueryData({
queryKey: queryKeys.taxonomy.customerSegments(),
queryFn: () =>
taxonomyApi.getCustomerSegments().then((r) => r.data || []),
staleTime: STALE_1HR,
});
queryClient.ensureQueryData({
queryKey: queryKeys.taxonomy.serviceCategories(),
queryFn: () =>
taxonomyApi.getServiceCategories().then((r) => r.data || []),
staleTime: STALE_1HR,
});
queryClient.ensureQueryData({
queryKey: queryKeys.taxonomy.materialTags(),
queryFn: () => taxonomyApi.getMaterialTags().then((r) => r.data || {}),
staleTime: STALE_1HR,
});
queryClient.ensureQueryData({
queryKey: queryKeys.taxonomy.brands(),
queryFn: () => taxonomyApi.getBrands().then((r) => r.data || {}),
staleTime: STALE_1HR,
});
queryClient.ensureQueryData({
queryKey: queryKeys.taxonomy.cities(),
queryFn: () => taxonomyApi.getCities().then((r) => r.data || []),
staleTime: STALE_1HR,
});
}
export function prefetchProfile() {
const proId = getCachedProId();
if (!proId) return;
queryClient.ensureQueryData({
queryKey: queryKeys.pro.profile(proId),
queryFn: () => proApi.getProfile(proId).then((r) => r.data),
staleTime: STALE_5MIN,
});
prefetchTaxonomy();
}
export function prefetchTeam() {
const proId = getCachedProId();
if (!proId) return;
queryClient.ensureQueryData({
queryKey: queryKeys.team.members(proId),
queryFn: () =>
proApi.getTeamMembers(proId, true).then((r) => r.data || []),
staleTime: STALE_5MIN,
});
queryClient.ensureQueryData({
queryKey: queryKeys.team.invitations(proId),
queryFn: () =>
proApi.getTeamInvitations(proId).then((r) => r.data || []),
staleTime: STALE_5MIN,
});
}
export function prefetchWebsite() {
const proId = getCachedProId();
if (!proId) return;
queryClient.ensureQueryData({
queryKey: queryKeys.website.templates(proId),
queryFn: () => websiteApi.getTemplates(proId),
staleTime: STALE_1HR,
});
queryClient.ensureQueryData({
queryKey: queryKeys.website.settings(proId),
queryFn: () => websiteApi.getSettings(proId),
staleTime: STALE_5MIN,
});
}
export function prefetchBlogs() {
const proId = getCachedProId();
if (!proId) return;
queryClient.ensureQueryData({
queryKey: queryKeys.blogs.list(proId, undefined),
queryFn: () =>
proApi.listMyBlogs(proId).then((r) => r.data || []),
staleTime: STALE_5MIN,
});
}
export function prefetchDashboard() {
prefetchProjects();
prefetchAnalytics();
prefetchTaxonomy();
// Prefetch CRM data for dashboard stat cards and recent leads
prefetchCrmKanban();
prefetchCrmAnalytics();
}
export function prefetchBlogEdit(blogId: string) {
const proId = getCachedProId();
if (!proId) return;
queryClient.ensureQueryData({
queryKey: queryKeys.blogs.detail(proId, blogId),
queryFn: () =>
proApi.getMyBlog(proId, blogId).then((r) => r.data),
staleTime: STALE_5MIN,
});
}
export function prefetchSettings() {
queryClient.ensureQueryData({
queryKey: queryKeys.settings.profile(),
queryFn: () => authApi.getProfile().then((r) => r.data),
staleTime: STALE_5MIN,
});
}
export function prefetchNotifications() {
queryClient.prefetchQuery({
queryKey: queryKeys.notifications.list(),
queryFn: () => notificationsApi.getAll().then((r) => r.data),
staleTime: STALE_5MIN,
});
}
|