Skip to content

Latest commit

 

History

History
312 lines (252 loc) · 9.02 KB

File metadata and controls

312 lines (252 loc) · 9.02 KB

Better Progress Bar for Sync and Async Processing

Overview

Created a new, simplified progress bar component that works reliably for both synchronous and asynchronous processing modes.

The Problem

The previous progress system had several issues:

  1. AsyncTaskProgress - Showed static progress (queued=10%, processing=50%) without real-time updates
  2. UnifiedProgress - Complex component that was overkill for this use case
  3. No mode detection - Couldn't distinguish between sync (fast) and async (slow) processing
  4. Inconsistent updates - Progress didn't animate smoothly

The Solution: SimpleProgress Component

Created a new lightweight component (SimpleProgress.vue) with these features:

✅ Key Features

  1. Smooth Progress Animation

    • Animates progress changes over 500ms for visual smoothness
    • Prevents jarring jumps in progress percentage
    • Uses CSS transitions for buttery smooth movement
  2. Dual Mode Support

    • Sync Mode: Fast processing (usually < 10 seconds)
    • Async Mode: Longer processing with queue management
    • Automatically detects which mode based on metadata
  3. Real-time Backend Updates

    • Watches globalProgress store for changes
    • Updates immediately when backend sends new progress
    • Counts number of progress updates received
  4. Smart Completion Detection

    • Recognizes when progress reaches 100%
    • Shows success state with checkmark
    • Auto-hides after 2 seconds on completion
  5. Error Handling

    • Displays error messages clearly
    • Shows warning icon for failed processing
    • Stops timers appropriately on error
  6. Processing Stats

    • Elapsed Time: Shows real-time elapsed duration
    • Processing Mode: Displays "Sync Mode" or "Async Mode"
    • Update Count: Shows how many progress updates received

🎨 Visual Design

┌─────────────────────────────────────────────────┐
│ [SPINNER]  Processing Content                   │
│            Extracting citations...              │
├─────────────────────────────────────────────────┤
│ ████████████████░░░░░░░░  45%                  │
├─────────────────────────────────────────────────┤
│ 🕐 12s    💻 Sync Mode    Updates: 8           │
└─────────────────────────────────────────────────┘

Implementation Details

Component Structure

File: casestrainer-vue-new/src/components/SimpleProgress.vue

<template>
  <div v-if="isProcessing" class="simple-progress-container">
    <!-- Header with icon (spinner/checkmark/error) -->
    <!-- Progress bar with smooth animation -->
    <!-- Stats row with elapsed time and mode -->
  </div>
</template>

Key Functions

1. Smooth Progress Animation

const animateProgress = (targetPercent) => {
  const startPercent = displayPercent.value
  const diff = targetPercent - startPercent
  
  // Animate over 500ms in 10 steps
  const steps = 10
  const increment = diff / steps
  
  smoothProgressTimer = setInterval(() => {
    displayPercent.value += increment
  }, 50)
}

2. Progress State Watcher

watch(() => globalProgress.progressState, (newState) => {
  // Extract progress percentage
  const newPercent = newState.totalProgress || 0
  
  // Animate to new value
  animateProgress(newPercent)
  
  // Update message
  currentMessage.value = newState.currentStep
  
  // Check for completion
  if (newPercent >= 100) {
    isComplete.value = true
    // Auto-hide after 2 seconds
  }
}, { deep: true, immediate: true })

3. Processing Mode Detection

onMounted(() => {
  // Extract mode from metadata
  const metadata = globalProgress.progressState.metadata || {}
  processingMode.value = metadata.processing_mode || ''
  // Shows "sync" or "async"
})

Integration with HomeView

File: casestrainer-vue-new/src/views/HomeView.vue

1. Import the Component

import SimpleProgress from '@/components/SimpleProgress.vue'

2. Add to Template

<!-- Real-time Progress Display - Works for both sync and async -->
<SimpleProgress component-id="home" />

3. Set Processing Mode Metadata

// At start of processing
globalProgress.progressState.metadata = {
  processing_mode: 'sync',
  input_type: activeTab.value
}

// If async detected
if (processingMode === 'queued' && jobId) {
  globalProgress.progressState.metadata = {
    processing_mode: 'async',
    input_type: activeTab.value,
    job_id: jobId
  }
}

Progress Flow

Sync Processing (Text/Small Files)

User submits → Analyze starts
  ↓
globalProgress initialized (mode: 'sync')
  ↓
SimpleProgress appears with spinner
  ↓
Backend polling: /processing_progress?request_id=...
  ↓
Progress updates: 0% → 25% → 50% → 75% → 100%
  ↓
SimpleProgress animates smoothly
  ↓
Completion: Shows checkmark, hides after 2s

Async Processing (Large Files/URLs)

User submits → Server queues job
  ↓
globalProgress initialized (mode: 'sync')
  ↓
Response includes job_id → Switch to 'async' mode
  ↓
SimpleProgress shows "Async Mode"
  ↓
Backend polling: /task_status/{job_id}
  ↓
Progress updates: 10% → 20% → ... → 100%
  ↓
SimpleProgress animates smoothly
  ↓
Completion: Shows checkmark, hides after 2s

Benefits

1. Simplicity

  • Single component handles both modes
  • Less code to maintain
  • Easier to debug

2. Reliability

  • Direct connection to globalProgress store
  • No complex state management
  • Fewer edge cases

3. Performance

  • Smooth CSS animations
  • Efficient reactivity
  • Minimal re-renders

4. User Experience

  • Clear visual feedback
  • Mode indicator (sync/async)
  • Processing stats
  • Smooth progress animation
  • Auto-hiding on completion

Testing

Test Sync Mode (Fast)

  1. Go to home page
  2. Paste a small text (< 2KB)
  3. Click "Analyze Content"
  4. Expected:
    • Progress bar appears immediately
    • Shows "Sync Mode"
    • Animates 0% → 100% in 5-10 seconds
    • Shows checkmark and hides

Test Async Mode (Slow)

  1. Go to home page
  2. Submit a large PDF URL
  3. Click "Analyze Content"
  4. Expected:
    • Progress bar shows "Queued" initially
    • Switches to "Async Mode"
    • Animates over 30-60 seconds
    • Shows real progress from backend
    • Completes at 100%

Comparison: Before vs After

Feature Old (AsyncTaskProgress) New (SimpleProgress)
Progress Type Static (10%, 50%, 100%) Real-time from backend
Animation None Smooth 500ms transitions
Mode Display No Yes (Sync/Async)
Stats Task ID only Elapsed time, mode, updates
Auto-hide No Yes (2s after completion)
Error Display Basic Clear with icon
Code Lines ~385 lines ~350 lines (simpler)

Files Modified

New Files

  1. casestrainer-vue-new/src/components/SimpleProgress.vue (NEW)
    • Complete progress bar component
    • ~350 lines with full styling

Modified Files

  1. casestrainer-vue-new/src/views/HomeView.vue

    • Import SimpleProgress (line 455)
    • Use SimpleProgress component (lines 403-406)
    • Set metadata for mode detection (lines 1278-1281, 1384-1388)
  2. BETTER_PROGRESS_BAR.md (NEW - this file)

    • Complete documentation

Deployment

Frontend rebuilt - Ready to deploy

To Deploy

cd d:\dev\casestrainer
./cslaunch

To Test

  1. Navigate to home page
  2. Try both sync (paste text) and async (submit URL) processing
  3. Watch progress bar animate smoothly
  4. Verify mode indicator shows correct mode
  5. Check that progress stops at 100% and auto-hides

Future Enhancements

Potential Improvements

  1. Pause/Resume: Add ability to pause long-running tasks
  2. Cancel Button: Allow users to cancel processing
  3. Progress History: Show list of recent processing jobs
  4. Estimated Completion: Calculate ETA based on current progress
  5. Multi-task Display: Show multiple jobs in parallel
  6. Sound Notifications: Play sound when processing completes

Summary

Created SimpleProgress component - Works for both sync and async
Smooth animations - 500ms transitions for visual polish
Mode detection - Shows "Sync Mode" or "Async Mode"
Real-time updates - Connected to backend progress
Processing stats - Elapsed time, update count
Auto-completion - Hides 2s after reaching 100%
Error handling - Clear error display
Frontend rebuilt - Ready to test

The new progress bar provides a much better user experience with clear feedback for both fast (sync) and slow (async) processing!