mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 17:38:10 +00:00
- Rebased to take the filter object from bombay - New Object Upload Tab available in Film Set Tab and Object Tab - Character Tab now uses the generic uploader because previewing and taking a snapshot of a character is too much of a code challenge atm. - added the dev-only feature tag, expressions uploads is now dev-only - went over acceptable file types and took out refreshed all the upload tabs - realign the code so all upload tabs uses the exact same logic, interfaces, and code structure, for better legibility this PR eliminates: https://github.com/storytold/GottaGoFast/pull/600 https://github.com/storytold/GottaGoFast/pull/598 --------- Co-authored-by: wil <wil@storyteller.ai>
116 lines
2.8 KiB
TypeScript
116 lines
2.8 KiB
TypeScript
import { useEffect, useState } from "react";
|
|
|
|
import { TransitionDialogue, LoadingDots } from "~/components";
|
|
|
|
import { UploadAssetError } from "./UploadAssetError";
|
|
import { UploadSuccess } from "./UploadSuccess";
|
|
import { UploadFiles } from "./UploadFiles";
|
|
|
|
import { FilterEngineCategories, UploaderStates } from "~/enums";
|
|
import { UploaderState, initialUploaderState } from "~/models";
|
|
|
|
interface Props {
|
|
onClose: () => void;
|
|
onSuccess: () => void;
|
|
isOpen: boolean;
|
|
title: string;
|
|
fileTypes: string[];
|
|
type: FilterEngineCategories;
|
|
options?: {
|
|
fileSubtypes?: { [key: string]: string }[];
|
|
hasLength?: boolean;
|
|
hasThumbnailUpload?: boolean;
|
|
};
|
|
}
|
|
|
|
export function UploadModal({
|
|
isOpen,
|
|
onClose,
|
|
onSuccess,
|
|
title,
|
|
fileTypes,
|
|
type,
|
|
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 (
|
|
<UploadFiles
|
|
title={title}
|
|
engineCategory={type}
|
|
fileTypes={fileTypes}
|
|
options={options}
|
|
onClose={onClose}
|
|
onUploadProgress={updateUploaderState}
|
|
/>
|
|
);
|
|
case UploaderStates.uploadingAsset:
|
|
case UploaderStates.uploadingCover:
|
|
case UploaderStates.settingCover:
|
|
return (
|
|
<>
|
|
<LoadingDots className="mb-1 bg-transparent" />
|
|
<div className="w-100 text-center opacity-50">Uploading...</div>
|
|
</>
|
|
);
|
|
case UploaderStates.success:
|
|
return (
|
|
<UploadSuccess
|
|
title={title}
|
|
onOk={() => {
|
|
onSuccess();
|
|
onClose();
|
|
}}
|
|
/>
|
|
);
|
|
case UploaderStates.assetError:
|
|
return (
|
|
<UploadAssetError
|
|
onCancel={onClose}
|
|
onRetry={() => {
|
|
resetModalState();
|
|
}}
|
|
type={type}
|
|
errorMessage={uploaderState.errorMessage}
|
|
/>
|
|
);
|
|
case UploaderStates.coverCreateError:
|
|
case UploaderStates.coverSetError:
|
|
return (
|
|
<UploadAssetError
|
|
onCancel={onClose}
|
|
onRetry={() => {
|
|
resetModalState();
|
|
}}
|
|
type={"Thumbnail"}
|
|
errorMessage={uploaderState.errorMessage}
|
|
/>
|
|
);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<TransitionDialogue isOpen={isOpen} onClose={onClose} title={title}>
|
|
<UploaderModalContent />
|
|
</TransitionDialogue>
|
|
);
|
|
}
|