Fix initial errors in calculate metrics and get progress working in frontend

This commit is contained in:
2025-01-12 14:12:18 -05:00
parent 3e855eeb2b
commit ac8563325a
3 changed files with 148 additions and 67 deletions

View File

@@ -254,8 +254,8 @@ export function Settings() {
}
// Handle completion
if (progressData.status === 'complete') {
console.log(`Operation ${type} completed`);
if (progressData.status === 'complete' || progressData.status === 'cancelled') {
console.log(`Operation ${type} completed or cancelled`);
// For import, only close connection when both operations are complete
if (type === 'import') {
@@ -433,11 +433,14 @@ export function Settings() {
}, [eventSource]);
const handleCancel = async () => {
// Determine which operation is running first
const operation = isImporting ? 'Import' : isUpdating ? 'Update' : 'Reset';
// Determine which operation is running
const operation = isImporting ? 'import' :
isUpdating ? 'update' :
isResetting ? 'reset' :
isCalculatingMetrics ? 'calculate-metrics' : 'reset';
// Show cancellation toast immediately
toast.warning(`${operation} cancelled`);
toast.warning(`${operation.charAt(0).toUpperCase() + operation.slice(1)} cancelled`);
// Clean up everything immediately
if (eventSource) {
@@ -447,13 +450,15 @@ export function Settings() {
setIsUpdating(false);
setIsImporting(false);
setIsResetting(false);
setIsCalculatingMetrics(false);
setUpdateProgress(null);
setImportProgress(null);
setResetProgress(null);
setMetricsProgress(null);
// Fire and forget the cancel request with the operation type
try {
await fetch(`${config.apiUrl}/csv/cancel?operation=${operation.toLowerCase()}`, {
await fetch(`${config.apiUrl}/csv/cancel?operation=${operation}`, {
method: 'POST',
credentials: 'include'
});