added spinner, tab disabled mode, simplified code

This commit is contained in:
wil committed 2024-01-22 16:55:00 -05:00
1 parent e4f54ffa5f
commit fc93dd00c6
6 files changed
+49 -93

No files matched your search

@@ -32,5 +32,10 @@
background-color: transparent;
border-bottom: 4px solid $primary !important;
}
&.disabled{
color: rgba($white, 0.5) !important;
pointer-events: none;
}
}
}
@@ -4,6 +4,7 @@ import { useSpring, a } from "@react-spring/web";
import "./Tabs.scss";
import { IconDefinition } from "@fortawesome/fontawesome-svg-core";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import makeClass from "resources/makeClass";
interface TabProps {
to: string;
@@ -11,10 +12,12 @@ interface TabProps {
content?: React.ReactNode;
icon?: IconDefinition;
padding?: boolean;
disabled?:boolean;
}
interface TabsProps {
tabs: TabProps[];
disabled?: boolean;
}
interface TabContentProps {
@@ -22,12 +25,12 @@ interface TabContentProps {
padding?: boolean;
}
function Tab({ to, label, icon, onClick }: TabProps & { onClick: () => void }) {
function Tab({ to, label, icon, onClick, disabled }: TabProps & { onClick: () => void }) {
return (
<li className="nav-item">
<NavLink
to={to}
className="nav-link fs-6 px-3 px-lg-4"
className={"nav-link fs-6 px-3 px-lg-4" + (disabled?" disabled":"")}
activeClassName="active"
onClick={onClick}
>
@@ -43,7 +46,7 @@ function TabContent({ children, padding }: TabContentProps) {
return <div className={`tab-content ${paddingClasses}`}>{children}</div>;
}
function Tabs({ tabs }: TabsProps) {
function Tabs({ tabs, disabled }: TabsProps) {
const location = useLocation();
const currentPath = location.pathname;
const initialTab = tabs.find(tab => tab.to === currentPath) || tabs[0];
@@ -83,6 +86,7 @@ function Tabs({ tabs }: TabsProps) {
label={tab.label}
onClick={() => handleTabClick(tab.to)}
icon={tab.icon}
disabled={disabled || tab.disabled}
/>
))}
</ul>
@@ -28,35 +28,29 @@ export default function VideoMotionCapture(props: {
const { enqueueInferenceJob } = props;
const { t } = useLocalize("VideoMotionCapture");
enum pageStates {
VIDEO_PROVISION,
START,
VIDEO_PROVISIONING,
SHOW_JOB_STATUS,
}
const { VIDEO_PROVISION, SHOW_JOB_STATUS } = pageStates;
const [pageState, setPageState] = useState<{
index: number;
inputMediaToken: string;
jobToken: string;
resultMediaToken: string;
}>({
index: VIDEO_PROVISION,
inputMediaToken: "",
jobToken: "",
resultMediaToken: "",
});
const { START, VIDEO_PROVISIONING, SHOW_JOB_STATUS } = pageStates;
const [pageState, setPageState] = useState<number>(START);
const handlePageState = ({
tokenType,
nextState,
token,
}: {
tokenType: string;
token: string | undefined;
nextState: number;
token?: string;
}) => {
if (token && tokenType === "jobToken") {
setPageState({
...pageState,
index: SHOW_JOB_STATUS,
jobToken: token,
});
if(nextState===VIDEO_PROVISIONING){
setPageState(VIDEO_PROVISIONING)
}
else if (nextState===SHOW_JOB_STATUS && token) {
enqueueInferenceJob(
token,
FrontendInferenceJobType.VideoMotionCapture
);
setPageState(SHOW_JOB_STATUS);
}
};
@@ -91,14 +85,14 @@ export default function VideoMotionCapture(props: {
<div className="row g-0">
{/*Video Provision Tabs & Job Statuses*/}
<div className="col-12 col-md-6">
{pageState.index === VIDEO_PROVISION && <Tabs tabs={tabs} />}
{pageState.index === SHOW_JOB_STATUS && (
{pageState !== SHOW_JOB_STATUS &&
<Tabs tabs={tabs} disabled={pageState === VIDEO_PROVISIONING}/>
}
{pageState === SHOW_JOB_STATUS && (
<PageInferenceStatuses
{...{
t,
enqueueInferenceJob,
pageStates,
pageState,
pageStateCallback: handlePageState,
}}
/>
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react'
import React from 'react'
import { Analytics } from "common/Analytics";
import InferenceJobsList from "components/layout/InferenceJobsList";
@@ -7,26 +7,9 @@ import { FrontendInferenceJobType } from "@storyteller/components/src/jobs/Infer
export function PageInferenceStatuses (props:{
t: Function,
pageStates: Object,
pageState: {
index:number,
inputMediaToken: string,
jobToken: string,
resultMediaToken: string
},
enqueueInferenceJob: (
jobToken: string,
frontendInferenceJobType: FrontendInferenceJobType
) => void,
pageStateCallback: (data:{tokenType:string, token:string | undefined}) => void
pageStateCallback: (data:{nextState:number, token?:string}) => void
}){
const { t, pageState, enqueueInferenceJob } = props;
useEffect(()=>{
console.log("ENQUEUE INFERENCE JOB>>")
enqueueInferenceJob(
props.pageState.jobToken,
FrontendInferenceJobType.VideoMotionCapture
);
}, [props.pageState.jobToken, enqueueInferenceJob])
const { t } = props;
const failures = (fail = "") => {
switch (fail) {
@@ -38,15 +21,14 @@ export function PageInferenceStatuses (props:{
};
return(
<>
<div className="p3">
<h2>{t("tab.message.mocapNetRequestSucceed")}</h2>
<h4>Job Token: {pageState.jobToken}</h4>
<InferenceJobsList {...{
failures,
onSelect: () => Analytics.voiceConversionClickDownload(),
jobType: FrontendInferenceJobType.VideoMotionCapture,
}}/>
</>
</div>
)
}
@@ -1,39 +0,0 @@
import React from "react";
import TabContentUpload from "./tabContentUpload";
import TabContentLibrary from "./tabContentLibrary";
export function PageVideoProvision (props:{
t: Function
pageStateCallback: (data:{tokenType:string, token:string | undefined}) => void
}){
const {t} = props;
return(<>
<ul className="nav nav-tabs" id="vmcTab">
<li className="nav-item">
<button
className="nav-link active"
id="vmcUploadTab"
data-bs-toggle="tab"
data-bs-target="#vmcUpload"
>
{t("tabTitle.upload")}
</button>
</li>
<li className="nav-item">
<button
disabled
className="nav-link"
id="vmcLibraryTab"
data-bs-toggle="tab"
data-bs-target="#vmcLibrary"
>
{t("tabTitle.library")}
</button>
</li>
</ul>
<div className="tab-content" id="vmcTabContent">
<TabContentUpload {...props}/>
<TabContentLibrary {...props}/>
</div>
</>);
}
@@ -5,13 +5,15 @@ import { UploadMedia } from "@storyteller/components/src/api/media_files/UploadM
import { EnqueueVideoMotionCapture } from "@storyteller/components/src/api/video_mocap";
import { useFile } from "hooks";
import { Spinner } from "components/common";
import VideoInput from "components/common/VideoInput";
export default function TabContentUpload(props: {
t: Function;
pageStateCallback: (data: {
tokenType: string;
token: string | undefined;
nextState: number;
tokenType?: string;
token?: string | undefined;
}) => void;
}) {
const { t, pageStateCallback } = props;
@@ -43,6 +45,11 @@ export default function TabContentUpload(props: {
}
});
};
useEffect(()=>{
if(tabState === FILE_UPLOADING){
pageStateCallback({nextState:1});
}
}, [tabState])
useEffect(() => {
if (token !== "") setTabState(FILE_UPLOADED);
}, [token, FILE_UPLOADED]);
@@ -54,6 +61,7 @@ export default function TabContentUpload(props: {
};
EnqueueVideoMotionCapture(request).then(res => {
pageStateCallback({
nextState: 2,
tokenType: "jobToken",
token: res.inference_job_token,
});
@@ -98,6 +106,7 @@ export default function TabContentUpload(props: {
<div className="row">
<div className="col-12">
<h2>{t("tab.message.fileUploading")}</h2>
<Spinner />
</div>
</div>
</div>
@@ -123,6 +132,7 @@ export default function TabContentUpload(props: {
<div className="row">
<div className="col-12">
<h2>{t("tab.message.mocapNetRequesting")}</h2>
<Spinner />
</div>
</div>
</div>