removed voice designer unnecessary field divs

This commit is contained in:
BFlat committed 2023-12-31 12:55:45 +07:00
1 parent 14e266f7cb
commit 2b17b5d76f
3 files changed
+130 -102

No files matched your search

@@ -67,43 +67,37 @@ function VoiceDesignerVoiceEditPage() {
/>
<Panel>
<div className="d-flex flex-column gap-4 p-3 py-4 p-md-4">
<div>
<TempInput
{...{
label: "Title",
placeholder: "Voice name",
onChange: inputCtrl(titleSet),
value: title,
}}
/>
</div>
<div className="p-3 py-4 p-md-4">
<TempInput
{...{
label: "Title",
placeholder: "Voice name",
onChange: inputCtrl(titleSet),
value: title,
}}
/>
<div>
<TempSelect
{...{
icon: faLanguage,
label: "Language",
// placeholder: "Voice name",
onChange: inputCtrl(languageSet),
options: languages,
value: language,
}}
/>
</div>
<TempSelect
{...{
icon: faLanguage,
label: "Language",
// placeholder: "Voice name",
onChange: inputCtrl(languageSet),
options: languages,
value: language,
}}
/>
<div>
<TempSelect
{...{
icon: faEye,
label: "Visibility",
// placeholder: "Voice name",
onChange: inputCtrl(visibilitySet),
options: visibilityOptions,
value: visibility,
}}
/>
</div>
<TempSelect
{...{
icon: faEye,
label: "Visibility",
// placeholder: "Voice name",
onChange: inputCtrl(visibilitySet),
options: visibilityOptions,
value: visibility,
}}
/>
</div>
<hr className="mt-0 mb-4" />
<div className="p-3 pb-4 px-lg-4 pt-0">
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from "react";
import { AudioInput } from "components/common";
import moment from 'moment';
import moment from "moment";
import ListItems from "../NewList";
import { v4 as uuidv4 } from "uuid";
import { ListSamplesForDataset } from "@storyteller/components/src/api/voice_designer/voice_dataset_samples/ListSamplesForDataset";
@@ -10,72 +10,94 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faWaveform } from "@fortawesome/pro-solid-svg-icons";
interface Props {
audioProps: any,
datasetToken?: string,
deleting: any,
deletingSet: any,
inProgress: any,
inProgressSet: any
samples: any,
samplesSet: any
audioProps: any;
datasetToken?: string;
deleting: any;
deletingSet: any;
inProgress: any;
inProgressSet: any;
samples: any;
samplesSet: any;
}
function UploadSamples({ audioProps, datasetToken, deleting, deletingSet, inProgress, inProgressSet, samples, samplesSet }: Props) {
const [listFetched,listFetchedSet] = useState(false);
function UploadSamples({
audioProps,
datasetToken,
deleting,
deletingSet,
inProgress,
inProgressSet,
samples,
samplesSet,
}: Props) {
const [listFetched, listFetchedSet] = useState(false);
const SampleBadge = () => <FontAwesomeIcon icon={faWaveform} className="me-2 me-lg-3" />;
const SampleBadge = () => (
<FontAwesomeIcon icon={faWaveform} className="me-2 me-lg-3" />
);
const sampleClick = () => ({ target }: { target: any }) => {
let sampleToken = samples[target.name.split(",")[0].split(":")[1]].sample_token;
deletingSet([ ...deleting, sampleToken ]); // add to deleting list
DeleteSample(sampleToken,{ as_mod: false, set_delete: true })
.then((res) => {
listFetchedSet(false);
deletingSet(deleting.filter((item: any) => item === sampleToken)); // remove from deleting list
});
};
const sampleClick =
() =>
({ target }: { target: any }) => {
let sampleToken =
samples[target.name.split(",")[0].split(":")[1]].sample_token;
deletingSet([...deleting, sampleToken]); // add to deleting list
DeleteSample(sampleToken, { as_mod: false, set_delete: true }).then(
res => {
listFetchedSet(false);
deletingSet(deleting.filter((item: any) => item === sampleToken)); // remove from deleting list
}
);
};
const actionSamples = [ // these spread operators combine the inProgress and sample arrays
const actionSamples = [
// these spread operators combine the inProgress and sample arrays
...inProgress,
...samples.map((sample: any, i: number) => {
let date = new Date(sample.created_at);
return {
...sample,
badge: SampleBadge,
buttons: [
{
label: "Delete",
small: true,
variant: "secondary",
onClick: sampleClick()
},
],
name: `Sample from ${ date ? moment(date).format("MMMM Do YYYY, h:mm a") : "" }`,
};
})
let date = new Date(sample.created_at);
return {
...sample,
badge: SampleBadge,
buttons: [
{
label: "Delete",
small: true,
variant: "secondary",
onClick: sampleClick(),
},
],
name: `Sample from ${
date ? moment(date).format("MMMM Do YYYY, h:mm a") : ""
}`,
};
}),
];
useEffect(() => {
if (audioProps.file && datasetToken) {
let uuid_idempotency_token = uuidv4();
audioProps.clear();
inProgressSet([ // add sample to in progress list
inProgressSet([
// add sample to in progress list
{
// badge: Component // this can be a loading indicator
// badge: Component // this can be a loading indicator
name: "Uploading",
uuid_idempotency_token
uuid_idempotency_token,
},
...inProgress
...inProgress,
]);
UploadSample("",{
UploadSample("", {
dataset_token: datasetToken || "",
file: audioProps.file,
uuid_idempotency_token,
})
.then((res) => {
}).then(res => {
if (res.success) {
inProgressSet(inProgress.filter((item: any) => // removes sample from in progress list
item.uuid_idempotency_token === uuid_idempotency_token)
inProgressSet(
inProgress.filter(
(
item: any // removes sample from in progress list
) => item.uuid_idempotency_token === uuid_idempotency_token
)
);
listFetchedSet(false); // refetches sample list
}
@@ -84,30 +106,40 @@ function UploadSamples({ audioProps, datasetToken, deleting, deletingSet, inProg
if (datasetToken && !listFetched) {
listFetchedSet(true);
ListSamplesForDataset(datasetToken,{})
.then((res) => {
ListSamplesForDataset(datasetToken, {}).then(res => {
if (res.success && res.samples) {
samplesSet(res.samples);
}
});
}
}, [
audioProps,
datasetToken,
listFetched,
inProgress,
inProgressSet,
samplesSet,
]);
},[audioProps, datasetToken, listFetched, inProgress, inProgressSet, samplesSet]);
return <div className="d-flex flex-column gap-4">
<label className="sub-title">Upload Audio</label>
<div className="d-flex flex-column gap-3 upload-component">
<AudioInput {...{ ...audioProps }}/>
{ actionSamples.length ? <ListItems {...{ data: actionSamples, isLoading: false }}/> :
<div className="panel panel-inner text-center p-5 rounded-5 h-100">
<div className="d-flex flex-column opacity-75 h-100 justify-content-center">
<FontAwesomeIcon icon={faWaveform} className="fs-3 mb-3" />
<h5>No voice samples yet</h5>
<p>Uploaded samples will appear here.</p>
return (
<div>
<label className="sub-title">Upload Audio</label>
<div className="d-flex flex-column gap-3 upload-component">
<AudioInput {...{ ...audioProps }} />
{actionSamples.length ? (
<ListItems {...{ data: actionSamples, isLoading: false }} />
) : (
<div className="panel panel-inner text-center p-5 rounded-5 h-100">
<div className="d-flex flex-column opacity-75 h-100 justify-content-center">
<FontAwesomeIcon icon={faWaveform} className="fs-3 mb-3" />
<h5>No voice samples yet</h5>
<p>Uploaded samples will appear here.</p>
</div>
</div>
</div> }
)}
</div>
</div>
</div>;
);
}
export { UploadSamples };
@@ -24,11 +24,13 @@ function VoiceDetails({ datasetInputs }: { datasetInputs: any }) {
const classNames = SearchFieldClass;
return (
<div className="d-flex flex-column gap-4">
{ datasetInputs.map(({ type = "", options = [], ...props }, key: number) => {
if (type === "text") return <Input {...{ ...props, key }} />;
else return <Select {...{ ...props, classNames, key, options } }/>;
}) }
<div>
{datasetInputs.map(
({ type = "", options = [], ...props }, key: number) => {
if (type === "text") return <Input {...{ ...props, key }} />;
else return <Select {...{ ...props, classNames, key, options }} />;
}
)}
</div>
);
}