Skip to content

Commit

Permalink
feat: poll course reset list
Browse files Browse the repository at this point in the history
  • Loading branch information
hajorg committed Mar 4, 2024
1 parent 0738d4d commit 4dc16cd
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/users/CourseReset.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ function CourseReset({ username, intl }) {
const [courseResetData, setCourseResetData] = useState([]);
const [error, setError] = useState('');
const [isOpen, open, close] = useToggle(false);
const POLLING_INTERVAL = 10000;

useEffect(() => {
// check if there is an enqueued or in progress course reset
const shouldPoll = courseResetData.some((course) => {
const status = course.status.toLowerCase();
return status.includes('in progress') || status.includes('enqueued');
});

let intervalId;
if (shouldPoll) {
intervalId = setInterval(async () => {
const data = await getLearnerCourseResetList(username);
setCourseResetData(data);

Check warning on line 33 in src/users/CourseReset.jsx

View check run for this annotation

Codecov / codecov/patch

src/users/CourseReset.jsx#L32-L33

Added lines #L32 - L33 were not covered by tests
}, POLLING_INTERVAL);
}
return () => clearInterval(intervalId);
}, [courseResetData]);

const handleSubmit = async (courseID) => {
setError(null);
Expand Down

0 comments on commit 4dc16cd

Please sign in to comment.