@shopify/cli-kit
Version:
A set of utilities, interfaces, and models that are common across all the platform features
37 lines • 1.23 kB
JavaScript
import { LoadingBar } from './LoadingBar.js';
import { handleCtrlC } from '../../ui.js';
import React, { useEffect, useState } from 'react';
import { useApp, useInput, useStdin } from 'ink';
const SingleTask = ({ task, title, onComplete, onAbort, noColor }) => {
const [status, setStatus] = useState(title);
const [isDone, setIsDone] = useState(false);
const { exit: unmountInk } = useApp();
const { isRawModeSupported } = useStdin();
useInput((input, key) => {
if (onAbort) {
handleCtrlC(input, key, onAbort);
}
else {
handleCtrlC(input, key);
}
}, { isActive: Boolean(isRawModeSupported) });
useEffect(() => {
task(setStatus)
.then((result) => {
setIsDone(true);
onComplete?.(result);
unmountInk();
})
.catch((error) => {
setIsDone(true);
unmountInk(error);
});
}, [task, unmountInk, onComplete]);
if (isDone) {
// clear things once done
return null;
}
return React.createElement(LoadingBar, { title: status.value, noColor: noColor });
};
export { SingleTask };
//# sourceMappingURL=SingleTask.js.map