Skip to content

The open-source full-stack studio for Opus 5.5 motion video. Reverse engineering for any video. Code video with HTML: recreate, edit and render. BYOA + BYOK · Motion.md · Images, Video, Music & Voice.

1.4 KB
Raw Blame
import { useCallback } from "react";
import type { DomEditSelection } from "../components/editor/domEditing";
import { trackStudioEditBlocked, trackStudioSaveFailure } from "../utils/studioSaveDiagnostics";
import { isGsapEditBlockedError } from "./gsapEditOutcome";
import { wasAlreadyToasted } from "./domEditPersistFailure";

function failureToast(error: unknown, toast: boolean): string | null {
  if (!toast || wasAlreadyToasted(error)) return null;
  return isGsapEditBlockedError(error) ? error.message : "Failed to save animated edit.";
}

export function useGsapInteractionFailureTelemetry(
  activeCompPath: string | null,
  showToast: (message: string, tone?: "error" | "info") => void,
) {
  return useCallback(
    (
      error: unknown,
      selection: DomEditSelection | null,
      mutationType: string,
      label: string,
      toast?: boolean,
    ) => {
      const report = isGsapEditBlockedError(error)
        ? trackStudioEditBlocked
        : trackStudioSaveFailure;
      report({
        source: "gsap_commit",
        error,
        filePath: selection?.sourceFile ?? activeCompPath ?? "index.html",
        mutationType,
        label,
        targetId: selection?.id,
        targetSelector: selection?.selector,
        targetSourceFile: selection?.sourceFile,
      });
      const message = failureToast(error, toast !== false);
      if (message) showToast(message, "error");
    },
    [activeCompPath, showToast],
  );
}