Skip to content

Commit

Permalink
keep track of previous job
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Einars <contact@dle.dev>
  • Loading branch information
polaroidkidd committed Aug 6, 2022
1 parent 84c4ff4 commit a4343a4
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/hooks/useWorkerStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,19 @@ export function useWorkerStatus(): {
const user = useAppSelector(selectUserSelfDetails);
const { data: currentData } = useWorkerQuery(null, { pollingInterval: 2000 });

const [previousJob, setPreviousJob] = useState(currentData);

useEffect(() => {
if (currentData?.job_detail?.job_id !== previousJob?.job_detail?.job_id) {
setPreviousJob(currentData);
}
}, [currentData, previousJob?.job_detail?.job_id]);

useEffect(() => {
if (hadPreviousJob && workerRunningJob !== undefined && currentData?.job_detail === null) {
showNotification({
message: t("toasts.jobfinished", {
job: workerRunningJob?.job_type_str,
job: previousJob?.job_detail?.job_type_str,
}),
title: workerRunningJob?.job_type_str,
color: "teal",
Expand Down Expand Up @@ -56,7 +64,16 @@ export function useWorkerStatus(): {
} else {
dispatch({ type: FacesActions.SET_WORKER_AVAILABILITY, payload: true });
}
}, [currentData, dispatch, hadPreviousJob, t, user.id, user.username, workerRunningJob]);
}, [
currentData,
dispatch,
hadPreviousJob,
previousJob?.job_detail?.job_type_str,
t,
user.id,
user.username,
workerRunningJob,
]);

useEffect(() => {
if (workerRunningJob) {
Expand Down

0 comments on commit a4343a4

Please sign in to comment.