Stabilize admin state and submission metadata

This commit is contained in:
2026-04-10 15:48:32 -07:00
parent 215ead0768
commit bd2087ba5f
14 changed files with 2171 additions and 463 deletions
+38
View File
@@ -0,0 +1,38 @@
import type { Cue } from "./entities";
export const indexCueOrder = (cues: Cue[]) =>
cues.map((cue, index) => ({
...cue,
orderIndex: index
}));
export const sortCuesByOrder = (cues: Cue[]) =>
indexCueOrder([...cues].sort((left, right) => left.orderIndex - right.orderIndex));
export const moveCueInOrder = (cues: Cue[], cueId: string, direction: "up" | "down") => {
const sorted = sortCuesByOrder(cues);
const currentIndex = sorted.findIndex((cue) => cue.id === cueId);
if (currentIndex < 0) {
return sorted;
}
const swapIndex = direction === "up" ? currentIndex - 1 : currentIndex + 1;
if (swapIndex < 0 || swapIndex >= sorted.length) {
return sorted;
}
const next = [...sorted];
[next[currentIndex], next[swapIndex]] = [next[swapIndex]!, next[currentIndex]!];
return indexCueOrder(next);
};
export const upsertCueInOrder = (cues: Cue[], cue: Cue) => {
const sorted = sortCuesByOrder(cues);
const existingIndex = sorted.findIndex((entry) => entry.id === cue.id);
if (existingIndex >= 0) {
sorted.splice(existingIndex, 1);
}
sorted.splice(Math.max(0, Math.min(cue.orderIndex, sorted.length)), 0, cue);
return indexCueOrder(sorted);
};
+7
View File
@@ -57,6 +57,9 @@ export interface Submission {
submittedAt: string;
status: SubmissionStatus;
consentId: string;
contributorName?: string;
lovedOneName?: string;
/** Legacy/operator label retained for existing runtime data and older clients. */
displayName?: string;
caption?: string;
promptAnswer?: string;
@@ -344,6 +347,8 @@ export interface SessionEvent {
}
export interface SubmissionPayload {
contributorName?: string;
lovedOneName?: string;
displayName?: string;
caption?: string;
promptAnswer?: string;
@@ -355,6 +360,8 @@ export interface SubmissionPayload {
}
export interface SubmissionUpdatePayload {
contributorName?: string;
lovedOneName?: string;
displayName?: string;
caption?: string;
promptAnswer?: string;
+1
View File
@@ -1,4 +1,5 @@
export * from "./entities";
export * from "./cue-order";
export * from "./events";
export * from "./mock";
export * from "./scene-params";