feat: add functionality to fetch and display ongoing extractions with toast notifications

This commit is contained in:
JSC
2025-08-24 13:43:52 +02:00
parent b1eb5c4ab2
commit e029a692a6
2 changed files with 31 additions and 1 deletions

View File

@@ -17,6 +17,7 @@ import {
soundEvents,
userEvents,
} from '../lib/events'
import { extractionsService } from '../lib/api/services/extractions'
import { useAuth } from './AuthContext'
interface SocketContextType {
@@ -39,6 +40,22 @@ export function SocketProvider({ children }: SocketProviderProps) {
const [connectionError, setConnectionError] = useState<string | null>(null)
const [isReconnecting, setIsReconnecting] = useState(false)
const fetchAndShowOngoingExtractions = useCallback(async () => {
try {
const processingExtractions = await extractionsService.getProcessingExtractions()
processingExtractions.forEach(extraction => {
const title = extraction.title || 'Processing extraction...'
toast.loading(`Extracting: ${title}`, {
id: `extraction-${extraction.id}`,
duration: Infinity, // Keep it open until status changes
})
})
} catch (error) {
console.error('Failed to fetch ongoing extractions:', error)
}
}, [])
const createSocket = useCallback(() => {
if (!user) return null
@@ -59,6 +76,9 @@ export function SocketProvider({ children }: SocketProviderProps) {
setIsConnected(true)
setConnectionError(null)
setIsReconnecting(false)
// Fetch and show any ongoing extractions
fetchAndShowOngoingExtractions()
})
newSocket.on('disconnect', () => {
@@ -131,7 +151,7 @@ export function SocketProvider({ children }: SocketProviderProps) {
})
return newSocket
}, [user])
}, [user, fetchAndShowOngoingExtractions])
// Handle token refresh - reconnect socket with new token
const handleTokenRefresh = useCallback(() => {

View File

@@ -125,6 +125,16 @@ export class ExtractionsService {
const response = await apiClient.get<GetExtractionsResponse>(url)
return response
}
/**
* Get currently processing extractions
*/
async getProcessingExtractions(): Promise<ExtractionInfo[]> {
const response = await apiClient.get<ExtractionInfo[]>(
'/api/v1/extractions/processing/current'
)
return response
}
}
export const extractionsService = new ExtractionsService()