feat: add functionality to fetch and display ongoing extractions with toast notifications
This commit is contained in:
@@ -17,6 +17,7 @@ import {
|
|||||||
soundEvents,
|
soundEvents,
|
||||||
userEvents,
|
userEvents,
|
||||||
} from '../lib/events'
|
} from '../lib/events'
|
||||||
|
import { extractionsService } from '../lib/api/services/extractions'
|
||||||
import { useAuth } from './AuthContext'
|
import { useAuth } from './AuthContext'
|
||||||
|
|
||||||
interface SocketContextType {
|
interface SocketContextType {
|
||||||
@@ -39,6 +40,22 @@ export function SocketProvider({ children }: SocketProviderProps) {
|
|||||||
const [connectionError, setConnectionError] = useState<string | null>(null)
|
const [connectionError, setConnectionError] = useState<string | null>(null)
|
||||||
const [isReconnecting, setIsReconnecting] = useState(false)
|
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(() => {
|
const createSocket = useCallback(() => {
|
||||||
if (!user) return null
|
if (!user) return null
|
||||||
|
|
||||||
@@ -59,6 +76,9 @@ export function SocketProvider({ children }: SocketProviderProps) {
|
|||||||
setIsConnected(true)
|
setIsConnected(true)
|
||||||
setConnectionError(null)
|
setConnectionError(null)
|
||||||
setIsReconnecting(false)
|
setIsReconnecting(false)
|
||||||
|
|
||||||
|
// Fetch and show any ongoing extractions
|
||||||
|
fetchAndShowOngoingExtractions()
|
||||||
})
|
})
|
||||||
|
|
||||||
newSocket.on('disconnect', () => {
|
newSocket.on('disconnect', () => {
|
||||||
@@ -131,7 +151,7 @@ export function SocketProvider({ children }: SocketProviderProps) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return newSocket
|
return newSocket
|
||||||
}, [user])
|
}, [user, fetchAndShowOngoingExtractions])
|
||||||
|
|
||||||
// Handle token refresh - reconnect socket with new token
|
// Handle token refresh - reconnect socket with new token
|
||||||
const handleTokenRefresh = useCallback(() => {
|
const handleTokenRefresh = useCallback(() => {
|
||||||
|
|||||||
@@ -125,6 +125,16 @@ export class ExtractionsService {
|
|||||||
const response = await apiClient.get<GetExtractionsResponse>(url)
|
const response = await apiClient.get<GetExtractionsResponse>(url)
|
||||||
return response
|
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()
|
export const extractionsService = new ExtractionsService()
|
||||||
|
|||||||
Reference in New Issue
Block a user