feat: add functionality to fetch and display ongoing extractions with toast notifications
This commit is contained in:
@@ -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(() => {
|
||||
|
||||
Reference in New Issue
Block a user