-
Notifications
You must be signed in to change notification settings - Fork 74
/
useJobsAll.ts
41 lines (33 loc) · 1.01 KB
/
useJobsAll.ts
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
30
31
32
33
34
35
36
37
38
39
40
41
import React, { useEffect, useState } from "react";
import { useGet } from "use-http";
import TeamContext from "../../contexts/Teams";
type Jobs = object;
type useJobsAll = [Jobs | undefined, Error | undefined];
const useJobsAll = (openKillWarn?: boolean,openApproveWan?: boolean): useJobsAll => {
const [jobsAll, setJobsAll] = useState<Jobs>();
const { selectedTeam } = React.useContext(TeamContext);
const params = new URLSearchParams({
user:'all',
limit:'100'
});
const { data, error, get } = useGet<Jobs>('/api');
useEffect(() => {
if (data == null) return;
setJobsAll(data);
const timeout = setTimeout(() => {
get(`/teams/${selectedTeam}/jobs?${params}`);
}, 3000);
return () => {
clearTimeout(timeout);
}
}, [data]);
useEffect(() => {
setJobsAll(undefined);
get(`/teams/${selectedTeam}/jobs?${params}`);
}, [selectedTeam, get]);
if (jobsAll !== undefined) {
return [jobsAll, undefined];
}
return [undefined, error];
}
export default useJobsAll;