diff --git a/src/components/codeEditors/aceEditors/aceEditorsStorageHelper.ts b/src/components/codeEditors/aceEditors/aceEditorsStorageHelper.ts index 6554d9b99c56aee14446a7b51bdb8016ed0667fa..619fb2002248eb8830c3564834995576cab5af5f 100644 --- a/src/components/codeEditors/aceEditors/aceEditorsStorageHelper.ts +++ b/src/components/codeEditors/aceEditors/aceEditorsStorageHelper.ts @@ -31,6 +31,11 @@ export class AceEditorsStorageHelper { static editorsMap: EditorMap = {} + /** + * this will overwrite the editor session map with the given initial tab + * @param id + * @param initialTab + */ public static addEditor(id: string, initialTab: AceStoredTabLike) { const initialSession = createEditSession(initialTab.content, `ace/mode/${initialTab.language}` as any) @@ -41,6 +46,11 @@ export class AceEditorsStorageHelper { this.editorsMap[id] = [initialWrappedTab] } + /** + * this will overwrite the editor session map with the given initial tabs + * @param id + * @param initialTabs + */ public static addEditorWithTabs(id: string, initialTabs: AceStoredTabLike[]) { const tabs: EditorWrapperTab[] = [] diff --git a/src/components/sites/tutorViewSite/feedbackPanel/feedbackEditorView.tsx b/src/components/sites/tutorViewSite/feedbackPanel/feedbackEditorView.tsx index 29996b5c8eaba5cc269778792072a66156987d6e..8c3ec841a112d15509a7b0984ba6298d0c52863e 100644 --- a/src/components/sites/tutorViewSite/feedbackPanel/feedbackEditorView.tsx +++ b/src/components/sites/tutorViewSite/feedbackPanel/feedbackEditorView.tsx @@ -63,16 +63,13 @@ class FeedbackEditorView extends React.Component<Props, any> { const editorTabs = AceEditorsStorageHelper.getEditor(tutorViewTutorFeedbackForStudentEditor) + //this should never happen because we overwrite any default session when we get the assessment from backend + //(see reducer) if (editorTabs && editorTabs.length === 1 && editorTabs[0].tab.id === -1) { //this was set by the initial tutor view load with the default assessment //because we mounted the feedback editor and then changed tabs... AceEditorsStorageHelper.removeEditor(tutorViewTutorFeedbackForStudentEditor) AceEditorsStorageHelper.addEditor(tutorViewTutorFeedbackForStudentEditor, tempEditorTab) - - } else if (editorTabs === undefined) { //when we load another submission but the feedback editor is visible --> no mount --> no default session - //so create a default session (simple editor will re-use the this session if the associated tab has the same id) - //this allows us to clear all e.g. undo else we would undo and get the previous/next submission feedback - AceEditorsStorageHelper.addEditor(tutorViewTutorFeedbackForStudentEditor, tempEditorTab) } return ( diff --git a/src/state/reducers/tutorViewSite/crud/getSingleAssessmentReducer.ts b/src/state/reducers/tutorViewSite/crud/getSingleAssessmentReducer.ts index 52d58a056e8ac2eda9e4105f3b26d2c5929c42e1..7dab23cb61b242351ece456d8e3baa8e3a321423 100644 --- a/src/state/reducers/tutorViewSite/crud/getSingleAssessmentReducer.ts +++ b/src/state/reducers/tutorViewSite/crud/getSingleAssessmentReducer.ts @@ -7,6 +7,9 @@ import Logger from "../../../../helpers/logger"; import {AssessmentFullBase} from "../../../../types/submissions"; import {ReduxPromiseAction, ReduxPromiseFulfilledAction, ReduxPromiseRejectedAction} from "../../index"; import {notExhaustive} from "../../_notExhausiveHelper"; +import {AceEditorsStorageHelper} from '../../../../components/codeEditors/aceEditors/aceEditorsStorageHelper' +import {tutorViewTutorFeedbackForStudentEditor} from '../../../../constants' +import {EditorTab} from '../../../../components/codeEditors/multiTabCodeEditorProps' export interface GET_singleAssessmentAction extends ActionBase, ReduxPromiseAction<AssessmentFullBase, GET_singleAssessment_PENDINGAction, GET_singleAssessment_FULFILLEDAction, GET_singleAssessment_REJECTEDAction> { @@ -51,6 +54,28 @@ export function reducer(state: State = initial, action: AllActions): State { isLoading: true } case ActionType.GET_singleAssessment_FULFILLED: + + if (state.exercise.id === -1) { + Logger.error('[getUserSolutionReducer] state.exercise must be loaded before loading the assessment!') + } + + let releaseFinishedAndAutomaticAssessmentHasFinished = state.exercise.exerciseRelease.isReleased && + state.exercise.exerciseRelease.hasAutomaticAssessmentFinished + + const tempEditorTab: EditorTab = { + id: 0, //not -1 else we cannot distinct between this and the default tab/session + content: (action.payload.hasAssessment && action.payload.feedbackForStudent !== null) + ? action.payload.feedbackForStudent + : '', + language: 'markdown', + isReadonly: releaseFinishedAndAutomaticAssessmentHasFinished === false || action.payload.hasAssessment === false, + fileNameWithExtensions: '', + displayIndex: 1, + isMainFile: true, + isContentVisibleForUser: true, + } + AceEditorsStorageHelper.addEditor(tutorViewTutorFeedbackForStudentEditor, tempEditorTab) + return { ...state, isLoading: false,