Merge pull request #49 from sartography/feature/refresh-my-tasks
add simple refresh capability
This commit is contained in:
commit
1002ff376c
|
@ -197,3 +197,16 @@ export const getGroupFromModifiedModelId = (modifiedId: string) => {
|
||||||
export const splitProcessModelId = (processModelId: string) => {
|
export const splitProcessModelId = (processModelId: string) => {
|
||||||
return processModelId.split('/');
|
return processModelId.split('/');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const refreshAtInterval = (
|
||||||
|
interval: number,
|
||||||
|
timeout: number,
|
||||||
|
func: Function
|
||||||
|
) => {
|
||||||
|
const intervalRef = setInterval(() => func(), interval * 1000);
|
||||||
|
const timeoutRef = setTimeout(
|
||||||
|
() => clearInterval(intervalRef),
|
||||||
|
timeout * 1000
|
||||||
|
);
|
||||||
|
return [intervalRef, timeoutRef];
|
||||||
|
};
|
||||||
|
|
|
@ -6,11 +6,14 @@ import PaginationForTable from '../components/PaginationForTable';
|
||||||
import {
|
import {
|
||||||
getPageInfoFromSearchParams,
|
getPageInfoFromSearchParams,
|
||||||
modifyProcessModelPath,
|
modifyProcessModelPath,
|
||||||
|
refreshAtInterval,
|
||||||
} from '../helpers';
|
} from '../helpers';
|
||||||
import HttpService from '../services/HttpService';
|
import HttpService from '../services/HttpService';
|
||||||
import { PaginationObject, RecentProcessModel } from '../interfaces';
|
import { PaginationObject, RecentProcessModel } from '../interfaces';
|
||||||
|
|
||||||
const PER_PAGE_FOR_TASKS_ON_HOME_PAGE = 5;
|
const PER_PAGE_FOR_TASKS_ON_HOME_PAGE = 5;
|
||||||
|
const REFRESH_INTERVAL = 10;
|
||||||
|
const REFRESH_TIMEOUT = 600;
|
||||||
|
|
||||||
export default function MyTasks() {
|
export default function MyTasks() {
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
|
@ -18,18 +21,23 @@ export default function MyTasks() {
|
||||||
const [pagination, setPagination] = useState<PaginationObject | null>(null);
|
const [pagination, setPagination] = useState<PaginationObject | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const { page, perPage } = getPageInfoFromSearchParams(
|
const getTasks = () => {
|
||||||
searchParams,
|
const { page, perPage } = getPageInfoFromSearchParams(
|
||||||
PER_PAGE_FOR_TASKS_ON_HOME_PAGE
|
searchParams,
|
||||||
);
|
PER_PAGE_FOR_TASKS_ON_HOME_PAGE
|
||||||
const setTasksFromResult = (result: any) => {
|
);
|
||||||
setTasks(result.results);
|
const setTasksFromResult = (result: any) => {
|
||||||
setPagination(result.pagination);
|
setTasks(result.results);
|
||||||
|
setPagination(result.pagination);
|
||||||
|
};
|
||||||
|
HttpService.makeCallToBackend({
|
||||||
|
path: `/tasks?per_page=${perPage}&page=${page}`,
|
||||||
|
successCallback: setTasksFromResult,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
HttpService.makeCallToBackend({
|
|
||||||
path: `/tasks?per_page=${perPage}&page=${page}`,
|
getTasks();
|
||||||
successCallback: setTasksFromResult,
|
refreshAtInterval(REFRESH_INTERVAL, REFRESH_TIMEOUT, getTasks);
|
||||||
});
|
|
||||||
}, [searchParams]);
|
}, [searchParams]);
|
||||||
|
|
||||||
let recentProcessModels: RecentProcessModel[] = [];
|
let recentProcessModels: RecentProcessModel[] = [];
|
||||||
|
|
Loading…
Reference in New Issue