Skip to content

Commit

Permalink
feature(codaveri-live-feedback): frontend tweaks
Browse files Browse the repository at this point in the history
- tweaked live feedback component styling
- live feedback drawer now closes only when all feedback is deleted
- added toast messages for successful feedback / no feedback generated
  • Loading branch information
adi-herwana-nus committed Jul 4, 2024
1 parent c108b59 commit f981823
Show file tree
Hide file tree
Showing 5 changed files with 232 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,20 +230,38 @@ export function initializeLiveFeedback(questionId) {
});
}

// if status returned 200, populate feedback array if has feedback, otherwise return error
const handleFeedbackOKResponse = (dispatch, response, answerId, questionId) => {
const feedbackFiles = response.data?.data?.feedbackFiles ?? [];
const success = response.data?.success;
if (success && feedbackFiles.length) {
dispatch({
type: actionTypes.LIVE_FEEDBACK_SUCCESS,
payload: {
questionId,
answerId,
feedbackFiles,
},
});
dispatch(setNotification(translations.liveFeedbackSuccess));
} else {
dispatch({
type: actionTypes.LIVE_FEEDBACK_FAILURE,
payload: {
questionId,
},
});
dispatch(setNotification(translations.liveFeedbackNoneGenerated));
}
};

export function generateLiveFeedback(submissionId, answerId, questionId) {
return (dispatch) =>
CourseAPI.assessment.submissions
.generateLiveFeedback(submissionId, { answer_id: answerId })
.then((response) => {
if (response.status === 200) {
dispatch({
type: actionTypes.LIVE_FEEDBACK_SUCCESS,
payload: {
questionId,
answerId,
feedbackFiles: response.data?.data?.feedbackFiles ?? {},
},
});
handleFeedbackOKResponse(dispatch, response, answerId, questionId);
} else {
// 201, save feedback signed token
dispatch({
Expand All @@ -267,7 +285,6 @@ export function generateLiveFeedback(submissionId, answerId, questionId) {
});
}

// TODO should each answer/question store its own feedback array?
export function fetchLiveFeedback(
answerId,
questionId,
Expand All @@ -278,16 +295,8 @@ export function fetchLiveFeedback(
CourseAPI.assessment.submissions
.fetchLiveFeedback(feedbackUrl, feedbackToken)
.then((response) => {
// if 200, go straight to LIVE_FEEDBACK_SUCCESS
if (response.status === 200) {
dispatch({
type: actionTypes.LIVE_FEEDBACK_SUCCESS,
payload: {
questionId,
answerId,
feedbackFiles: response.data?.data?.feedbackFiles ?? {},
},
});
handleFeedbackOKResponse(dispatch, response, answerId, questionId);
}
})
.catch(() => {
Expand Down
Loading

0 comments on commit f981823

Please sign in to comment.