mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-19 16:15:04 +00:00
supress error for process env, added vscode setting to gitignore segrgate enums (#369) Co-authored-by: Christopher Oliphant <RALifeCoach@users.noreply.github.com> Refactor storybook (#370) Co-authored-by: Christopher Oliphant <RALifeCoach@users.noreply.github.com> button dropdown docs (#372) storybook doc for button dropdown component refactor side panel tabs (#371) Co-authored-by: Christopher Oliphant <RALifeCoach@users.noreply.github.com> fix enums (#373) Co-authored-by: Christopher Oliphant <RALifeCoach@users.noreply.github.com> Refactoring Auth Context to Signals (#374) - file restructure, store -> signals - rewrite AuthContext to signals, and get rid of AuthContext - modify all files that need to use AuthContext to use the authentication Signal - the complex login persistency logic is now just a persistLogin function ran at root! - fetchers uses the auth signal directly to get the sessionToken - components no longer useSignals for these fetchers, hence decoupled from the auth signals !! components and fetchers that are definitely subjected to refactor does not receive the useSignal decoupling treatment Co-authored-by: wil <wil@storyteller.ai> Refactoring Toaster Context to a Toaster Component + Signal (#378) - Created the Toaster Component - Created the Toasts Signal - Now no useContext is needed for Toast Poping, nor passing AddToast around - Simply import addToast from the Signals and you can pop a toast from anywhere in the codebase Co-authored-by: wil <wil@storyteller.ai> Refactoring AppUi Context (partial: delete unused, editorLoader becomes signal) (#379) - dialogueTTS is unused, hence deleted - view side-by-side mode is unused, hence deleted - timeline height in this context was already made into signal, hence deleted - editorLoader in this context is now made into a page level signal, hence deleted - components and dispatcher of the editorLoader are modified to use signal instead - app level reducer is no longer used, tugged into context folder to avoid confusion, will be deleted when all attributes in AppUi context is refactored into signals Co-authored-by: wil <wil@storyteller.ai> Refactor control panel (#391) - control panel - simplified and improved - Please also test it. It operates slightly differently. For example, if the user types an invalid character, the character is ignored. --------- Co-authored-by: Christopher Oliphant <RALifeCoach@users.noreply.github.com> Refactoring App Level Components - Components that are in the /app/component folder are split into reusable and signaled - reusable are in theory signal independent - signaled are dependent on signals (and maybe a use-once component) - some app level components has page level enums or signals, those are bumped to app level now - all components in the module directory are moved into the component directories depending on whether it's reusable or signaled - code changes in are mostly just import changes to get re-target to get the correct files - discovered a small bug in FilterButtons and is fixed - whether a component need more work, it is commented on the index file that import them into the grand collection of components Refactor - Signals Part 2 - store is renamed to signals in PageEditor for clarity - ObjectControlPanel now uses a Signal instead of the AppUiContext - Moved EditorContext to Page Level, all context are page level only now - editor is modified to read and use signals directly (for now), this includes: -- the ObjectPanel signal -- the Scene signal -- the Authentication signal - and hence, editor now has a constructor doesn't require any arguments - editor also has a simple initialization - AppUiContext is retired completely and deleted --------- Co-authored-by: wil <wil@storyteller.ai> Co-authored-by: Christopher Oliphant <RALifeCoach@users.noreply.github.com>
218 lines
6.1 KiB
TypeScript
218 lines
6.1 KiB
TypeScript
import { useEffect, useState } from "react";
|
|
import { v4 as uuidv4 } from "uuid";
|
|
import {
|
|
faCirclePlus,
|
|
faFileArrowUp,
|
|
faFileAudio,
|
|
faSpinnerThird,
|
|
} from "@fortawesome/pro-solid-svg-icons";
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
import { FileUploader } from "react-drag-drop-files";
|
|
|
|
import {
|
|
Button,
|
|
H2,
|
|
P,
|
|
TransitionDialogue,
|
|
WaveformPlayer,
|
|
} from "~/components";
|
|
|
|
import { UploadMedia, UploadMediaResponse } from "./utilities";
|
|
|
|
import { AUDIO_FILE_TYPE } from "~/enums";
|
|
const FILE_TYPES = Object.keys(AUDIO_FILE_TYPE);
|
|
|
|
// import { ListDropdown } from "../ListDropdown";
|
|
// const visiblityOptions = [
|
|
// {
|
|
// name: "private",
|
|
// value: "private",
|
|
// },
|
|
// {
|
|
// name: "public",
|
|
// value: "public",
|
|
// },
|
|
// ];
|
|
|
|
type ComponentState = {
|
|
isOpen: boolean;
|
|
file: File | undefined;
|
|
audioUrl: string;
|
|
uploadState: "init" | "staged" | "uploading" | "uploaded" | "error";
|
|
// visibility: string;
|
|
fileToken: string | undefined;
|
|
};
|
|
const initialValues: ComponentState = {
|
|
isOpen: false,
|
|
file: undefined,
|
|
audioUrl: "",
|
|
uploadState: "init",
|
|
// visibility: "private",
|
|
fileToken: undefined,
|
|
};
|
|
|
|
const getFileName = (file: File) => {
|
|
return file.name.split(".")[0] || "";
|
|
};
|
|
|
|
export const UploadAudioButtonDialogue = ({
|
|
onUploaded,
|
|
}: {
|
|
onUploaded: (fileToken: string) => void;
|
|
}) => {
|
|
const [{ isOpen, file, audioUrl, uploadState, fileToken }, setState] =
|
|
useState<ComponentState>(initialValues);
|
|
|
|
const closeModal = () => setState(initialValues);
|
|
const openModal = () => setState((curr) => ({ ...curr, isOpen: true }));
|
|
// const selectVisibility = (value:string) => {
|
|
// setState((curr)=>({...curr, visibility:value}))
|
|
// };
|
|
const handleFileChange = (file: File) => {
|
|
setState((curr) => ({
|
|
...curr,
|
|
file: file,
|
|
audioUrl: URL.createObjectURL(file),
|
|
uploadState: "staged",
|
|
}));
|
|
};
|
|
const handleClear = () => {
|
|
setState({
|
|
...initialValues,
|
|
isOpen: true,
|
|
});
|
|
};
|
|
const submitUpload = () => {
|
|
if (file) {
|
|
setState((curr) => ({
|
|
...curr,
|
|
uploadState: "uploading",
|
|
}));
|
|
UploadMedia({
|
|
uuid_idempotency_token: uuidv4(),
|
|
file: file,
|
|
source: "file",
|
|
title: getFileName(file),
|
|
}).then((res: UploadMediaResponse) => {
|
|
// console.log(res);
|
|
if ("media_file_token" in res) {
|
|
setState((curr) => ({
|
|
...curr,
|
|
uploadState: "uploaded",
|
|
fileToken: res.media_file_token,
|
|
}));
|
|
} else {
|
|
setState((curr) => ({
|
|
...curr,
|
|
uploadState: "error",
|
|
}));
|
|
}
|
|
});
|
|
}
|
|
};
|
|
useEffect(() => {
|
|
if (fileToken) {
|
|
onUploaded(fileToken);
|
|
}
|
|
}, [fileToken]);
|
|
return (
|
|
<>
|
|
<Button
|
|
className="grow py-3 text-sm font-medium"
|
|
variant="action"
|
|
icon={faCirclePlus}
|
|
type="button"
|
|
onClick={openModal}
|
|
>
|
|
Upload Audio
|
|
</Button>
|
|
<TransitionDialogue
|
|
isOpen={isOpen}
|
|
onClose={closeModal}
|
|
title={<H2>Upload Audio</H2>}
|
|
>
|
|
<div className="flex w-full flex-col gap-3">
|
|
<FileUploader
|
|
handleChange={handleFileChange}
|
|
name="file"
|
|
types={FILE_TYPES}
|
|
maxSize={50}
|
|
children={<DragAndDropZone file={file} />}
|
|
/>
|
|
{file && (
|
|
<div className="flex items-center gap-3 rounded-lg bg-brand-secondary p-3">
|
|
<div className="grow">
|
|
<WaveformPlayer audio={audioUrl} hasPlayButton />
|
|
</div>
|
|
</div>
|
|
)}
|
|
{/* <ListDropdown list={visiblityOptions} onSelect={selectVisibility}/> */}
|
|
<div className="flex justify-end gap-3">
|
|
<Button variant="secondary" onClick={closeModal}>
|
|
{uploadState === "uploaded" ? "Close" : "Cancel"}
|
|
</Button>
|
|
{uploadState !== "uploaded" && (
|
|
<Button
|
|
onClick={submitUpload}
|
|
disabled={uploadState !== "staged"}
|
|
>
|
|
Upload
|
|
{uploadState === "uploading" && (
|
|
<FontAwesomeIcon icon={faSpinnerThird} spin />
|
|
)}
|
|
</Button>
|
|
)}
|
|
{uploadState === "uploaded" && (
|
|
<Button onClick={handleClear}>Upload Another</Button>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</TransitionDialogue>
|
|
</>
|
|
);
|
|
};
|
|
|
|
const DragAndDropZone = ({ file }: { file: File | undefined }) => {
|
|
const fileSize =
|
|
file && file.size >= 1024 * 1024
|
|
? (file.size / 1024 / 1024).toFixed(2) + " MB"
|
|
: file
|
|
? `${Math.floor(file.size / 1024)} KB`
|
|
: null;
|
|
|
|
const fileName = file && getFileName(file).toUpperCase();
|
|
|
|
if (!file) {
|
|
return (
|
|
<div className="flex cursor-pointer items-center gap-3.5 rounded-lg border-2 border-dashed border-ui-controls-button/50 bg-brand-secondary p-3">
|
|
<FontAwesomeIcon icon={faFileArrowUp} className="text-4xl" />
|
|
<div className="flex flex-col gap-0">
|
|
<P className="font-medium">
|
|
<u>Upload a file</u> or drop it here
|
|
</P>
|
|
<P className="flex items-center gap-2 text-sm font-normal opacity-50">
|
|
{FILE_TYPES.join(", ").toString()} supported
|
|
</P>
|
|
</div>
|
|
</div>
|
|
);
|
|
} else {
|
|
return (
|
|
<div className="flex cursor-pointer items-center justify-between gap-3.5 rounded-lg border-2 border-dashed border-ui-controls-button/50 bg-brand-secondary p-3">
|
|
<FontAwesomeIcon icon={faFileAudio} className="text-4xl" />
|
|
<div className="flex grow flex-col gap-0">
|
|
<P className="font-medium">
|
|
{file.name.slice(0, file.name.lastIndexOf("."))}
|
|
</P>
|
|
<P className="flex items-center gap-2 text-sm font-normal">
|
|
<span className="opacity-50">
|
|
{`${fileName} file size: ${fileSize} `}
|
|
</span>
|
|
<u className="transition-all hover:text-white/80">Change File</u>
|
|
</P>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
};
|