Skip to content

Commit

Permalink
Merge pull request #356 from amplimindcc/355-fix-sse-throws-error-on-…
Browse files Browse the repository at this point in the history
…timeout

recursively reconnect SSE on timeout and clear on leaving page
  • Loading branch information
cwsyth authored Jun 11, 2024
2 parents 81457d1 + 237ed5f commit 4ed0057
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/pages/Admin/components/Submissions/Submissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ export default function Submissions() {
const [rowData, setRowData] = useState<UserSubmissionTableElement[]>([]);

useEffect(() => {
/**
* connect SSE to the backend to get the submission status changes in real time and update the table accordingly
* @author Timo Hauser
* @author David Linhardt
*
* @async
* @returns {void}
*/
const connect = async () => {
try {
const res = await submission.heartbeat();
Expand All @@ -97,15 +105,19 @@ export default function Submissions() {
}
}
);
sse.onerror = (event) => {
toast.showToast(ToastType.ERROR, t('sseError', { event: event}));
sse.onerror = () => {
connect();
};
}
} catch (e: unknown) {
toast.showToast(ToastType.ERROR, t('connectionError', { ns: 'main' }));
}
};
connect();

return () => {
// clean up
};
});

/**
Expand Down

0 comments on commit 4ed0057

Please sign in to comment.