diff --git a/src/front/component/convert.tsx b/src/front/component/convert.tsx index 862f85a..0b0a145 100644 --- a/src/front/component/convert.tsx +++ b/src/front/component/convert.tsx @@ -10,7 +10,9 @@ import { directoryNameFromFileList } from "../../share/file-list-ext"; import { initialProgress, Progress, + ProgressPair, ProgressReducer, + Step, } from "../../share/progress"; import { ConvertMode, @@ -161,6 +163,7 @@ export const Convert: React.FC<{ session.current = null; }; }, []); + const meta = session.current?.meta; return ( <> {!session.current && ( @@ -244,82 +247,21 @@ export const Convert: React.FC<{ )} )} - {session.current && ( + {meta && (
- {session.current.meta.steps.map((step) => { - switch (step) { - case "unzip": - return ( - session.current?.meta && - state.current.unzip && ( - - ) - ); - case "copy": - return ( - session.current?.meta && - state.current.copy && ( - - ) - ); - case "convert": - return ( - session.current?.meta && - state.current.convert && ( - - ) - ); - case "compaction": - return ( - session.current?.meta && - state.current.compaction && ( - - ) - ); - case "extract": - return ( - session.current?.meta && - state.current.extract && ( - - ) - ); - case "postprocess": - return ( - session.current?.meta && - state.current.postprocess && ( - - ) - ); + {meta.steps.map((step, index) => { + const value = progressValue(state.current, meta.steps, index, step); + if (!value) { + return; + } else { + return ( + + ); } })}
@@ -382,3 +324,31 @@ const FileInputGuidance: React.FC<{ mode: ConvertMode }> = ({ mode }) => { ); } }; + +const progressValue = ( + state: State, + steps: Step[], + index: number, + step: Step, +): ProgressPair | undefined => { + const base = state[step]; + if (!base) { + return undefined; + } + if (state.dl && state.error === undefined) { + return { progress: base.count, count: base.count }; + } + if ( + steps.slice(index + 1).some((s) => { + const p = state[s]; + if (p === undefined) { + return false; + } + return p.progress > 0; + }) + ) { + return { progress: base.count, count: base.count }; + } else { + return base; + } +};