a4d5777e1d
Imports and the external API assign shotNumber as max+10 (or 0), which needn't match the number in the shot code, so new shots could sink to the bottom of the list. Sort by episode then natural shot-code order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
150 lines
4.9 KiB
TypeScript
150 lines
4.9 KiB
TypeScript
import { db } from "@/lib/db";
|
|
import { auth } from "@/auth";
|
|
import { redirect } from "next/navigation";
|
|
import { ShotStatusClient } from "./ShotStatusClient";
|
|
import { summariseShotDelivery } from "@/lib/render-pipeline/shot-delivery-summary";
|
|
import { getUnreadCommentSummaries, type UnreadCommentSummary } from "@/lib/comment-reads";
|
|
|
|
async function getProjects() {
|
|
return db.project.findMany({
|
|
where: { status: { in: ["ACTIVE", "ON_HOLD"] } },
|
|
select: { id: true, name: true, code: true, projectType: true },
|
|
orderBy: { name: "asc" },
|
|
});
|
|
}
|
|
|
|
async function getEpisodeDueDatesForProject(projectId: string) {
|
|
return db.episodeDueDate.findMany({
|
|
where: { projectId },
|
|
select: { episode: true, dueDate: true },
|
|
orderBy: { episode: "asc" },
|
|
});
|
|
}
|
|
|
|
/** Everyone a shot can be handed to — clients and deactivated accounts excluded. */
|
|
async function getAssignableArtists() {
|
|
return db.user.findMany({
|
|
where: { isActive: true, role: { not: "CLIENT" } },
|
|
select: { id: true, name: true, email: true, image: true },
|
|
orderBy: { name: "asc" },
|
|
});
|
|
}
|
|
|
|
const shotCodeCollator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
|
|
|
|
async function getShotsForProject(projectId: string) {
|
|
const shots = await db.shot.findMany({
|
|
where: { projectId },
|
|
select: {
|
|
id: true,
|
|
shotCode: true,
|
|
scene: true,
|
|
episode: true,
|
|
shotNumber: true,
|
|
status: true,
|
|
priority: true,
|
|
dueDate: true,
|
|
thumbnailUrl: true,
|
|
generatedThumbnailUrl: true,
|
|
notes: true,
|
|
description: true,
|
|
isKeyShot: true,
|
|
isScaled: true,
|
|
manualDeliveredAt: true,
|
|
manualDeliveryNote: true,
|
|
manualDeliverySharedWith: true,
|
|
// The shot-level version the panel burns into overlays and queueExport
|
|
// renders under — not the count of review Versions uploaded.
|
|
shotVersion: true,
|
|
artist: { select: { id: true, name: true, image: true, email: true } },
|
|
shotGroup: { select: { id: true, name: true } },
|
|
// Every export, for the packages each went into; the newest live one
|
|
// is what is on its way.
|
|
exports: {
|
|
orderBy: [{ versionNumber: "desc" }, { createdAt: "desc" }],
|
|
select: {
|
|
versionString: true,
|
|
status: true,
|
|
deliveryItems: {
|
|
select: {
|
|
versionString: true,
|
|
package: {
|
|
select: {
|
|
kind: true,
|
|
status: true,
|
|
packageNumber: true,
|
|
createdAt: true,
|
|
builtAt: true,
|
|
uploadedAt: true,
|
|
deliveredAt: true,
|
|
sharedWith: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
// Sorted by shot code rather than scene + shotNumber: imports and the
|
|
// external API assign shotNumber as "max + 10" (or 0), which needn't match
|
|
// the number in the code, so new shots could sink to the bottom.
|
|
shots.sort(
|
|
(a, b) =>
|
|
(a.episode === null ? 1 : 0) - (b.episode === null ? 1 : 0) ||
|
|
shotCodeCollator.compare(a.episode ?? "", b.episode ?? "") ||
|
|
shotCodeCollator.compare(a.shotCode, b.shotCode)
|
|
);
|
|
|
|
return shots.map(({ exports, ...shot }) => ({
|
|
...shot,
|
|
delivery: summariseShotDelivery({
|
|
packages: exports.flatMap((e) =>
|
|
e.deliveryItems.map((item) => ({ ...item.package, versionString: item.versionString }))
|
|
),
|
|
manual: {
|
|
deliveredAt: shot.manualDeliveredAt,
|
|
sharedWith: shot.manualDeliverySharedWith,
|
|
note: shot.manualDeliveryNote,
|
|
},
|
|
latestExport: exports.find((e) => e.status !== "CANCELLED" && e.status !== "ARCHIVED") ?? null,
|
|
}),
|
|
}));
|
|
}
|
|
|
|
export default async function ShotStatusPage({
|
|
searchParams,
|
|
}: {
|
|
searchParams: Promise<{ projectId?: string }>;
|
|
}) {
|
|
const session = await auth();
|
|
if (!session?.user) redirect("/login");
|
|
|
|
const { projectId } = await searchParams;
|
|
const canManage = ["ADMIN", "PRODUCER", "SUPERVISOR"].includes(session.user.role);
|
|
|
|
const [projects, shotRows, episodeDueDates, artists, unread] = await Promise.all([
|
|
getProjects(),
|
|
projectId ? getShotsForProject(projectId) : Promise.resolve([]),
|
|
projectId ? getEpisodeDueDatesForProject(projectId) : Promise.resolve([]),
|
|
canManage ? getAssignableArtists() : Promise.resolve([]),
|
|
projectId ? getUnreadCommentSummaries(session.user.id, projectId) : Promise.resolve({} as Record<string, UnreadCommentSummary>),
|
|
]);
|
|
const shots = shotRows.map((shot) => ({ ...shot, unreadComments: unread[shot.id] ?? null }));
|
|
|
|
const selectedProject = projects.find((p) => p.id === projectId) ?? null;
|
|
|
|
return (
|
|
<ShotStatusClient
|
|
projects={projects}
|
|
selectedProjectId={projectId ?? null}
|
|
selectedProject={selectedProject}
|
|
shots={shots as any}
|
|
episodeDueDates={episodeDueDates}
|
|
artists={artists}
|
|
canManage={canManage}
|
|
/>
|
|
);
|
|
}
|