feat(shot-status): flag shots with new comments until marked read

A per-user ShotCommentRead marker records how far each person has read a
shot's comments. Comments and replies from others after the marker put an
orange "!" beside the shot code; its popover lists them and only "Mark
read" clears it. A chip filters the board to flagged shots and marks all
read. The migration marks existing comments as read so the board starts
clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
twotalesanimation
2026-10-17 09:06:25 +02:00
parent 0aedc4b1fa
commit 7a7088f2ad
7 changed files with 489 additions and 7 deletions
@@ -36,6 +36,8 @@ import { updateShotNotes, bulkUpdateDueDates, bulkAssignArtist, bulkDeleteShots,
import { previewMovReview, buildMovReview } from "@/actions/deliveries";
import { useToast } from "@/components/ui/use-toast";
import { LogRequestDialog } from "@/components/delivery/LogRequestDialog";
import { markProjectCommentsRead } from "@/actions/comment-reads";
import { NewCommentsMarker } from "./NewCommentsMarker";
import {
Film,
Clock,
@@ -81,6 +83,8 @@ type ShotRow = {
manualDeliveryNote: string | null;
shotVersion: string | null;
delivery: ShotDeliverySummary;
/** Comments from others this user has not marked read; null = none. */
unreadComments: { count: number; latestAt: string } | null;
artist: { id: string; name: string | null; image: string | null; email: string } | null;
shotGroup: { id: string; name: string } | null;
};
@@ -912,6 +916,7 @@ function ShotTable({
selectedIds,
onToggle,
onToggleAll,
onCommentsRead,
}: {
shots: ShotRow[];
canManage: boolean;
@@ -919,6 +924,7 @@ function ShotTable({
selectedIds: Set<string>;
onToggle: (id: string) => void;
onToggleAll: (ids: string[], checked: boolean) => void;
onCommentsRead: (shotId: string) => void;
}) {
const allChecked = shots.length > 0 && shots.every((s) => selectedIds.has(s.id));
const someChecked = shots.some((s) => selectedIds.has(s.id));
@@ -1014,6 +1020,15 @@ function ShotTable({
>
{shot.shotCode}
</Link>
{shot.unreadComments && (
<NewCommentsMarker
shotId={shot.id}
shotCode={shot.shotCode}
count={shot.unreadComments.count}
latestAt={shot.unreadComments.latestAt}
onRead={onCommentsRead}
/>
)}
{shot.shotVersion && (
<span className="font-mono text-xs text-zinc-400 shrink-0">{shot.shotVersion}</span>
)}
@@ -1106,7 +1121,7 @@ export function ShotStatusClient({
projects,
selectedProjectId,
selectedProject,
shots,
shots: initialShots,
episodeDueDates,
artists,
canManage,
@@ -1114,6 +1129,18 @@ export function ShotStatusClient({
const router = useRouter();
const { toast } = useToast();
// Shots marked read here drop their "!" at once, ahead of the refresh; the
// refreshed props are authoritative, so the local set is cleared when they land.
const [readShotIds, setReadShotIds] = useState<Set<string>>(new Set());
useEffect(() => setReadShotIds(new Set()), [initialShots]);
const shots = readShotIds.size
? initialShots.map((s) => (readShotIds.has(s.id) ? { ...s, unreadComments: null } : s))
: initialShots;
const markShotReadLocally = (shotId: string) =>
setReadShotIds((prev) => new Set(prev).add(shotId));
const [unreadOnly, setUnreadOnly] = useState(false);
const [markingAllRead, startMarkingAllRead] = useTransition();
// Restore last selected project if no project is currently selected
useEffect(() => {
if (!selectedProjectId) {
@@ -1144,6 +1171,7 @@ export function ShotStatusClient({
if (!selectedProjectId) return;
setExpandRestored(false);
setStatusFilter(new Set());
setUnreadOnly(false);
const mode = (readStored(`shotStatus:${selectedProjectId}:groupMode`) ?? "flat") as "flat" | "scene" | "group";
setGroupMode(mode);
setExpandedEpisodes(new Set(readStoredList(`shotStatus:${selectedProjectId}:episodeExpand`) ?? []));
@@ -1246,13 +1274,43 @@ export function ShotStatusClient({
if (next.size > 0) {
setSelectedIds((prev) => {
const kept = new Set<string>();
for (const s of shots) if (prev.has(s.id) && next.has(s.status)) kept.add(s.id);
for (const s of shots)
if (prev.has(s.id) && next.has(s.status) && (!unreadOnly || s.unreadComments)) kept.add(s.id);
return kept;
});
}
};
const visibleShots = statusFilter.size > 0 ? shots.filter((s) => statusFilter.has(s.status)) : shots;
const visibleShots = shots.filter(
(s) => (statusFilter.size === 0 || statusFilter.has(s.status)) && (!unreadOnly || s.unreadComments)
);
const unreadShotCount = shots.filter((s) => s.unreadComments).length;
const isFiltered = statusFilter.size > 0 || unreadOnly;
const toggleUnreadOnly = () => {
const next = !unreadOnly;
setUnreadOnly(next);
// Bulk actions must never reach shots the filter has hidden.
if (next) {
setSelectedIds((prev) => {
const kept = new Set<string>();
for (const s of shots) if (prev.has(s.id) && s.unreadComments) kept.add(s.id);
return kept;
});
}
};
const handleMarkAllRead = () =>
startMarkingAllRead(async () => {
if (!selectedProjectId) return;
try {
await markProjectCommentsRead(selectedProjectId);
setReadShotIds(new Set(shots.filter((s) => s.unreadComments).map((s) => s.id)));
setUnreadOnly(false);
} catch {
toast({ title: "Could not mark comments read", variant: "destructive" });
}
});
const handleBulkDueDate = async (date: string, includeTasks: boolean) => {
try {
@@ -1457,7 +1515,7 @@ export function ShotStatusClient({
{selectionCount === 0 ? (
<>
<span className="text-xs text-zinc-500 self-center">
{statusFilter.size > 0 ? `${visibleShots.length} of ${shots.length} shots` : `${shots.length} shots total`}
{isFiltered ? `${visibleShots.length} of ${shots.length} shots` : `${shots.length} shots total`}
</span>
{Object.entries(STATUS_CONFIG).map(([key, cfg]) => {
const count = statusCounts[key] ?? 0;
@@ -1485,10 +1543,43 @@ export function ShotStatusClient({
</button>
);
})}
{statusFilter.size > 0 && (
{unreadShotCount > 0 && (
<span className="flex items-center gap-1">
<button
type="button"
onClick={toggleUnreadOnly}
aria-pressed={unreadOnly}
title={unreadOnly ? "Show all shots" : "Show only shots with new comments"}
className="rounded-full"
>
<Badge
className={cn(
"gap-1 text-xs cursor-pointer bg-orange-500/15 text-orange-300 border-orange-500/30",
unreadOnly && "ring-1 ring-current"
)}
>
<span className="font-bold">!</span>
{unreadShotCount} with new comments
</Badge>
</button>
<button
type="button"
onClick={handleMarkAllRead}
disabled={markingAllRead}
className="flex items-center gap-1 text-xs text-zinc-500 hover:text-zinc-300 transition-colors disabled:opacity-50"
>
{markingAllRead ? <Loader2 className="h-3 w-3 animate-spin" /> : <CheckCircle2 className="h-3 w-3" />}
Mark all read
</button>
</span>
)}
{isFiltered && (
<button
type="button"
onClick={() => setStatusFilter(new Set())}
onClick={() => {
setStatusFilter(new Set());
setUnreadOnly(false);
}}
className="flex items-center gap-1 text-xs text-zinc-500 hover:text-zinc-300 transition-colors"
>
<X className="h-3 w-3" />
@@ -1608,6 +1699,7 @@ export function ShotStatusClient({
projectId={selectedProjectId!}
selectedIds={selectedIds}
onToggle={toggleShot}
onCommentsRead={markShotReadLocally}
onToggleAll={toggleMany}
/>
</div>
@@ -1657,6 +1749,7 @@ export function ShotStatusClient({
projectId={selectedProjectId!}
selectedIds={selectedIds}
onToggle={toggleShot}
onCommentsRead={markShotReadLocally}
onToggleAll={toggleMany}
/>
</div>
@@ -1706,6 +1799,7 @@ export function ShotStatusClient({
projectId={selectedProjectId!}
selectedIds={selectedIds}
onToggle={toggleShot}
onCommentsRead={markShotReadLocally}
onToggleAll={toggleMany}
/>
</div>
@@ -1722,6 +1816,7 @@ export function ShotStatusClient({
projectId={selectedProjectId!}
selectedIds={selectedIds}
onToggle={toggleShot}
onCommentsRead={markShotReadLocally}
onToggleAll={toggleMany}
/>
</div>