@@ -6,7 +6,7 @@ import { AssignmentLanguage, Solution } from "@/service/types/tasky";
66import CentralLoading from "@/components/CentralLoading" ;
77import JobResultDisplay from "@/components/JobResultDisplay" ;
88import useCurrentUser from "@/hooks/useCurrentUser" ;
9- import { useState } from "react" ;
9+ import { useEffect , useState } from "react" ;
1010import { isGranted } from "@/service/auth" ;
1111import { UserRoles } from "@/service/types/usernator" ;
1212import ExecutorUIDisplay from "@/components/solution/ExecutorUIDisplay" ;
@@ -15,6 +15,9 @@ import NavigateBack from "@/components/NavigateBack";
1515import FileStructureDisplay from "@/components/FileStructureDisplay" ;
1616import QuestionAnswersDisplay from "@/components/solution/questions/QuestionAnswersDisplay" ;
1717
18+ // Every 30s
19+ const REFETCH_INTERVAL = 1000 * 30 ;
20+
1821const 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