Spaces:
Paused
Paused
Download ui/src/hooks/useJob.tsx from StaticExposure/ai-toolkit: direct link, hf CLI and curl.
- Browser
- Download file 1.04 kB
-
https://huggingface.co/spaces/StaticExposure/ai-toolkit/resolve/main/ui/src/hooks/useJob.tsx
- Command line
-
hf download hf://spaces/StaticExposure/ai-toolkit/ui/src/hooks/useJob.tsx
-
curl -L -o useJob.tsx https://huggingface.co/spaces/StaticExposure/ai-toolkit/resolve/main/ui/src/hooks/useJob.tsx
1.04 kB
| 'use client'; | |
| import { useEffect, useState } from 'react'; | |
| import { Job } from '@prisma/client'; | |
| import { apiClient } from '@/utils/api'; | |
| export default function useJob(jobID: string, reloadInterval: null | number = null) { | |
| const [job, setJob] = useState<Job | null>(null); | |
| const [status, setStatus] = useState<'idle' | 'loading' | 'success' | 'error'>('idle'); | |
| const refreshJob = () => { | |
| setStatus('loading'); | |
| apiClient | |
| .get(`/api/jobs?id=${jobID}`) | |
| .then(res => res.data) | |
| .then(data => { | |
| console.log('Job:', data); | |
| setJob(data); | |
| setStatus('success'); | |
| }) | |
| .catch(error => { | |
| console.error('Error fetching datasets:', error); | |
| setStatus('error'); | |
| }); | |
| }; | |
| useEffect(() => { | |
| refreshJob(); | |
| if (reloadInterval) { | |
| const interval = setInterval(() => { | |
| refreshJob(); | |
| }, reloadInterval); | |
| return () => { | |
| clearInterval(interval); | |
| }; | |
| } | |
| }, [jobID]); | |
| return { job, setJob, status, refreshJob }; | |
| } | |