From 793cd2cabd601d882ab0eb5428ad67cb58cdf4ee Mon Sep 17 00:00:00 2001 From: Cesar Date: Tue, 20 Feb 2024 16:37:18 +0100 Subject: [PATCH 1/6] rollback: progress bar init --- web/components/RealtimeLogs.tsx | 8 ++---- web/components/TimeRemaining.tsx | 2 +- web/hooks/useProgressTime.ts | 46 +++++++++++--------------------- web/utils/logs.ts | 8 +++--- 4 files changed, 22 insertions(+), 42 deletions(-) diff --git a/web/components/RealtimeLogs.tsx b/web/components/RealtimeLogs.tsx index 4d7be4f..56df573 100644 --- a/web/components/RealtimeLogs.tsx +++ b/web/components/RealtimeLogs.tsx @@ -51,8 +51,7 @@ export default function RealtimeLogs(props: { }); const progressInformation = useProgressTime( Object.values(STEP_TIME_ESTS), - sortedLogsWithSteps, - props.run.prompt + sortedLogsWithSteps ); const supabase = createSupabaseBrowserClient( @@ -78,10 +77,7 @@ export default function RealtimeLogs(props: { return; } - if ( - payload.new.step_name === "SYNTHESIZE_RESULTS" && - payload.new.status === "COMPLETED" - ) { + if (payload.new.status === "COMPLETED") { router.refresh(); } } diff --git a/web/components/TimeRemaining.tsx b/web/components/TimeRemaining.tsx index 363fff7..3e57ce4 100644 --- a/web/components/TimeRemaining.tsx +++ b/web/components/TimeRemaining.tsx @@ -16,7 +16,7 @@ function formatTime(seconds: number) { const roundedSeconds = Math.round(seconds); const minutes = Math.floor(roundedSeconds / 60); const secs = roundedSeconds % 60; - const timeRemaining = seconds ? `${minutes}:${secs.toString().padStart(2, "0")}` : "1:40" + const timeRemaining = seconds ? `${minutes}:${secs.toString().padStart(2, "0")}` : "1:10" return `Estimated time: ~${timeRemaining}` } diff --git a/web/hooks/useProgressTime.ts b/web/hooks/useProgressTime.ts index 9e4c5b5..643941d 100644 --- a/web/hooks/useProgressTime.ts +++ b/web/hooks/useProgressTime.ts @@ -1,11 +1,9 @@ import { Tables } from "@/supabase/dbTypes"; -import { COMPLETED_TEXTS } from "@/utils/logs"; import { useState, useEffect } from "react"; export function useProgressTime( stepTimes: number[], - logs: Array>, - prompt: string, + logs: Array> ) { const [startTime] = useState(Date.now()); const [progressInformation, setProgressInformation] = useState({ @@ -20,44 +18,28 @@ export function useProgressTime( const intervalId = setInterval(function () { const now = Date.now(); - const secondsFromStart = (now - startTime) / 1000; // Convert ms to seconds let currentStep = progressInformation.logs.findIndex( (x) => x.status === "IN_PROGRESS" ); + + if (currentStep === -1) { + return; + } + const elapsedTimeInSteps = stepTimes .slice(0, currentStep + 1) .reduce((a, b) => a + b, 0); - const timeRemaining = Math.max(totalTime - secondsFromStart, 0); - - const progress = (secondsFromStart / totalTime) * 100; - if (timeRemaining <= 1) { - clearInterval(intervalId); + const secondsFromStart = (now - startTime) / 1000; // Convert ms to seconds + if (secondsFromStart > elapsedTimeInSteps) { return; } - if ( - secondsFromStart > elapsedTimeInSteps && - stepTimes.length > currentStep && - currentStep !== -1 - ) { - setProgressInformation(({ logs }) => { - const newLogs = [...logs]; - newLogs[currentStep].status = "COMPLETED"; - newLogs[currentStep].value = COMPLETED_TEXTS[newLogs[currentStep].step_name] - if (currentStep === 0) { - newLogs[currentStep].value += " to " + prompt - } + const timeRemaining = Math.max(totalTime - secondsFromStart, 0); + const progress = (secondsFromStart / totalTime) * 100; - if (stepTimes.length > currentStep + 1) { - newLogs[currentStep + 1].status = "IN_PROGRESS"; - } - return { - time: timeRemaining, - progress: progress, - logs: newLogs, - }; - }); + if (timeRemaining <= 1) { + clearInterval(intervalId); return; } @@ -66,9 +48,11 @@ export function useProgressTime( time: timeRemaining, progress: progress, })); + + console.log(currentStep); }, 1000); return () => clearInterval(intervalId); - }, [stepTimes]); + }, [stepTimes, progressInformation]); return progressInformation; } diff --git a/web/utils/logs.ts b/web/utils/logs.ts index bc30b1c..1ca4e01 100644 --- a/web/utils/logs.ts +++ b/web/utils/logs.ts @@ -48,8 +48,8 @@ export const STEPS_ORDER: Record = { } export const STEP_TIME_ESTS: Record = { - FETCH_PROJECTS: 30, - EVALUATE_PROJECTS: 30, - ANALYZE_FUNDING: 30, - SYNTHESIZE_RESULTS: 10 + FETCH_PROJECTS: 35, + EVALUATE_PROJECTS: 15, + ANALYZE_FUNDING: 5, + SYNTHESIZE_RESULTS: 15 } \ No newline at end of file From debee0050cada46496b63df1ea3979ffe7b736fc Mon Sep 17 00:00:00 2001 From: nerfZael Date: Tue, 20 Feb 2024 18:31:38 +0100 Subject: [PATCH 2/6] error fixing --- web/components/Button.tsx | 1 + web/components/Strategy.tsx | 2 +- web/components/StrategyTable.tsx | 14 ++++++++++--- web/hooks/useDonation.ts | 34 ++++++++++++++++++++------------ 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/web/components/Button.tsx b/web/components/Button.tsx index 62feeee..37857f5 100644 --- a/web/components/Button.tsx +++ b/web/components/Button.tsx @@ -42,6 +42,7 @@ const Button = ({ return (