Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(codaveri-live-feedback): frontend tweaks #7413

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -230,19 +230,57 @@ export function initializeLiveFeedback(questionId) {
});
}

export function generateLiveFeedback(submissionId, answerId, questionId) {
// if status returned 200, populate feedback array if has feedback, otherwise return error
const handleFeedbackOKResponse = ({
dispatch,
response,
answerId,
questionId,
successMessage,
noFeedbackMessage,
}) => {
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(successMessage));
} else {
dispatch({
type: actionTypes.LIVE_FEEDBACK_FAILURE,
payload: {
questionId,
},
});
dispatch(setNotification(noFeedbackMessage));
}
};

export function generateLiveFeedback({
submissionId,
answerId,
questionId,
successMessage,
noFeedbackMessage,
}) {
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,
successMessage,
noFeedbackMessage,
});
} else {
// 201, save feedback signed token
Expand All @@ -267,26 +305,26 @@ export function generateLiveFeedback(submissionId, answerId, questionId) {
});
}

// TODO should each answer/question store its own feedback array?
export function fetchLiveFeedback(
export function fetchLiveFeedback({
answerId,
questionId,
feedbackUrl,
feedbackToken,
) {
successMessage,
noFeedbackMessage,
}) {
return (dispatch) =>
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,
successMessage,
noFeedbackMessage,
});
}
})
Expand Down
Loading