All files / src/hooks useSourceTesting.ts

25% Statements 3/12
100% Branches 0/0
50% Functions 1/2
25% Lines 3/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29              1x   1x                                 1x    
import { useState } from 'react'
import { toast } from 'sonner'
import { api, type Source } from '../api/client'
 
export default function useSourceTesting(
  onSourcesChange: (sources: Source[]) => void
) {
  const [testingAll, setTestingAll] = useState(false)
 
  const handleTestAllSources = async () => {
    setTestingAll(true)
    try {
      const result = await api.sources.testAll()
      toast.success(
        `Tested ${result.tested} sources: ${result.passed} passed, ${result.failed} failed`
      )
      const sourcesData = await api.sources.list()
      onSourcesChange(sourcesData)
    } catch (error) {
      console.error('Failed to test all sources:', error)
      toast.error('Failed to test all sources')
    } finally {
      setTestingAll(false)
    }
  }
 
  return { testingAll, handleTestAllSources }
}
 
← Back to Dashboard