Skip to content

Commit 0e051f2

Browse files
authored
Ungraded questions prompts for save (#2884)
* save changes button and save and continue button will highlight for ungraded * added prompt to remind users to save changes * set it so an empty user will grade the qn * changed prompt message in GradingEditor to be the same * changed checkIsNewQuestion to look at gradedAt rather than graderName
1 parent e8648e6 commit 0e051f2

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

src/commons/mocks/BackendMocks.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ export function* mockBackendSaga(): SagaIterator {
321321
gradingQuestion.grade = {
322322
xpAdjustment,
323323
xp: gradingQuestion.grade.xp,
324-
comments
324+
comments,
325+
gradedAt: new Date().toISOString()
325326
};
326327
}
327328
return gradingQuestion;

src/commons/sagas/BackendSaga.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,8 @@ function* BackendSaga(): SagaIterator {
685685
gradingQuestion.grade = {
686686
xpAdjustment,
687687
xp: gradingQuestion.grade.xp,
688-
comments
688+
comments,
689+
gradedAt: new Date().toISOString()
689690
};
690691
}
691692
return gradingQuestion;

src/pages/academy/grading/subcomponents/GradingEditor.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ const GradingEditor: React.FC<Props> = props => {
204204
return props.xpAdjustment !== newXpAdjustmentInput || props.comments !== editorValue;
205205
};
206206

207+
const checkIsNewQuestion = () => {
208+
return props.gradedAt === undefined;
209+
};
210+
207211
const generateMarkdownPreview = (markdown: string) =>
208212
Promise.resolve(
209213
<Markdown
@@ -217,9 +221,10 @@ const GradingEditor: React.FC<Props> = props => {
217221

218222
// Render
219223
const hasUnsavedChanges = checkHasUnsavedChanges();
224+
const isNewQuestion = checkIsNewQuestion();
220225
const saveButtonOpts = {
221-
intent: hasUnsavedChanges ? Intent.WARNING : Intent.NONE,
222-
minimal: !hasUnsavedChanges,
226+
intent: hasUnsavedChanges || isNewQuestion ? Intent.WARNING : Intent.NONE,
227+
minimal: !hasUnsavedChanges && !isNewQuestion,
223228
className: gradingEditorButtonClass
224229
};
225230
const discardButtonOpts = {
@@ -228,8 +233,8 @@ const GradingEditor: React.FC<Props> = props => {
228233
className: gradingEditorButtonClass
229234
};
230235
const saveAndContinueButtonOpts = {
231-
intent: hasUnsavedChanges ? Intent.SUCCESS : Intent.NONE,
232-
minimal: !hasUnsavedChanges,
236+
intent: hasUnsavedChanges || isNewQuestion ? Intent.SUCCESS : Intent.NONE,
237+
minimal: !hasUnsavedChanges && !isNewQuestion,
233238
className: gradingEditorButtonClass
234239
};
235240
const onTabChange = (tab: ReactMdeProps['selectedTab']) => setSelectedTab(tab);
@@ -243,7 +248,7 @@ const GradingEditor: React.FC<Props> = props => {
243248
return (
244249
<div className="GradingEditor">
245250
<Prompt
246-
when={!currentlySaving && hasUnsavedChanges}
251+
when={!currentlySaving && (hasUnsavedChanges || isNewQuestion)}
247252
message={'You have unsaved changes. Are you sure you want to leave?'}
248253
/>
249254

src/pages/academy/grading/subcomponents/GradingWorkspace.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ const GradingWorkspace: React.FC<Props> = props => {
324324
: undefined
325325
}
326326
gradedAt={
327-
grading!.answers[questionId].grade.grader
327+
grading!.answers[questionId].grade.gradedAt
328328
? grading!.answers[questionId].grade.gradedAt!
329329
: undefined
330330
}

0 commit comments

Comments
 (0)