Skip to content

Commit 5d6a8b3

Browse files
committed
[FEAT] Added refetch interval to solutions page while wating for response
1 parent b84a61f commit 5d6a8b3

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

web/app/solutions/[id]/page.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { AssignmentLanguage, Solution } from "@/service/types/tasky";
66
import CentralLoading from "@/components/CentralLoading";
77
import JobResultDisplay from "@/components/JobResultDisplay";
88
import useCurrentUser from "@/hooks/useCurrentUser";
9-
import { useState } from "react";
9+
import {useEffect, useState} from "react";
1010
import { isGranted } from "@/service/auth";
1111
import { UserRoles } from "@/service/types/usernator";
1212
import ExecutorUIDisplay from "@/components/solution/ExecutorUIDisplay";
@@ -15,6 +15,9 @@ import NavigateBack from "@/components/NavigateBack";
1515
import FileStructureDisplay from "@/components/FileStructureDisplay";
1616
import QuestionAnswersDisplay from "@/components/solution/questions/QuestionAnswersDisplay";
1717

18+
// Every 30s
19+
const REFETCH_INTERVAL = 1000 * 30;
20+
1821
const SolutionDetailsPage = ({ params }: { params: { id: string } }) => {
1922
const id = parseInt(`${params.id}`, 10);
2023
const api = useApiServiceClient();
@@ -23,6 +26,22 @@ const SolutionDetailsPage = ({ params }: { params: { id: string } }) => {
2326
const [solution, refetch] = useClientQuery<Solution>(() =>
2427
api.getSolution(id),
2528
);
29+
30+
useEffect(() => {
31+
const fetcher = async () => {
32+
if (solution?.job && solution.job.execution.length > 0) {
33+
const exec = solution.job.execution[0];
34+
if (exec.error === null && exec.result === null && exec.state === "RUNNING") {
35+
setTimeout(() => {
36+
refetch();
37+
fetcher();
38+
}, REFETCH_INTERVAL);
39+
}
40+
}
41+
};
42+
fetcher();
43+
}, [solution]);
44+
2645
console.log(solution);
2746
const approve = async () => {
2847
await api.approveSolution(id);

0 commit comments

Comments
 (0)