import { Alert, Box, Progress, Text, VStack } from "@chakra-ui/react"; import { useErrorHandler, useInterval } from "@strata-foundation/react"; import React, { useEffect, useState } from "react"; import { useAsync } from "react-async-hook"; export interface ILongPromiseNotification { onComplete?: (result: T) => void; text: string; estTimeMillis: number; exec: () => Promise; onError: (error: Error) => void; } export function LongPromiseNotification({ onComplete, onError, exec, estTimeMillis, text }: ILongPromiseNotification) { const [time, setTime] = useState(0); const { result, error } = useAsync(exec, []); useEffect(() => { if (onComplete && result) { onComplete(result); } }, [result, onComplete]); useEffect(() => { if (onError && error) { onError(error); } }, [error, onError]); useInterval(() => { setTime(time => time + 100) }, 100); return ( {text} ); };