|
1 | | -// import { useEffect } from 'react'; |
2 | | -// import { runsActions } from '../../../../../redux/actions'; |
| 1 | +import { useEffect, useState } from 'react'; |
| 2 | +import { runsActions } from '../../../../../redux/actions'; |
3 | 3 | import { |
4 | 4 | runSelectors, |
5 | 5 | runPagesSelectors, |
6 | | - // workspaceSelectors, |
| 6 | + workspaceSelectors, |
7 | 7 | } from '../../../../../redux/selectors'; |
8 | | -import { useSelector } from '../../../../hooks'; |
| 8 | +import { useDispatch, useSelector } from '../../../../hooks'; |
9 | 9 | import { Run } from '../../../../../api/types'; |
10 | 10 |
|
11 | 11 | interface ServiceInterface { |
@@ -33,30 +33,37 @@ export const useService = ({ |
33 | 33 | }[]; |
34 | 34 | }): ServiceInterface => { |
35 | 35 | const fetching = useSelector(runPagesSelectors.fetching); |
36 | | - // const dispatch = useDispatch(); |
| 36 | + const dispatch = useDispatch(); |
37 | 37 | const runs = useSelector(runSelectors.myRuns); |
38 | | - // const selectedWorkspace = useSelector(workspaceSelectors.selectedWorkspace); |
| 38 | + const selectedWorkspace = useSelector(workspaceSelectors.selectedWorkspace); |
39 | 39 | const runsPaginated = useSelector(runSelectors.myRunsPaginated); |
40 | | - // const isValidFilter = filter?.map((f) => f.value).join(''); |
| 40 | + const isValidFilter = filter?.map((f) => f.value).join(''); |
| 41 | + const [pending, setPending] = useState(false); |
| 42 | + useEffect(() => { |
| 43 | + if (!isValidFilter && !isExpended && !pending) { |
| 44 | + const intervalId = setInterval(() => { |
| 45 | + setPending(true); |
| 46 | + //assign interval to a variable to clear it. |
| 47 | + dispatch( |
| 48 | + runsActions.allRuns({ |
| 49 | + sort_by: sortBy, |
| 50 | + logical_operator: 'and', |
| 51 | + workspace: selectedWorkspace, |
| 52 | + page: runsPaginated.page, |
| 53 | + size: runsPaginated.size, |
| 54 | + onSuccess: () => { |
| 55 | + setPending(false); |
| 56 | + }, |
| 57 | + onFailure: () => { |
| 58 | + setPending(false); |
| 59 | + }, |
| 60 | + }), |
| 61 | + ); |
| 62 | + }, 5000); |
41 | 63 |
|
42 | | - // useEffect(() => { |
43 | | - // if (!isValidFilter && !isExpended) { |
44 | | - // const intervalId = setInterval(() => { |
45 | | - // //assign interval to a variable to clear it. |
46 | | - // dispatch( |
47 | | - // runsActions.allRuns({ |
48 | | - // sort_by: sortBy, |
49 | | - // logical_operator: 'and', |
50 | | - // workspace: selectedWorkspace, |
51 | | - // page: runsPaginated.page, |
52 | | - // size: runsPaginated.size, |
53 | | - // }), |
54 | | - // ); |
55 | | - // }, 5000); |
56 | | - |
57 | | - // return () => clearInterval(intervalId); //This is important |
58 | | - // } |
59 | | - // }); |
| 64 | + return () => clearInterval(intervalId); //This is important |
| 65 | + } |
| 66 | + }); |
60 | 67 | const runIds = runs.map((run: Run) => run.id); |
61 | 68 |
|
62 | 69 | return { |
|
0 commit comments