artcraft host: import upload modals from @storyteller/ui-upload-modal

useTauriPageSceneAdapter, GlobalFileDropHandler, and UploadImagesButton
now pull UploadModal3D/Image/Splat from the shared lib. Removes the
host-local UploadModal3D/UploadModalImage/UploadModalSplat directories
since they're no longer referenced anywhere.

UploadModalMedia/ stays — it backs the host-only image-plane upload
adapter helpers, not the modal slots.
This commit is contained in:
Tanish Manku committed 2026-05-12 09:11:11 -07:00
1 parent 2d6af20d0b
commit 61c1aa720d
20 files changed
+11 -2550

No files matched your search

@@ -2,9 +2,11 @@ import { useEffect, useRef, useState } from "react";
import { toast } from "react-hot-toast";
import { faCube, faImages, faUpRightAndDownLeftFromCenter } from "@fortawesome/pro-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { UploadModal3D } from "../reusable/UploadModal3D/UploadModal3D";
import { UploadModalImage } from "../reusable/UploadModalImage/UploadModalImage";
import { UploadModalSplat } from "../reusable/UploadModalSplat/UploadModalSplat";
import {
UploadModal3D,
UploadModalImage,
UploadModalSplat,
} from "@storyteller/ui-upload-modal";
import { FilterEngineCategories } from "../../enums";
type ModalType = "3d" | "image" | "splat" | null;
@@ -1,533 +0,0 @@
import { useCallback, useEffect, useRef, useState } from "react";
import { Group as PanelGroup, Panel, Separator as PanelResizeHandle } from "react-resizable-panels";
import { ListDropdown } from "@storyteller/ui-list-dropdown";
import { Button } from "@storyteller/ui-button";
import { FileUploader } from "@storyteller/ui-file-uploader";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import {
faCube,
faXmark,
faCheck,
faCircleExclamation,
faChevronLeft,
faChevronRight,
faRotateRight,
faSpinner,
} from "@fortawesome/pro-solid-svg-icons";
import * as THREE from "three";
import { loadPreviewOnCanvas, snapshotCanvasAsThumbnail } from "./utilities";
import { upload3DObjects } from "./utilities/upload3DObjects";
import { upload3DObjectsBatch } from "./utilities/upload3DObjectsBatch";
import { FileEntryStatus } from "../UploadModalImage/utilities/uploadImagesBatch";
import type { UploaderState } from "../../../models";
import {
FilterEngineCategories,
MediaFileAnimationType,
UploaderStates,
} from "../../../enums";
interface FileEntry {
file: File;
status: FileEntryStatus;
errorMessage?: string;
}
interface Props {
title: string;
fileTypes: string[];
engineCategory: FilterEngineCategories;
initialFiles?: File[];
options?: {
fileSubtypes?: { [key: string]: string }[];
hasLength?: boolean;
hasThumbnailUpload?: boolean;
};
onClose: () => void;
onUploadProgress: (newState: UploaderState) => void;
}
export const UploadFiles3D = ({
fileTypes,
engineCategory,
initialFiles,
options,
onClose,
onUploadProgress,
}: Props) => {
const canvasRef = useRef<HTMLCanvasElement | undefined>(undefined);
const rendererRef = useRef<THREE.WebGLRenderer | null>(null);
const cameraRef = useRef<THREE.PerspectiveCamera | null>(null);
const resizeObserverRef = useRef<ResizeObserver | null>(null);
const canvasCallbackRef = useCallback((node: HTMLCanvasElement | null) => {
if (resizeObserverRef.current) {
resizeObserverRef.current.disconnect();
resizeObserverRef.current = null;
}
if (node !== null) {
canvasRef.current = node;
const observer = new ResizeObserver(() => {
const renderer = rendererRef.current;
const camera = cameraRef.current;
if (!renderer || !camera) return;
const w = node.clientWidth;
const h = node.clientHeight;
if (w === 0 || h === 0) return;
renderer.setSize(w, h, false);
camera.aspect = w / h;
camera.updateProjectionMatrix();
});
observer.observe(node);
resizeObserverRef.current = observer;
}
}, []);
const fileSubtypes = options?.fileSubtypes;
const [subtype, setSubtype] = useState<MediaFileAnimationType | undefined>(
fileSubtypes
? (Object.values(fileSubtypes[0])[0] as MediaFileAnimationType)
: undefined,
);
const seedFiles = initialFiles ?? [];
const [fileEntries, setFileEntries] = useState<FileEntry[]>(
seedFiles.map((f) => ({ file: f, status: "idle" })),
);
const [previewIndex, setPreviewIndex] = useState(0);
// Incremented on every handleFilesChange so useEffect re-runs even when count stays the same
const [filesVersion, setFilesVersion] = useState(0);
const [previewStatus, setPreviewStatus] = useState<{
type: string;
message?: string;
}>({ type: "init" });
const [thumbnails, setThumbnails] = useState<Map<File, Blob>>(new Map());
const [isUploading, setIsUploading] = useState(false);
const [overallProgress, setOverallProgress] = useState<{
current: number;
total: number;
} | null>(null);
const [selectionError, setSelectionError] = useState<string | undefined>();
const disposeRenderer = () => {
if (rendererRef.current) {
rendererRef.current.setAnimationLoop(null);
rendererRef.current.dispose();
rendererRef.current = null;
}
};
// Reload canvas preview whenever the current file or index changes.
// filesVersion ensures this re-runs when the same-count file set is replaced.
useEffect(() => {
const currentFile = fileEntries[previewIndex]?.file;
if (!canvasRef.current || !currentFile) return;
disposeRenderer();
setPreviewStatus({ type: "init" });
const { renderer, camera } = loadPreviewOnCanvas({
file: currentFile,
canvas: canvasRef.current,
statusCallback: setPreviewStatus,
});
rendererRef.current = renderer;
cameraRef.current = camera;
return disposeRenderer;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [previewIndex, filesVersion]);
// Snapshot thumbnail when preview finishes loading
useEffect(() => {
if (previewStatus.type === "OK" && canvasRef.current) {
snapshotCanvasAsThumbnail({
targetNode: canvasRef.current,
resultCallback: (blob) => {
const currentFile = fileEntries[previewIndex]?.file;
if (blob && currentFile) {
setThumbnails((prev) => new Map(prev).set(currentFile, blob));
}
},
});
}
}, [previewStatus, previewIndex]);
// Reset subtype when fileSubtypes set changes (e.g. toggling character)
useEffect(() => {
if (!fileSubtypes || fileSubtypes.length === 0) {
setSubtype(undefined);
return;
}
setSubtype(
Object.values(fileSubtypes[0])[0] as MediaFileAnimationType | undefined,
);
}, [fileSubtypes]);
const updateFileStatus = (
index: number,
status: FileEntryStatus,
errorMessage?: string,
) => {
setFileEntries((prev) =>
prev.map((entry, i) =>
i === index ? { ...entry, status, errorMessage } : entry,
),
);
};
const removeFile = (index: number) => {
setFileEntries((prev) => {
const next = prev.filter((_, i) => i !== index);
setPreviewIndex((prevIdx) =>
Math.min(prevIdx, Math.max(0, next.length - 1)),
);
return next;
});
setFilesVersion((v) => v + 1);
};
const retrySingleFile = async (index: number) => {
const entry = fileEntries[index];
if (!entry || entry.status === "uploading") return;
updateFileStatus(index, "uploading");
await upload3DObjects({
title: entry.file.name.slice(0, entry.file.name.lastIndexOf(".")),
assetFile: entry.file,
engineCategory,
animationType: subtype,
thumbnailSnapshot: thumbnails.get(entry.file),
progressCallback: (state) => {
if (state.status === UploaderStates.success) {
updateFileStatus(index, "success");
} else if (
state.status === UploaderStates.assetError ||
state.status === UploaderStates.coverCreateError ||
state.status === UploaderStates.coverSetError
) {
updateFileStatus(index, "error", state.errorMessage);
}
},
});
};
const handleFilesChange = (files: File[]) => {
setFileEntries(files.map((f) => ({ file: f, status: "idle" })));
setPreviewIndex(0);
setFilesVersion((v) => v + 1);
setThumbnails(new Map());
setSelectionError(undefined);
setOverallProgress(null);
setIsUploading(false);
};
const handleSubmit = () => {
if (fileEntries.length === 0) {
setSelectionError("Please select a file to upload.");
return;
}
// Only upload files that haven't already succeeded
const pendingEntries = fileEntries
.map((e, i) => ({ entry: e, originalIndex: i }))
.filter(
({ entry }) => entry.status !== "success" && entry.file !== undefined,
);
const files = pendingEntries.map(({ entry }) => entry.file!);
const originalIndices = pendingEntries.map(
({ originalIndex }) => originalIndex,
);
const pendingThumbnails = new Map<File, Blob>(
files
.map((file) => [file, thumbnails.get(file) ?? undefined])
.filter((pair): pair is [File, Blob] => pair[1] !== undefined),
);
if (files.length === 1 && fileEntries.length === 1) {
// Single file: use parent modal state machine (shows loading spinner)
upload3DObjects({
title: files[0].name.slice(0, files[0].name.lastIndexOf(".")),
assetFile: files[0],
engineCategory,
animationType: subtype,
thumbnailSnapshot: thumbnails.get(files[0]),
progressCallback: onUploadProgress,
});
return;
}
// Multi-file: stay on form, show inline progress
setIsUploading(true);
setOverallProgress({ current: 0, total: files.length });
upload3DObjectsBatch({
files,
thumbnails: pendingThumbnails,
engineCategory,
animationType: subtype,
onFileStatusChange: (batchIndex, status, errorMessage) =>
updateFileStatus(originalIndices[batchIndex], status, errorMessage),
onOverallProgress: (completed, total) =>
setOverallProgress({ current: completed, total }),
onComplete: (allSucceeded, anySucceeded) => {
setIsUploading(false);
if (allSucceeded) {
onUploadProgress({ status: UploaderStates.success });
} else if (!anySucceeded) {
onUploadProgress({
status: UploaderStates.assetError,
errorMessage: "All uploads failed.",
});
}
},
});
};
const retryAllFailed = () => {
const failedIndices = fileEntries
.map((e, i) => (e.status === "error" ? i : -1))
.filter((i) => i !== -1);
if (failedIndices.length === 0) return;
const failedFiles = failedIndices
.map((i) => fileEntries[i].file!)
.filter((file) => file !== undefined);
const failedThumbnails = new Map<File, Blob>(
failedFiles
.map((file): [File, Blob | undefined] => [
file,
thumbnails.get(file) ?? undefined,
])
.filter((pair): pair is [File, Blob] => pair[1] !== undefined),
);
setIsUploading(true);
setOverallProgress({ current: 0, total: failedFiles.length });
upload3DObjectsBatch({
files: failedFiles,
thumbnails: failedThumbnails,
engineCategory,
animationType: subtype,
onFileStatusChange: (batchIndex, status, errorMessage) =>
updateFileStatus(failedIndices[batchIndex], status, errorMessage),
onOverallProgress: (completed, total) =>
setOverallProgress({ current: completed, total }),
onComplete: (allSucceeded, anySucceeded) => {
setIsUploading(false);
if (allSucceeded) {
onUploadProgress({ status: UploaderStates.success });
} else if (!anySucceeded) {
onUploadProgress({
status: UploaderStates.assetError,
errorMessage: "All uploads failed.",
});
}
},
});
};
const isMulti = fileEntries.length > 1;
const anyFailed = fileEntries.some((e) => e.status === "error");
const anyUploading = fileEntries.some((e) => e.status === "uploading");
const hasUploadStarted = fileEntries.some((e) => e.status !== "idle");
const allDone =
fileEntries.length > 0 &&
fileEntries.every((e) => e.status === "success" || e.status === "error");
const currentFile = fileEntries[previewIndex]?.file;
return (
<div className="flex flex-col gap-3">
{fileSubtypes && fileSubtypes.length > 1 && (
<ListDropdown
list={fileSubtypes}
onSelect={(value) => setSubtype(value as MediaFileAnimationType)}
/>
)}
<FileUploader
fileTypes={fileTypes}
files={fileEntries.map((e) => e.file)}
handleChange={handleFilesChange}
multiple={true}
fileIcon={faCube}
/>
{selectionError && <h6 className="z-10 text-red">{selectionError}</h6>}
{isMulti ? (
<PanelGroup orientation="horizontal">
{/* File list sidebar */}
<Panel defaultSize="33%" minSize="20%">
<ul className="flex h-full flex-col gap-1 overflow-y-auto rounded-lg bg-brand-secondary p-2">
{fileEntries.map((entry, i) => (
<li
key={i}
className={`group flex cursor-pointer items-center justify-between gap-1.5 rounded px-2 py-1 text-sm transition-colors ${
i === previewIndex ? "bg-white/10" : "hover:bg-white/5"
}`}
onClick={() => setPreviewIndex(i)}
>
<span className="flex-1 truncate" title={entry.file.name}>
{entry.file.name.slice(0, entry.file.name.lastIndexOf("."))}
</span>
<span className="shrink-0">
{entry.status === "idle" && (
<button
className="opacity-40 transition-opacity hover:opacity-100"
onClick={(e) => {
e.stopPropagation();
removeFile(i);
}}
title="Remove"
>
<FontAwesomeIcon icon={faXmark} />
</button>
)}
{entry.status === "uploading" && (
<FontAwesomeIcon
icon={faSpinner}
className="animate-spin opacity-60"
/>
)}
{entry.status === "success" && (
<FontAwesomeIcon
icon={faCheck}
className="text-green-400"
/>
)}
{entry.status === "error" && (
<span className="flex items-center gap-1">
<FontAwesomeIcon
icon={faCircleExclamation}
className="text-red-400"
/>
<button
className="hidden items-center text-xs text-white/60 transition-colors hover:text-white group-hover:inline-flex"
onClick={(e) => {
e.stopPropagation();
retrySingleFile(i);
}}
title="Retry"
>
<FontAwesomeIcon icon={faRotateRight} />
</button>
</span>
)}
</span>
</li>
))}
</ul>
</Panel>
<PanelResizeHandle className="flex w-4 items-center justify-center" onPointerDown={(e) => e.stopPropagation()}>
<div className="h-8 w-1 rounded-full bg-white/20 transition-colors hover:bg-white/40" />
</PanelResizeHandle>
{/* Canvas preview + carousel */}
<Panel defaultSize="67%" minSize="25%">
<div className="flex h-full flex-col gap-2">
<div className="relative w-full min-h-48 overflow-hidden rounded-lg bg-brand-secondary">
<canvas
className="pointer-events-none h-full min-h-48 !w-full"
ref={canvasCallbackRef}
/>
{!currentFile && (
<h6 className="pointer-events-auto absolute left-0 top-1/2 -mt-5 flex w-full items-center justify-center gap-2.5 text-center opacity-50">
<FontAwesomeIcon icon={faCube} />
Your model preview will appear here
</h6>
)}
{previewStatus.type.includes("Error") && (
<h6 className="pointer-events-auto absolute left-0 top-1/2 -mt-5 w-full text-center">
{previewStatus.type}
{previewStatus.message && <br />}
{previewStatus.message}
</h6>
)}
</div>
<div className="flex items-center justify-center gap-3">
<Button
variant="secondary"
onClick={() => setPreviewIndex((p) => Math.max(0, p - 1))}
disabled={previewIndex === 0}
>
<FontAwesomeIcon icon={faChevronLeft} />
</Button>
<span className="text-sm opacity-60">
{previewIndex + 1} / {fileEntries.length}
</span>
<Button
variant="secondary"
onClick={() =>
setPreviewIndex((p) =>
Math.min(fileEntries.length - 1, p + 1),
)
}
disabled={previewIndex === fileEntries.length - 1}
>
<FontAwesomeIcon icon={faChevronRight} />
</Button>
</div>
</div>
</Panel>
</PanelGroup>
) : (
/* Single-file layout: canvas takes full width (original behaviour) */
<div className="relative m-auto w-full min-h-48 overflow-hidden rounded-lg bg-brand-secondary">
<canvas
className="pointer-events-none h-full min-h-48 !w-full"
ref={canvasCallbackRef}
/>
{!currentFile && (
<h6 className="pointer-events-auto absolute left-0 top-1/2 -mt-5 flex w-full items-center justify-center gap-2.5 text-center opacity-50">
<FontAwesomeIcon icon={faCube} />
Your model preview will appear here
</h6>
)}
{previewStatus.type.includes("Error") && (
<h6 className="pointer-events-auto absolute left-0 top-1/2 -mt-5 w-full text-center">
{previewStatus.type}
{previewStatus.message && <br />}
{previewStatus.message}
</h6>
)}
</div>
)}
{(isUploading || anyUploading) && overallProgress && isMulti && (
<p className="text-center text-sm opacity-60">
Uploading {overallProgress.current} / {overallProgress.total}...
</p>
)}
{!isUploading && !anyUploading && allDone && anyFailed && isMulti && (
<p className="text-center text-sm text-red-400">
{fileEntries.filter((e) => e.status === "error").length} file(s)
failed to upload.
</p>
)}
<div className="flex justify-end gap-2">
<Button variant="secondary" onClick={onClose}>
Cancel
</Button>
{!isUploading && !anyUploading && allDone && anyFailed && isMulti && (
<Button variant="secondary" onClick={retryAllFailed}>
Retry Failed
</Button>
)}
{/* Hide Upload once any upload has started; only Retry Failed or Close remains */}
{!hasUploadStarted && (
<Button
variant="primary"
onClick={handleSubmit}
disabled={fileEntries.length === 0}
>
Upload
</Button>
)}
</div>
</div>
);
};
@@ -1,172 +0,0 @@
import { useEffect, useMemo, useState } from "react";
import { Checkbox } from "@storyteller/ui-checkbox";
import { LoadingDots } from "@storyteller/ui-loading";
import { Modal } from "@storyteller/ui-modal";
import { UploadAssetError, UploadSuccess } from "@storyteller/ui-upload-modal";
import { UploadFiles3D } from "./UploadFiles3D";
import { initialUploaderState, UploaderState } from "../../../models";
import {
FilterEngineCategories,
UploaderStates,
OBJECT_FILE_TYPE,
MediaFileAnimationType,
} from "../../../enums";
import { IconDefinition } from "@fortawesome/fontawesome-svg-core";
import {
galleryModalVisibleViewMode,
galleryModalVisibleDuringDrag,
} from "@storyteller/ui-gallery-modal";
interface Props {
onClose: () => void;
onSuccess: (category: FilterEngineCategories) => void;
isOpen: boolean;
title: string;
titleIcon: IconDefinition;
initialFiles?: File[];
options?: {
fileSubtypes?: { [key: string]: string }[];
hasLength?: boolean;
hasThumbnailUpload?: boolean;
};
}
const objectFileTypes = Object.values(OBJECT_FILE_TYPE);
export function UploadModal3D(props: Props) {
const { isOpen, onClose, onSuccess, title, titleIcon, initialFiles, options } = props;
const [uploaderState, setUploaderState] =
useState<UploaderState>(initialUploaderState);
const [isCharacter, setIsCharacter] = useState(false);
const selectedCategory = isCharacter
? FilterEngineCategories.CHARACTER
: FilterEngineCategories.OBJECT;
const characterAnimationOptions = useMemo(() => {
if (!isCharacter) return undefined;
const values = Object.values(MediaFileAnimationType);
const sorted = values.sort((a, b) =>
a === MediaFileAnimationType.MixamoArKit
? -1
: b === MediaFileAnimationType.MixamoArKit
? 1
: a.localeCompare(b),
);
const toLabel = (v: string) =>
v.replace(/_/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
return sorted.map((v) => ({ [toLabel(v)]: v }));
}, [isCharacter]);
const updateUploaderState = (newState: UploaderState) => {
setUploaderState(newState);
};
const resetModalState = () => {
setUploaderState(initialUploaderState);
};
useEffect(() => {
if (isOpen) {
resetModalState();
setIsCharacter(false);
}
}, [isOpen]);
const UploaderModalContent = () => {
switch (uploaderState.status) {
case UploaderStates.ready:
return (
<div className="space-y-4">
<Checkbox
id="upload-as-character"
checked={isCharacter}
onChange={(e) => setIsCharacter(e.target.checked)}
label="Upload as Character"
/>
<UploadFiles3D
title={title}
engineCategory={selectedCategory}
fileTypes={objectFileTypes}
initialFiles={initialFiles}
options={{
...(options ?? {}),
fileSubtypes: characterAnimationOptions,
}}
onClose={onClose}
onUploadProgress={updateUploaderState}
/>
</div>
);
case UploaderStates.uploadingAsset:
case UploaderStates.uploadingCover:
case UploaderStates.settingCover: {
const p = uploaderState.uploadProgress;
return (
<>
<LoadingDots className="mb-1 bg-transparent" />
<div className="w-100 text-center opacity-50">
{p && p.total > 1
? `Uploading ${p.current} / ${p.total}...`
: "Uploading..."}
</div>
</>
);
}
case UploaderStates.success: {
return (
<UploadSuccess
title="3D model"
onOk={() => {
// Open the gallery so the user can drag the freshly
// uploaded model onto the canvas.
galleryModalVisibleViewMode.value = true;
galleryModalVisibleDuringDrag.value = true;
onSuccess(selectedCategory);
onClose();
}}
/>
);
}
case UploaderStates.assetError:
return (
<UploadAssetError
onCancel={onClose}
onRetry={() => {
resetModalState();
}}
type={selectedCategory}
errorMessage={uploaderState.errorMessage}
/>
);
case UploaderStates.coverCreateError:
case UploaderStates.coverSetError:
return (
<UploadAssetError
onCancel={onClose}
onRetry={() => {
resetModalState();
}}
type={"Thumbnail"}
errorMessage={uploaderState.errorMessage}
/>
);
}
return undefined;
};
return (
<Modal
isOpen={isOpen}
onClose={onClose}
titleIcon={titleIcon}
title={title}
className="max-w-xl"
showClose={true}
>
{/* Inline call — `<Comp />` would be a fresh component reference each render, remounting the dropzone mid-click and breaking the file picker. */}
{UploaderModalContent()}
</Modal>
);
}
@@ -1 +0,0 @@
export * from "./UploadModal3D";
@@ -1,3 +0,0 @@
export * from "./loadPreviewOnCanvas";
export * from "./thumbnailHelpers";
export * from "./uploadAsset";
@@ -1,266 +0,0 @@
import * as THREE from "three";
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
import { FontLoader } from "three/addons/loaders/FontLoader.js";
import { TextGeometry } from "three/addons/geometries/TextGeometry.js";
import { SplatFileType, SplatMesh } from "@sparkjsdev/spark";
import { SPLAT_FILE_TYPE } from "~/enums";
interface LoaderInterface {
file: File;
camera: THREE.PerspectiveCamera;
scene: THREE.Scene;
renderer: THREE.WebGLRenderer;
statusCallback: (statusObject: { type: string; message?: string }) => void;
}
interface PreviewReturn {
renderer: THREE.WebGLRenderer;
camera: THREE.PerspectiveCamera;
}
export const loadPreviewOnCanvas = ({
file,
canvas,
statusCallback,
}: {
file: File;
canvas: HTMLCanvasElement;
statusCallback: (error: { type: string; message?: string }) => void;
}): PreviewReturn => {
// Setup of scene, camera, and renderer in the canvas
const scene = new THREE.Scene();
// Calculate proper aspect ratio from canvas dimensions
const width = canvas.getBoundingClientRect().width || 0;
const height = canvas.getBoundingClientRect().height || 0;
const aspectRatio = width / height;
// Reduce FOV to make objects appear larger
const camera = new THREE.PerspectiveCamera(35, aspectRatio, 0.1, 1000);
camera.position.z = 2;
const gl2ctx = canvas.getContext("webgl2", { preserveDrawingBuffer: true });
const renderer = new THREE.WebGLRenderer({
alpha: true,
antialias: true,
canvas: canvas,
context: gl2ctx!,
});
renderer.setSize(width, height);
const color = 0xfcece7;
const light = new THREE.HemisphereLight(color, 0x8d8d8d, 3.0);
// Add some additional lighting to better show the model
const frontLight = new THREE.DirectionalLight(0xffffff, 2);
frontLight.position.set(0, 0, 10);
scene.add(frontLight);
scene.add(light);
let splatMesh: SplatMesh | null = null;
// load the file into the preview mini-scene depending of the file's type
if (file.name.endsWith(".glb")) {
glbLoader({ file, scene, camera, renderer, statusCallback });
} else if (file.name.endsWith(".pmd")) {
pmdLoader({ file, scene, camera, renderer, statusCallback });
} else if (
file.name.endsWith(".png") ||
file.name.endsWith(".jpg") ||
file.name.endsWith(".jpeg") ||
file.name.endsWith(".gif")
) {
imagePlaneLoader({ file, scene, camera, renderer, statusCallback });
} else if (file.name.endsWith(".spz")) {
file
.arrayBuffer()
.then((arrayBuffer) => {
splatMesh = new SplatMesh({
fileBytes: arrayBuffer,
fileType: SplatFileType.SPZ,
onLoad: () => {
scene.add(splatMesh!);
},
});
if (file.name.split(".")[0].endsWith("ceramic")) {
splatMesh.rotateX(Math.PI);
splatMesh.rotateZ(Math.PI);
}
})
.catch((loaderError) => {
statusCallback({
type: "SPLAT Loader Error",
message: String(loaderError),
});
});
} else if (file.name.endsWith(".vmd")) {
statusCallback({
type: "Preview Error",
message: "Sorry, Preview is not available to VMD files yet",
});
} else {
statusCallback({
type: "Preview Error",
message: "Unknown file type for loader",
});
}
// Render the loaded data
const animate = function () {
renderer.render(scene, camera);
splatMesh?.rotateY(0.01);
};
renderer.setAnimationLoop(animate);
return { renderer, camera };
};
const glbLoader = ({
file,
camera,
scene,
renderer,
statusCallback,
}: LoaderInterface) => {
const loader = new GLTFLoader();
loader.load(
URL.createObjectURL(file),
(data) => {
data.scene.children.forEach((child) => {
child.userData["color"] = "#FFFFFF";
scene.add(child);
// Calculate bounding box for all objects in the scene
const box = new THREE.Box3();
scene.traverse((object) => {
if (object instanceof THREE.Mesh) {
object.geometry.computeBoundingBox();
box.expandByObject(object);
}
});
// Get the center and size of the bounding box
const center = new THREE.Vector3();
const size = new THREE.Vector3();
box.getCenter(center);
box.getSize(size);
// Calculate the radius of the bounding sphere
const radius = Math.max(size.x, size.y, size.z) * 0.5;
// Position camera to fit the object in view with minimal padding
const fov = camera.fov * (Math.PI / 180);
const distance = (radius * 1.2) / Math.tan(fov * 0.5);
// Position camera at a better angle for preview
camera.position.set(
center.x + distance * 0.6,
center.y + distance * 0.4,
center.z + distance * 0.6,
);
camera.lookAt(center);
// Adjust the camera's near and far planes to ensure the model is visible
camera.near = distance * 0.01;
camera.far = distance * 100;
camera.updateProjectionMatrix();
renderer.render(scene, camera);
statusCallback({
type: "OK",
message: "Preview should be available",
});
});
},
undefined, // nothing to-do onProgress
(loaderError) => {
/*onError*/
statusCallback({
type: "GLB Loader Error",
message: String(loaderError),
});
},
);
};
const pmdLoader = ({
camera,
scene,
renderer,
statusCallback,
}: LoaderInterface) => {
camera.position.z = 30;
const loader = new FontLoader();
loader.load(
"https://threejs.org/examples/fonts/helvetiker_regular.typeface.json",
(font) => {
const textGeometry = new TextGeometry("MMD", {
font: font,
size: 100,
depth: 5,
curveSegments: 12,
bevelEnabled: true,
bevelThickness: 1,
bevelSize: 1,
bevelOffset: 0,
bevelSegments: 5,
});
textGeometry.computeBoundingBox();
const textMaterial = new THREE.MeshPhongMaterial({
color: 0xffffff,
});
const textMesh = new THREE.Mesh(textGeometry, textMaterial);
textMesh.scale.set(0.15, 0.15, 0.01);
textMesh.position.set(-22, -5, 0);
scene.add(textMesh);
renderer.render(scene, camera);
statusCallback({
type: "OK",
message: "Preview should be available",
});
},
undefined, // nothing on Progress
(loaderError) => {
/*onError*/
statusCallback({
type: "PMD Loader Error",
message: String(loaderError),
});
},
);
};
const imagePlaneLoader = ({ file, scene, statusCallback }: LoaderInterface) => {
const geometry = new THREE.PlaneGeometry(1, 1);
const loader = new THREE.TextureLoader();
const texture = loader.load(
URL.createObjectURL(file),
undefined, // nothing to-do onLoad
undefined, // nothing to-do onProgress
(loaderError) => {
/*onError*/
statusCallback({
type: "Image Plane Loader Error",
message: String(loaderError),
});
},
);
texture.colorSpace = THREE.SRGBColorSpace;
const image_material = new THREE.MeshBasicMaterial({
color: 0xffffff,
map: texture,
});
const obj = new THREE.Mesh(geometry, image_material);
obj.receiveShadow = true;
obj.castShadow = true;
scene.add(obj);
statusCallback({
type: "OK",
message: "Preview should be available",
});
};
@@ -1,54 +0,0 @@
import { MediaFilesApi, MediaUploadApi } from "~/Classes/ApiManager";
import { v4 as uuidv4 } from "uuid";
import { getFileName } from "~/utilities";
export const snapshotCanvasAsThumbnail = async ({
targetNode,
resultCallback,
}: {
targetNode: HTMLCanvasElement | undefined;
resultCallback: (blob: Blob | undefined) => void;
}) => {
if (!targetNode) {
//TODO: Verbose Error
return undefined;
}
targetNode.toBlob((blob: Blob | null) => {
resultCallback(blob || undefined);
});
};
export const uploadSnapshotAsThumbnail = async ({
assetTitle = "unknown_asset",
blob,
}: {
assetTitle?: string;
blob: Blob;
}) => {
const thumbnailFile = new File([blob], "storyteller-cap.png");
const thumbnailTitle = "thumbnail_" + assetTitle;
const mediaUploadApi = new MediaUploadApi();
return await mediaUploadApi.UploadImage({
uuid: uuidv4(),
blob: thumbnailFile,
fileName: getFileName(thumbnailFile),
maybe_title: thumbnailTitle,
});
};
export const setThumbnail = async ({
assetToken,
thumbnailToken,
}: {
assetToken: string;
thumbnailToken: string;
}) => {
const mediaFilesApi = new MediaFilesApi();
return await mediaFilesApi.UpdateCoverImage({
mediaFileToken: assetToken,
imageToken: thumbnailToken,
});
};
@@ -1,76 +0,0 @@
import {
FilterEngineCategories,
MediaFileAnimationType,
UploaderStates,
} from "~/enums";
import { setThumbnail, uploadSnapshotAsThumbnail } from "./thumbnailHelpers";
import { uploadAsset } from "./uploadAsset";
import { UploaderState } from "~/models";
export const upload3DObjects = async ({
title,
assetFile,
engineCategory,
thumbnailSnapshot,
animationType,
progressCallback,
}: {
title: string;
assetFile: File;
engineCategory: FilterEngineCategories;
thumbnailSnapshot: Blob | undefined;
animationType?: MediaFileAnimationType;
progressCallback: (newState: UploaderState) => void;
}) => {
progressCallback({ status: UploaderStates.uploadingAsset });
const assetReponse = await uploadAsset({
file: assetFile,
title: title,
engineCategory: engineCategory,
animationType: animationType,
});
if (!assetReponse.success || !assetReponse.data) {
progressCallback({
status: UploaderStates.assetError,
errorMessage: assetReponse.errorMessage,
});
return;
}
const assetToken = assetReponse.data;
if (!thumbnailSnapshot) {
progressCallback({ status: UploaderStates.success });
return;
}
progressCallback({ status: UploaderStates.uploadingCover });
const thumbnailResponse = await uploadSnapshotAsThumbnail({
assetTitle: title,
blob: thumbnailSnapshot,
});
if (!thumbnailResponse.success || !thumbnailResponse.data) {
progressCallback({
status: UploaderStates.coverCreateError,
errorMessage: thumbnailResponse.errorMessage,
});
return;
}
progressCallback({ status: UploaderStates.settingCover });
const thumbnailToken = thumbnailResponse.data;
const setThumbnailResponse = await setThumbnail({
assetToken: assetToken,
thumbnailToken: thumbnailToken,
});
if (!setThumbnailResponse.success) {
progressCallback({
status: UploaderStates.coverSetError,
errorMessage: setThumbnailResponse.errorMessage,
});
return;
}
progressCallback({ status: UploaderStates.success });
};
@@ -1,89 +0,0 @@
import {
FilterEngineCategories,
MediaFileAnimationType,
UploaderStates,
} from "~/enums";
import { upload3DObjects } from "./upload3DObjects";
import { FileEntryStatus } from "../../UploadModalImage/utilities/uploadImagesBatch";
export const upload3DObjectsBatch = async ({
files,
thumbnails,
engineCategory,
animationType,
onFileStatusChange,
onOverallProgress,
onComplete,
}: {
files: File[];
thumbnails: Map<File, Blob>;
engineCategory: FilterEngineCategories;
animationType?: MediaFileAnimationType;
onFileStatusChange: (
index: number,
status: FileEntryStatus,
errorMessage?: string,
) => void;
onOverallProgress: (completed: number, total: number) => void;
onComplete: (allSucceeded: boolean, anySucceeded: boolean) => void;
}) => {
// JS is single-threaded; these counters are safe across concurrent async callbacks.
let completedCount = 0;
let successCount = 0;
const completedIndices = new Set<number>();
files.forEach((_, i) => onFileStatusChange(i, "uploading"));
onOverallProgress(0, files.length);
try {
await Promise.all(
files.map((file, i) =>
upload3DObjects({
title: file.name.slice(0, file.name.lastIndexOf(".")),
assetFile: file,
engineCategory,
animationType,
thumbnailSnapshot: thumbnails.get(file),
progressCallback: (state) => {
if (state.status === UploaderStates.success) {
successCount++;
onFileStatusChange(i, "success");
} else if (
state.status === UploaderStates.assetError ||
state.status === UploaderStates.coverCreateError ||
state.status === UploaderStates.coverSetError
) {
onFileStatusChange(i, "error", state.errorMessage);
}
if (
state.status === UploaderStates.success ||
state.status === UploaderStates.assetError ||
state.status === UploaderStates.coverCreateError ||
state.status === UploaderStates.coverSetError
) {
if (!completedIndices.has(i)) {
completedIndices.add(i);
completedCount++;
onOverallProgress(completedCount, files.length);
}
}
},
}),
),
);
} catch (err) {
// Only mark files that haven't already reached a terminal state
files.forEach((_, i) => {
if (!completedIndices.has(i)) {
onFileStatusChange(
i,
"error",
err instanceof Error ? err.message : "Unexpected error",
);
}
});
}
onComplete(successCount === files.length, successCount > 0);
};
@@ -1,57 +0,0 @@
import { MediaFilesApi, MediaUploadApi } from "~/Classes/ApiManager";
import { FilterEngineCategories, MediaFileAnimationType } from "~/enums";
import { getFileExtension } from "~/utilities";
import { v4 as uuidv4 } from "uuid";
export const uploadAsset = async ({
file,
title,
engineCategory,
animationType,
}: {
file: File;
title: string;
engineCategory: FilterEngineCategories;
animationType?: MediaFileAnimationType;
}) => {
// TODO: 'media_uploads' is the name of an ancient table nothing writes to. We shouldn't use this name here to mean the media_files table.
const mediaUploadApi = new MediaUploadApi();
const mediaFileApi = new MediaFilesApi();
const fileExtension = getFileExtension(file);
const assetReponse = await (async () => {
switch (fileExtension) {
case ".spz":
console.log("Uploading asset as SPZ");
return mediaFileApi.UploadSpzFile({
file: file,
fileName: file.name,
uuid: uuidv4(),
maybe_title: title,
});
case ".zip":
console.log("Uploading asset as PMX");
return mediaUploadApi.UploadPmx({
file: file,
fileName: file.name,
engine_category: engineCategory,
maybe_title: title,
maybe_animation_type: animationType,
uuid: uuidv4(),
});
default:
console.log("Uploading asset as generic engine asset");
return mediaUploadApi.UploadNewEngineAsset({
file: file,
fileName: file.name,
engine_category: engineCategory,
maybe_title: title,
maybe_animation_type: animationType,
uuid: uuidv4(),
});
}
})();
return assetReponse;
};
@@ -1,376 +0,0 @@
import { useEffect, useState } from "react";
import { Group as PanelGroup, Panel, Separator as PanelResizeHandle } from "react-resizable-panels";
import { Button } from "@storyteller/ui-button";
import { FileUploader } from "@storyteller/ui-file-uploader";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import {
faXmark,
faCheck,
faCircleExclamation,
faChevronLeft,
faChevronRight,
faRotateRight,
faSpinner,
} from "@fortawesome/pro-solid-svg-icons";
import { uploadImage } from "./utilities/uploadImage";
import {
uploadImagesBatch,
FileEntryStatus,
} from "./utilities/uploadImagesBatch";
import type { UploaderState } from "../../../models";
import { UploaderStates } from "../../../enums";
interface FileEntry {
file: File;
status: FileEntryStatus;
errorMessage?: string;
}
interface Props {
title: string;
fileTypes: string[];
initialFiles?: File[];
onClose: () => void;
onUploadProgress: (newState: UploaderState) => void;
}
export const UploadFilesImage = ({
fileTypes,
initialFiles,
onClose,
onUploadProgress,
}: Props) => {
const seedFiles = initialFiles ?? [];
const [fileEntries, setFileEntries] = useState<FileEntry[]>(
seedFiles.map((f) => ({ file: f, status: "idle" }))
);
const [previewIndex, setPreviewIndex] = useState(0);
const [previewUrl, setPreviewUrl] = useState<string | null>(null);
// Incremented on every handleFilesChange so useEffect re-runs even when count stays the same
const [filesVersion, setFilesVersion] = useState(0);
const [isUploading, setIsUploading] = useState(false);
const [overallProgress, setOverallProgress] = useState<{ current: number; total: number } | null>(null);
const [selectionError, setSelectionError] = useState<string | undefined>();
// Create and clean up the object URL for the current preview.
// filesVersion ensures this re-runs when the same-count file set is replaced.
useEffect(() => {
const currentFile = fileEntries[previewIndex]?.file;
if (!currentFile) {
setPreviewUrl(null);
return;
}
const url = URL.createObjectURL(currentFile);
setPreviewUrl(url);
return () => URL.revokeObjectURL(url);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [previewIndex, filesVersion]);
const updateFileStatus = (
index: number,
status: FileEntryStatus,
errorMessage?: string
) => {
setFileEntries((prev) =>
prev.map((entry, i) =>
i === index ? { ...entry, status, errorMessage } : entry
)
);
};
const removeFile = (index: number) => {
setFileEntries((prev) => {
const next = prev.filter((_, i) => i !== index);
// Compute new index inside the updater so it's always based on the post-remove length
setPreviewIndex((prevIdx) => Math.min(prevIdx, Math.max(0, next.length - 1)));
return next;
});
setFilesVersion((v) => v + 1);
};
const retrySingleFile = async (index: number) => {
const entry = fileEntries[index];
if (!entry || entry.status === "uploading") return;
updateFileStatus(index, "uploading");
await uploadImage({
title: entry.file.name.slice(0, entry.file.name.lastIndexOf(".")),
assetFile: entry.file,
progressCallback: (state) => {
if (state.status === UploaderStates.success) {
updateFileStatus(index, "success");
} else if (state.status === UploaderStates.assetError) {
updateFileStatus(index, "error", state.errorMessage);
}
},
});
};
const handleFilesChange = (files: File[]) => {
setFileEntries(files.map((f) => ({ file: f, status: "idle" })));
setPreviewIndex(0);
setFilesVersion((v) => v + 1);
setSelectionError(undefined);
setOverallProgress(null);
setIsUploading(false);
};
const handleSubmit = () => {
if (fileEntries.length === 0) {
setSelectionError("Please select an image to upload.");
return;
}
// Only upload files that haven't already succeeded
const files = fileEntries
.filter((e) => e.status !== "success")
.map((e) => e.file);
const originalIndices = fileEntries
.map((e, i) => (e.status !== "success" ? i : -1))
.filter((i) => i !== -1);
if (files.length === 1 && fileEntries.length === 1) {
// Single file: use parent modal state machine (shows loading spinner)
uploadImage({
title: files[0].name.slice(0, files[0].name.lastIndexOf(".")),
assetFile: files[0],
progressCallback: onUploadProgress,
});
return;
}
// Multi-file: stay on form, show inline progress
setIsUploading(true);
setOverallProgress({ current: 0, total: files.length });
uploadImagesBatch({
files,
onFileStatusChange: (batchIndex, status, errorMessage) =>
updateFileStatus(originalIndices[batchIndex], status, errorMessage),
onOverallProgress: (completed, total) =>
setOverallProgress({ current: completed, total }),
onComplete: (allSucceeded, anySucceeded) => {
setIsUploading(false);
if (allSucceeded) {
onUploadProgress({ status: UploaderStates.success });
} else if (!anySucceeded) {
onUploadProgress({
status: UploaderStates.assetError,
errorMessage: "All uploads failed.",
});
}
// Partial failure: stay on form, sidebar shows which files are red
},
});
};
const retryAllFailed = () => {
const failedIndices = fileEntries
.map((e, i) => (e.status === "error" ? i : -1))
.filter((i) => i !== -1);
if (failedIndices.length === 0) return;
const failedFiles = failedIndices.map((i) => fileEntries[i].file);
setIsUploading(true);
setOverallProgress({ current: 0, total: failedFiles.length });
uploadImagesBatch({
files: failedFiles,
onFileStatusChange: (batchIndex, status, errorMessage) =>
updateFileStatus(failedIndices[batchIndex], status, errorMessage),
onOverallProgress: (completed, total) =>
setOverallProgress({ current: completed, total }),
onComplete: (allSucceeded, anySucceeded) => {
setIsUploading(false);
if (allSucceeded) {
onUploadProgress({ status: UploaderStates.success });
} else if (!anySucceeded) {
onUploadProgress({
status: UploaderStates.assetError,
errorMessage: "All uploads failed.",
});
}
},
});
};
const isMulti = fileEntries.length > 1;
const anyFailed = fileEntries.some((e) => e.status === "error");
const anyUploading = fileEntries.some((e) => e.status === "uploading");
// Upload has started if any file has left the idle state
const hasUploadStarted = fileEntries.some((e) => e.status !== "idle");
const allDone =
fileEntries.length > 0 &&
fileEntries.every((e) => e.status === "success" || e.status === "error");
return (
<div className="flex flex-col gap-3">
<FileUploader
fileTypes={fileTypes}
files={fileEntries.map((e) => e.file)}
handleChange={handleFilesChange}
multiple={true}
/>
{selectionError && (
<h6 className="z-10 text-red">{selectionError}</h6>
)}
{fileEntries.length > 0 && (
isMulti ? (
<PanelGroup orientation="horizontal">
{/* File list sidebar */}
<Panel defaultSize="33%" minSize="20%">
<ul className="flex h-full flex-col gap-1 overflow-y-auto rounded-lg bg-brand-secondary p-2">
{fileEntries.map((entry, i) => (
<li
key={i}
className={`group flex items-center justify-between gap-1.5 rounded px-2 py-1 cursor-pointer text-sm transition-colors ${
i === previewIndex ? "bg-white/10" : "hover:bg-white/5"
}`}
onClick={() => setPreviewIndex(i)}
>
<span className="truncate flex-1" title={entry.file.name}>
{entry.file.name.slice(0, entry.file.name.lastIndexOf("."))}
</span>
<span className="shrink-0">
{entry.status === "idle" && (
<button
className="opacity-40 hover:opacity-100 transition-opacity"
onClick={(e) => {
e.stopPropagation();
removeFile(i);
}}
title="Remove"
>
<FontAwesomeIcon icon={faXmark} />
</button>
)}
{entry.status === "uploading" && (
<FontAwesomeIcon
icon={faSpinner}
className="animate-spin opacity-60"
/>
)}
{entry.status === "success" && (
<FontAwesomeIcon
icon={faCheck}
className="text-green-400"
/>
)}
{entry.status === "error" && (
<span className="flex items-center gap-1">
<FontAwesomeIcon
icon={faCircleExclamation}
className="text-red-400"
/>
<button
className="hidden group-hover:inline-flex items-center text-xs text-white/60 hover:text-white transition-colors"
onClick={(e) => {
e.stopPropagation();
retrySingleFile(i);
}}
title="Retry"
>
<FontAwesomeIcon icon={faRotateRight} />
</button>
</span>
)}
</span>
</li>
))}
</ul>
</Panel>
<PanelResizeHandle className="flex w-4 items-center justify-center" onPointerDown={(e) => e.stopPropagation()}>
<div className="h-8 w-1 rounded-full bg-white/20 transition-colors hover:bg-white/40" />
</PanelResizeHandle>
{/* Preview + carousel navigation */}
<Panel defaultSize="67%" minSize="25%">
<div className="flex h-full flex-col gap-2">
<div className="relative aspect-square w-full overflow-hidden rounded-lg bg-brand-secondary flex items-center justify-center">
{previewUrl && (
<img
key={previewIndex}
alt="Preview"
className="m-auto max-h-full max-w-full object-contain"
src={previewUrl}
/>
)}
</div>
<div className="flex items-center justify-center gap-3">
<Button
variant="secondary"
onClick={() => setPreviewIndex((p) => Math.max(0, p - 1))}
disabled={previewIndex === 0}
>
<FontAwesomeIcon icon={faChevronLeft} />
</Button>
<span className="text-sm opacity-60">
{previewIndex + 1} / {fileEntries.length}
</span>
<Button
variant="secondary"
onClick={() =>
setPreviewIndex((p) =>
Math.min(fileEntries.length - 1, p + 1)
)
}
disabled={previewIndex === fileEntries.length - 1}
>
<FontAwesomeIcon icon={faChevronRight} />
</Button>
</div>
</div>
</Panel>
</PanelGroup>
) : (
previewUrl && (
<div className="relative m-auto flex aspect-square w-full items-center justify-center overflow-hidden rounded-lg bg-brand-secondary">
<img
alt="Preview"
className="m-auto max-h-full max-w-full object-contain"
src={previewUrl}
/>
</div>
)
)
)}
{(isUploading || anyUploading) && overallProgress && isMulti && (
<p className="text-center text-sm opacity-60">
Uploading {overallProgress.current} / {overallProgress.total}...
</p>
)}
{!isUploading && !anyUploading && allDone && anyFailed && isMulti && (
<p className="text-center text-sm text-red-400">
{fileEntries.filter((e) => e.status === "error").length} file(s) failed to upload.
</p>
)}
<div className="flex justify-end gap-2">
<Button variant="secondary" onClick={onClose}>
Cancel
</Button>
{!isUploading && !anyUploading && allDone && anyFailed && isMulti && (
<Button variant="secondary" onClick={retryAllFailed}>
Retry Failed
</Button>
)}
{/* Hide Upload once any upload has started; only Retry Failed or Close remains */}
{!hasUploadStarted && (
<Button
variant="primary"
onClick={handleSubmit}
disabled={fileEntries.length === 0}
>
Upload
</Button>
)}
</div>
</div>
);
};
@@ -1,136 +0,0 @@
import { useEffect, useState } from "react";
import { LoadingDots } from "@storyteller/ui-loading";
import { Modal } from "@storyteller/ui-modal";
import { UploadAssetError, UploadSuccess } from "@storyteller/ui-upload-modal";
import { UploadFilesImage } from "./UploadFilesImage";
import { initialUploaderState, UploaderState } from "../../../models";
import {
FilterEngineCategories,
UploaderStates,
IMAGEPLANE_FILE_TYPE,
} from "../../../enums";
import { IconDefinition } from "@fortawesome/fontawesome-svg-core";
import {
galleryModalVisibleViewMode,
galleryModalVisibleDuringDrag,
} from "@storyteller/ui-gallery-modal";
interface Props {
onClose: () => void;
onSuccess: (category: FilterEngineCategories) => void;
isOpen: boolean;
title: string;
titleIcon: IconDefinition;
initialFiles?: File[];
}
const imageFileTypes = Object.values(IMAGEPLANE_FILE_TYPE);
export function UploadModalImage(props: Props) {
const { isOpen, onClose, onSuccess, title, titleIcon, initialFiles } = props;
const [uploaderState, setUploaderState] =
useState<UploaderState>(initialUploaderState);
// Category fixed to IMAGE_PLANE
const selectedCategory = FilterEngineCategories.IMAGE_PLANE;
const updateUploaderState = (newState: UploaderState) => {
setUploaderState(newState);
};
const resetModalState = () => {
setUploaderState(initialUploaderState);
};
useEffect(() => {
if (isOpen) {
resetModalState();
}
}, [isOpen]);
const UploaderModalContent = () => {
switch (uploaderState.status) {
case UploaderStates.ready:
return (
<div className="space-y-4">
<UploadFilesImage
title={title}
fileTypes={imageFileTypes}
initialFiles={initialFiles}
onClose={onClose}
onUploadProgress={updateUploaderState}
/>
</div>
);
case UploaderStates.uploadingAsset:
case UploaderStates.uploadingCover:
case UploaderStates.settingCover: {
const p = uploaderState.uploadProgress;
return (
<>
<LoadingDots className="mb-1 bg-transparent" />
<div className="w-100 text-center opacity-50">
{p && p.total > 1
? `Uploading ${p.current} / ${p.total}...`
: "Uploading..."}
</div>
</>
);
}
case UploaderStates.success: {
return (
<UploadSuccess
title="Image"
onOk={() => {
// Open the gallery so the user can drag the freshly
// uploaded image onto the canvas.
galleryModalVisibleViewMode.value = true;
galleryModalVisibleDuringDrag.value = true;
onSuccess(selectedCategory);
onClose();
}}
/>
);
}
case UploaderStates.assetError:
return (
<UploadAssetError
onCancel={onClose}
onRetry={() => {
resetModalState();
}}
type={selectedCategory}
errorMessage={uploaderState.errorMessage}
/>
);
case UploaderStates.coverCreateError:
case UploaderStates.coverSetError:
return (
<UploadAssetError
onCancel={onClose}
onRetry={() => {
resetModalState();
}}
type={"Thumbnail"}
errorMessage={uploaderState.errorMessage}
/>
);
}
return undefined;
};
return (
<Modal
isOpen={isOpen}
onClose={onClose}
titleIcon={titleIcon}
title={title}
className="max-w-xl"
showClose={true}
>
{/* Inline call — `<Comp />` would be a fresh component reference each render, remounting the dropzone mid-click and breaking the file picker. */}
{UploaderModalContent()}
</Modal>
);
}
@@ -1 +0,0 @@
export { UploadModalImage } from "./UploadModalImage";
@@ -1,56 +0,0 @@
import { v4 as uuidv4 } from "uuid";
import { MediaUploadApi } from "../../../../Classes/ApiManager";
import { UploaderStates } from "../../../../enums";
import { UploaderState } from "../../../../models";
import { getFileName } from "../../../../utilities";
import { EIntermediateFile } from "~/enums/EIntermediateFile";
export const uploadImage = async ({
title,
assetFile,
progressCallback,
}: {
title: string;
assetFile: File;
progressCallback: (newState: UploaderState) => void;
}) => {
const mediaUploadApi = new MediaUploadApi();
console.log("Uploading image plane:", assetFile);
progressCallback({ status: UploaderStates.uploadingAsset });
const assetResponse = await mediaUploadApi.UploadImage({
blob: assetFile,
fileName: getFileName(assetFile),
uuid: uuidv4(),
maybe_title: title,
is_intermediate_system_file: EIntermediateFile.false,
});
console.log("Image plane response:", assetResponse);
if (assetResponse == undefined) {
console.log("Error: Could not upload image plane!");
progressCallback({
status: UploaderStates.assetError,
errorMessage: "Could not upload image plane!",
});
return;
}
if (!assetResponse.success || !assetResponse.data) {
console.log("Error:", assetResponse.errorMessage);
progressCallback({
status: UploaderStates.assetError,
errorMessage: assetResponse.errorMessage,
});
return;
}
console.log("Upload successful:", assetResponse.data);
progressCallback({
status: UploaderStates.success,
data: assetResponse.data,
});
};
@@ -1,63 +0,0 @@
import { UploaderStates } from "~/enums";
import { uploadImage } from "./uploadImage";
export type FileEntryStatus = "idle" | "uploading" | "success" | "error";
export const uploadImagesBatch = async ({
files,
onFileStatusChange,
onOverallProgress,
onComplete,
}: {
files: File[];
onFileStatusChange: (index: number, status: FileEntryStatus, errorMessage?: string) => void;
onOverallProgress: (completed: number, total: number) => void;
onComplete: (allSucceeded: boolean, anySucceeded: boolean) => void;
}) => {
// JS is single-threaded; these counters are safe across concurrent async callbacks.
let completedCount = 0;
let successCount = 0;
const completedIndices = new Set<number>();
files.forEach((_, i) => onFileStatusChange(i, "uploading"));
onOverallProgress(0, files.length);
try {
await Promise.all(
files.map((file, i) =>
uploadImage({
title: file.name.slice(0, file.name.lastIndexOf(".")),
assetFile: file,
progressCallback: (state) => {
if (state.status === UploaderStates.success) {
successCount++;
onFileStatusChange(i, "success");
} else if (state.status === UploaderStates.assetError) {
onFileStatusChange(i, "error", state.errorMessage);
}
if (
state.status === UploaderStates.success ||
state.status === UploaderStates.assetError
) {
if (!completedIndices.has(i)) {
completedIndices.add(i);
completedCount++;
onOverallProgress(completedCount, files.length);
}
}
},
})
)
);
} catch (err) {
// Only mark files that haven't already reached a terminal state
files.forEach((_, i) => {
if (!completedIndices.has(i)) {
onFileStatusChange(i, "error", err instanceof Error ? err.message : "Unexpected error");
}
});
}
onComplete(successCount === files.length, successCount > 0);
};
@@ -1,515 +0,0 @@
import { useCallback, useEffect, useRef, useState } from "react";
import { Group as PanelGroup, Panel, Separator as PanelResizeHandle } from "react-resizable-panels";
import { ListDropdown } from "@storyteller/ui-list-dropdown";
import { Button } from "@storyteller/ui-button";
import { FileUploader } from "@storyteller/ui-file-uploader";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import {
faCube,
faXmark,
faCheck,
faCircleExclamation,
faChevronLeft,
faChevronRight,
faRotateRight,
faSpinner,
} from "@fortawesome/pro-solid-svg-icons";
import { WebGLRenderer, PerspectiveCamera } from "three";
import { loadPreviewOnCanvas, snapshotCanvasAsThumbnail } from "../UploadModal3D/utilities";
import { upload3DObjects } from "../UploadModal3D/utilities/upload3DObjects";
import { upload3DObjectsBatch } from "../UploadModal3D/utilities/upload3DObjectsBatch";
import { FileEntryStatus } from "../UploadModalImage/utilities/uploadImagesBatch";
import type { UploaderState } from "../../../models";
import { FilterEngineCategories, MediaFileAnimationType, UploaderStates } from "../../../enums";
interface FileEntry {
file: File;
status: FileEntryStatus;
errorMessage?: string;
}
interface Props {
title: string;
fileTypes: string[];
engineCategory: FilterEngineCategories;
initialFiles?: File[];
options?: {
fileSubtypes?: { [key: string]: string }[];
hasLength?: boolean;
hasThumbnailUpload?: boolean;
};
onClose: () => void;
onUploadProgress: (newState: UploaderState) => void;
}
export const UploadFilesSplat = ({
fileTypes,
engineCategory,
initialFiles,
options,
onClose,
onUploadProgress,
}: Props) => {
const canvasRef = useRef<HTMLCanvasElement | undefined>(undefined);
const rendererRef = useRef<WebGLRenderer | null>(null);
const cameraRef = useRef<PerspectiveCamera | null>(null);
const resizeObserverRef = useRef<ResizeObserver | null>(null);
const canvasCallbackRef = useCallback((node: HTMLCanvasElement | null) => {
if (resizeObserverRef.current) {
resizeObserverRef.current.disconnect();
resizeObserverRef.current = null;
}
if (node !== null) {
canvasRef.current = node;
const observer = new ResizeObserver(() => {
const renderer = rendererRef.current;
const camera = cameraRef.current;
if (!renderer || !camera) return;
const w = node.clientWidth;
const h = node.clientHeight;
if (w === 0 || h === 0) return;
renderer.setSize(w, h, false);
camera.aspect = w / h;
camera.updateProjectionMatrix();
});
observer.observe(node);
resizeObserverRef.current = observer;
}
}, []);
const fileSubtypes = options?.fileSubtypes;
const [subtype, setSubtype] = useState<MediaFileAnimationType | undefined>(
fileSubtypes
? (Object.values(fileSubtypes[0])[0] as MediaFileAnimationType)
: undefined
);
const seedFiles = initialFiles ?? [];
const [fileEntries, setFileEntries] = useState<FileEntry[]>(
seedFiles.map((f) => ({ file: f, status: "idle" }))
);
const [previewIndex, setPreviewIndex] = useState(0);
// Incremented on every handleFilesChange so useEffect re-runs even when count stays the same
const [filesVersion, setFilesVersion] = useState(0);
const [previewStatus, setPreviewStatus] = useState<{ type: string; message?: string }>({ type: "init" });
const [thumbnails, setThumbnails] = useState<Map<File, Blob>>(new Map());
const [isUploading, setIsUploading] = useState(false);
const [overallProgress, setOverallProgress] = useState<{ current: number; total: number } | null>(null);
const [selectionError, setSelectionError] = useState<string | undefined>();
const disposeRenderer = () => {
if (rendererRef.current) {
rendererRef.current.setAnimationLoop(null);
rendererRef.current.dispose();
rendererRef.current = null;
}
};
// Reload canvas preview whenever the current file or index changes.
// filesVersion ensures this re-runs when the same-count file set is replaced.
useEffect(() => {
const currentFile = fileEntries[previewIndex]?.file;
if (!canvasRef.current || !currentFile) return;
disposeRenderer();
setPreviewStatus({ type: "init" });
const { renderer, camera } = loadPreviewOnCanvas({
file: currentFile,
canvas: canvasRef.current,
statusCallback: setPreviewStatus,
});
rendererRef.current = renderer;
cameraRef.current = camera;
return disposeRenderer;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [previewIndex, filesVersion]);
// Snapshot thumbnail when preview finishes loading
// Defer one animation frame so the splat renderer has produced a visible frame
useEffect(() => {
if (previewStatus.type === "OK" && canvasRef.current) {
const canvas = canvasRef.current;
const currentFile = fileEntries[previewIndex]?.file;
const rafId = requestAnimationFrame(() => {
snapshotCanvasAsThumbnail({
targetNode: canvas,
resultCallback: (blob) => {
if (blob && currentFile) {
setThumbnails((prev) => new Map(prev).set(currentFile, blob));
}
},
});
});
return () => cancelAnimationFrame(rafId);
}
}, [previewStatus, previewIndex]);
// Reset subtype when fileSubtypes set changes
useEffect(() => {
if (!fileSubtypes || fileSubtypes.length === 0) {
setSubtype(undefined);
return;
}
setSubtype(Object.values(fileSubtypes[0])[0] as MediaFileAnimationType | undefined);
}, [fileSubtypes]);
const updateFileStatus = (
index: number,
status: FileEntryStatus,
errorMessage?: string
) => {
setFileEntries((prev) =>
prev.map((entry, i) =>
i === index ? { ...entry, status, errorMessage } : entry
)
);
};
const removeFile = (index: number) => {
setFileEntries((prev) => {
const next = prev.filter((_, i) => i !== index);
setPreviewIndex((prevIdx) => Math.min(prevIdx, Math.max(0, next.length - 1)));
return next;
});
setFilesVersion((v) => v + 1);
};
const retrySingleFile = async (index: number) => {
const entry = fileEntries[index];
if (!entry || entry.status === "uploading") return;
updateFileStatus(index, "uploading");
await upload3DObjects({
title: entry.file.name.slice(0, entry.file.name.lastIndexOf(".")),
assetFile: entry.file,
engineCategory,
animationType: subtype,
thumbnailSnapshot: thumbnails.get(entry.file),
progressCallback: (state) => {
if (state.status === UploaderStates.success) {
updateFileStatus(index, "success");
} else if (
state.status === UploaderStates.assetError ||
state.status === UploaderStates.coverCreateError ||
state.status === UploaderStates.coverSetError
) {
updateFileStatus(index, "error", state.errorMessage);
}
},
});
};
const handleFilesChange = (files: File[]) => {
setFileEntries(files.map((f) => ({ file: f, status: "idle" })));
setPreviewIndex(0);
setFilesVersion((v) => v + 1);
setThumbnails(new Map());
setSelectionError(undefined);
setOverallProgress(null);
setIsUploading(false);
};
const handleSubmit = () => {
if (fileEntries.length === 0) {
setSelectionError("Please select a file to upload.");
return;
}
// Only upload files that haven't already succeeded
const pendingEntries = fileEntries
.map((e, i) => ({ entry: e, originalIndex: i }))
.filter(({ entry }) => entry.status !== "success");
const files = pendingEntries.map(({ entry }) => entry.file);
const originalIndices = pendingEntries.map(({ originalIndex }) => originalIndex);
const pendingThumbnails = new Map<File, Blob>(
files
.map((file): [File, Blob | undefined] => [file, thumbnails.get(file)])
.filter((pair): pair is [File, Blob] => pair[1] !== undefined)
);
if (files.length === 1 && fileEntries.length === 1) {
// Single file: use parent modal state machine (shows loading spinner)
upload3DObjects({
title: files[0].name.slice(0, files[0].name.lastIndexOf(".")),
assetFile: files[0],
engineCategory,
animationType: subtype,
thumbnailSnapshot: thumbnails.get(files[0]),
progressCallback: onUploadProgress,
});
return;
}
// Multi-file: stay on form, show inline progress
setIsUploading(true);
setOverallProgress({ current: 0, total: files.length });
upload3DObjectsBatch({
files,
thumbnails: pendingThumbnails,
engineCategory,
animationType: subtype,
onFileStatusChange: (batchIndex, status, errorMessage) =>
updateFileStatus(originalIndices[batchIndex], status, errorMessage),
onOverallProgress: (completed, total) =>
setOverallProgress({ current: completed, total }),
onComplete: (allSucceeded, anySucceeded) => {
setIsUploading(false);
if (allSucceeded) {
onUploadProgress({ status: UploaderStates.success });
} else if (!anySucceeded) {
onUploadProgress({
status: UploaderStates.assetError,
errorMessage: "All uploads failed.",
});
}
},
});
};
const retryAllFailed = () => {
const failedIndices = fileEntries
.map((e, i) => (e.status === "error" ? i : -1))
.filter((i) => i !== -1);
if (failedIndices.length === 0) return;
const failedFiles = failedIndices
.map((i) => fileEntries[i].file)
.filter((file) => file !== undefined);
const failedThumbnails = new Map<File, Blob>(
failedFiles
.map((file): [File, Blob | undefined] => [file, thumbnails.get(file) ?? undefined])
.filter((pair): pair is [File, Blob] => pair[1] !== undefined)
);
setIsUploading(true);
setOverallProgress({ current: 0, total: failedFiles.length });
upload3DObjectsBatch({
files: failedFiles,
thumbnails: failedThumbnails,
engineCategory,
animationType: subtype,
onFileStatusChange: (batchIndex, status, errorMessage) =>
updateFileStatus(failedIndices[batchIndex], status, errorMessage),
onOverallProgress: (completed, total) =>
setOverallProgress({ current: completed, total }),
onComplete: (allSucceeded, anySucceeded) => {
setIsUploading(false);
if (allSucceeded) {
onUploadProgress({ status: UploaderStates.success });
} else if (!anySucceeded) {
onUploadProgress({
status: UploaderStates.assetError,
errorMessage: "All uploads failed.",
});
}
},
});
};
const isMulti = fileEntries.length > 1;
const anyFailed = fileEntries.some((e) => e.status === "error");
const anyUploading = fileEntries.some((e) => e.status === "uploading");
const hasUploadStarted = fileEntries.some((e) => e.status !== "idle");
const allDone =
fileEntries.length > 0 &&
fileEntries.every((e) => e.status === "success" || e.status === "error");
const currentFile = fileEntries[previewIndex]?.file;
return (
<div className="flex flex-col gap-3">
{fileSubtypes && fileSubtypes.length > 1 && (
<ListDropdown
list={fileSubtypes}
onSelect={(value) => setSubtype(value as MediaFileAnimationType)}
/>
)}
<FileUploader
fileTypes={fileTypes}
files={fileEntries.map((e) => e.file)}
handleChange={handleFilesChange}
multiple={true}
fileIcon={faCube}
/>
{selectionError && (
<h6 className="z-10 text-red">{selectionError}</h6>
)}
{isMulti ? (
<PanelGroup orientation="horizontal">
{/* File list sidebar */}
<Panel defaultSize="33%" minSize="20%">
<ul className="flex h-full flex-col gap-1 overflow-y-auto rounded-lg bg-brand-secondary p-2">
{fileEntries.map((entry, i) => (
<li
key={i}
className={`group flex items-center justify-between gap-1.5 rounded px-2 py-1 cursor-pointer text-sm transition-colors ${
i === previewIndex ? "bg-white/10" : "hover:bg-white/5"
}`}
onClick={() => setPreviewIndex(i)}
>
<span className="truncate flex-1" title={entry.file.name}>
{entry.file.name.slice(0, entry.file.name.lastIndexOf("."))}
</span>
<span className="shrink-0">
{entry.status === "idle" && (
<button
className="opacity-40 hover:opacity-100 transition-opacity"
onClick={(e) => {
e.stopPropagation();
removeFile(i);
}}
title="Remove"
>
<FontAwesomeIcon icon={faXmark} />
</button>
)}
{entry.status === "uploading" && (
<FontAwesomeIcon
icon={faSpinner}
className="animate-spin opacity-60"
/>
)}
{entry.status === "success" && (
<FontAwesomeIcon icon={faCheck} className="text-green-400" />
)}
{entry.status === "error" && (
<span className="flex items-center gap-1">
<FontAwesomeIcon
icon={faCircleExclamation}
className="text-red-400"
/>
<button
className="hidden group-hover:inline-flex items-center text-xs text-white/60 hover:text-white transition-colors"
onClick={(e) => {
e.stopPropagation();
retrySingleFile(i);
}}
title="Retry"
>
<FontAwesomeIcon icon={faRotateRight} />
</button>
</span>
)}
</span>
</li>
))}
</ul>
</Panel>
<PanelResizeHandle className="flex w-4 items-center justify-center" onPointerDown={(e) => e.stopPropagation()}>
<div className="h-8 w-1 rounded-full bg-white/20 transition-colors hover:bg-white/40" />
</PanelResizeHandle>
{/* Canvas preview + carousel */}
<Panel defaultSize="67%" minSize="25%">
<div className="flex h-full flex-col gap-2">
<div className="relative w-full min-h-48 overflow-hidden rounded-lg bg-brand-secondary">
<canvas
className="pointer-events-none h-full min-h-48 !w-full"
ref={canvasCallbackRef}
/>
{!currentFile && (
<h6 className="pointer-events-auto absolute left-0 top-1/2 -mt-5 flex w-full items-center justify-center gap-2.5 text-center opacity-50">
<FontAwesomeIcon icon={faCube} />
Your model preview will appear here
</h6>
)}
{previewStatus.type.includes("Error") && (
<h6 className="pointer-events-auto absolute left-0 top-1/2 -mt-5 w-full text-center">
{previewStatus.type}
{previewStatus.message && <br />}
{previewStatus.message}
</h6>
)}
</div>
<div className="flex items-center justify-center gap-3">
<Button
variant="secondary"
onClick={() => setPreviewIndex((p) => Math.max(0, p - 1))}
disabled={previewIndex === 0}
>
<FontAwesomeIcon icon={faChevronLeft} />
</Button>
<span className="text-sm opacity-60">
{previewIndex + 1} / {fileEntries.length}
</span>
<Button
variant="secondary"
onClick={() =>
setPreviewIndex((p) =>
Math.min(fileEntries.length - 1, p + 1)
)
}
disabled={previewIndex === fileEntries.length - 1}
>
<FontAwesomeIcon icon={faChevronRight} />
</Button>
</div>
</div>
</Panel>
</PanelGroup>
) : (
/* Single-file layout: canvas takes full width (original behaviour) */
<div className="relative m-auto w-full min-h-48 overflow-hidden rounded-lg bg-brand-secondary">
<canvas
className="pointer-events-none h-full min-h-48 !w-full"
ref={canvasCallbackRef}
/>
{!currentFile && (
<h6 className="pointer-events-auto absolute left-0 top-1/2 -mt-5 flex w-full items-center justify-center gap-2.5 text-center opacity-50">
<FontAwesomeIcon icon={faCube} />
Your model preview will appear here
</h6>
)}
{previewStatus.type.includes("Error") && (
<h6 className="pointer-events-auto absolute left-0 top-1/2 -mt-5 w-full text-center">
{previewStatus.type}
{previewStatus.message && <br />}
{previewStatus.message}
</h6>
)}
</div>
)}
{(isUploading || anyUploading) && overallProgress && isMulti && (
<p className="text-center text-sm opacity-60">
Uploading {overallProgress.current} / {overallProgress.total}...
</p>
)}
{!isUploading && !anyUploading && allDone && anyFailed && isMulti && (
<p className="text-center text-sm text-red-400">
{fileEntries.filter((e) => e.status === "error").length} file(s) failed to upload.
</p>
)}
<div className="flex justify-end gap-2">
<Button variant="secondary" onClick={onClose}>
Cancel
</Button>
{!isUploading && !anyUploading && allDone && anyFailed && isMulti && (
<Button variant="secondary" onClick={retryAllFailed}>
Retry Failed
</Button>
)}
{/* Hide Upload once any upload has started; only Retry Failed or Close remains */}
{!hasUploadStarted && (
<Button
variant="primary"
onClick={handleSubmit}
disabled={fileEntries.length === 0}
>
Upload
</Button>
)}
</div>
</div>
);
};
@@ -1,144 +0,0 @@
import { useEffect, useMemo, useState } from "react";
import { LoadingDots } from "@storyteller/ui-loading";
import { Modal } from "@storyteller/ui-modal";
import { UploadAssetError, UploadSuccess } from "@storyteller/ui-upload-modal";
import { initialUploaderState, UploaderState } from "../../../models";
import {
FilterEngineCategories,
UploaderStates,
MediaFileAnimationType,
SPLAT_FILE_TYPE,
} from "../../../enums";
import { IconDefinition } from "@fortawesome/fontawesome-svg-core";
import {
galleryModalVisibleViewMode,
galleryModalVisibleDuringDrag,
} from "@storyteller/ui-gallery-modal";
import { UploadFilesSplat } from "./UploadFilesSplat";
interface Props {
onClose: () => void;
onSuccess: (category: FilterEngineCategories) => void;
isOpen: boolean;
title: string;
titleIcon: IconDefinition;
initialFiles?: File[];
options?: {
fileSubtypes?: { [key: string]: string }[];
hasLength?: boolean;
hasThumbnailUpload?: boolean;
};
}
const splatFileTypes = Object.values(SPLAT_FILE_TYPE);
export function UploadModalSplat(props: Props) {
const selectedCategory = FilterEngineCategories.SPLAT;
const { isOpen, onClose, onSuccess, title, titleIcon, initialFiles, options } = props;
const [uploaderState, setUploaderState] =
useState<UploaderState>(initialUploaderState);
const updateUploaderState = (newState: UploaderState) => {
setUploaderState(newState);
};
const resetModalState = () => {
setUploaderState(initialUploaderState);
};
useEffect(() => {
if (isOpen) {
resetModalState();
}
}, [isOpen]);
const UploaderModalContent = () => {
switch (uploaderState.status) {
case UploaderStates.ready:
return (
<div className="space-y-4">
<UploadFilesSplat
title={title}
engineCategory={selectedCategory}
fileTypes={splatFileTypes}
initialFiles={initialFiles}
options={{
...(options ?? {}),
}}
onClose={onClose}
onUploadProgress={updateUploaderState}
/>
</div>
);
case UploaderStates.uploadingAsset:
case UploaderStates.uploadingCover:
case UploaderStates.settingCover: {
const p = uploaderState.uploadProgress;
return (
<>
<LoadingDots className="mb-1 bg-transparent" />
<div className="w-100 text-center opacity-50">
{p && p.total > 1
? `Uploading ${p.current} / ${p.total}...`
: "Uploading..."}
</div>
</>
);
}
case UploaderStates.success: {
return (
<UploadSuccess
title="Splat"
onOk={() => {
// Open the gallery so the user can drag the freshly
// uploaded splat onto the canvas.
galleryModalVisibleViewMode.value = true;
galleryModalVisibleDuringDrag.value = true;
onSuccess(selectedCategory);
onClose();
}}
/>
);
}
case UploaderStates.assetError:
return (
<UploadAssetError
onCancel={onClose}
onRetry={() => {
resetModalState();
}}
type={selectedCategory}
errorMessage={uploaderState.errorMessage}
/>
);
case UploaderStates.coverCreateError:
case UploaderStates.coverSetError:
return (
<UploadAssetError
onCancel={onClose}
onRetry={() => {
resetModalState();
}}
type={"Thumbnail"}
errorMessage={uploaderState.errorMessage}
/>
);
}
return undefined;
};
return (
<Modal
isOpen={isOpen}
onClose={onClose}
titleIcon={titleIcon}
title={title}
className="max-w-xl"
showClose={true}
>
{/* Inline call — `<Comp />` would be a fresh component reference each render, remounting the dropzone mid-click and breaking the file picker. */}
{UploaderModalContent()}
</Modal>
);
}
@@ -1 +0,0 @@
export * from "./UploadModalSplat";
@@ -2,7 +2,7 @@ import { useState } from "react";
import { Button } from "@storyteller/ui-button";
import { Tooltip } from "@storyteller/ui-tooltip";
import { faUpload, faImages } from "@fortawesome/pro-solid-svg-icons";
import { UploadModalImage } from "../../reusable/UploadModalImage/UploadModalImage";
import { UploadModalImage } from "@storyteller/ui-upload-modal";
interface Props {
className?: string;
@@ -25,9 +25,11 @@ import { ToastTypes } from "@storyteller/ui-pagescene";
import { GetCdnOrigin } from "~/api/GetCdnOrigin";
import { BucketConfig } from "~/api/BucketConfig";
import { MediaFilesApi as ArtcraftMediaFilesApi } from "~/Classes/ApiManager";
import { UploadModal3D } from "~/components/reusable/UploadModal3D";
import { UploadModalImage } from "~/components/reusable/UploadModalImage";
import { UploadModalSplat } from "~/components/reusable/UploadModalSplat";
import {
UploadModal3D,
UploadModalImage,
UploadModalSplat,
} from "@storyteller/ui-upload-modal";
import { uploadImage as hostUploadImage } from "~/components/reusable/UploadModalMedia/uploadImage";
import { uploadPlaneFromMediaToken as hostUploadPlaneFromMediaToken } from "~/components/reusable/UploadModalMedia/uploadPlane";
import { useTabStore } from "~/pages/Stores/TabState";