diff --git a/src/views/AssessmentView/SelfAssessmentView/index.jsx b/src/views/AssessmentView/SelfAssessmentView/index.jsx
index f476b367..d509883d 100644
--- a/src/views/AssessmentView/SelfAssessmentView/index.jsx
+++ b/src/views/AssessmentView/SelfAssessmentView/index.jsx
@@ -3,7 +3,7 @@ import React from 'react';
import {
useIsORAConfigLoaded,
usePrompts,
- useResponseData,
+ useResponse,
} from 'hooks/app';
import FileUpload from 'components/FileUpload';
@@ -15,7 +15,7 @@ import BaseAssessmentView from '../BaseAssessmentView';
export const SelfAssessmentView = () => {
const prompts = usePrompts();
- const response = useResponseData();
+ const response = useResponse();
if (!useIsORAConfigLoaded()) {
return null;
}
diff --git a/src/views/AssessmentView/StudentTrainingView/index.jsx b/src/views/AssessmentView/StudentTrainingView/index.jsx
index 8992c083..6a2b230f 100644
--- a/src/views/AssessmentView/StudentTrainingView/index.jsx
+++ b/src/views/AssessmentView/StudentTrainingView/index.jsx
@@ -3,7 +3,7 @@ import React from 'react';
import {
useIsORAConfigLoaded,
usePrompts,
- useResponseData,
+ useResponse,
} from 'hooks/app';
import Prompt from 'components/Prompt';
@@ -15,7 +15,7 @@ import BaseAssessmentView from '../BaseAssessmentView';
export const StudentTrainingView = () => {
const prompts = usePrompts();
- const response = useResponseData();
+ const response = useResponse();
console.log("StudentTrainingView");
if (!useIsORAConfigLoaded()) {
return null;
diff --git a/src/views/AssessmentView/index.jsx b/src/views/AssessmentView/index.jsx
new file mode 100644
index 00000000..ff40ee38
--- /dev/null
+++ b/src/views/AssessmentView/index.jsx
@@ -0,0 +1,33 @@
+import React from 'react';
+
+import Prompt from 'components/Prompt';
+import TextResponse from 'components/TextResponse';
+import FileUpload from 'components/FileUpload';
+
+import BaseAssessmentView from './BaseAssessmentView';
+import useAssessmentData from './useAssessmentData';
+
+export const AssessmentView = () => {
+ const { prompts, response, isLoaded } = useAssessmentData();
+ if (!isLoaded || !response) {
+ return null;
+ }
+
+ return (
+
{}}>
+
+ {React.Children.toArray(
+ prompts.map((prompt, index) => (
+
+ )),
+ )}
+
+
+
+ );
+};
+
+export default AssessmentView;
diff --git a/src/views/AssessmentView/useAssessmentData.js b/src/views/AssessmentView/useAssessmentData.js
new file mode 100644
index 00000000..17cf1822
--- /dev/null
+++ b/src/views/AssessmentView/useAssessmentData.js
@@ -0,0 +1,43 @@
+import React from 'react';
+import { StrictDict, useKeyedState } from '@edx/react-unit-test-utils';
+import {
+ useIsORAConfigLoaded,
+ useIsPageDataLoaded,
+ usePageDataStatus,
+ usePrompts,
+ useResponse,
+ useSetResponse,
+ useResponseData,
+} from 'hooks/app';
+
+const stateKeys = StrictDict({
+ initialized: 'initialized',
+});
+
+const useAssessmentData = () => {
+ const [initialized, setInitialized] = useKeyedState(stateKeys.initialized, false);
+ const prompts = usePrompts();
+ const response = useResponse();
+ const responseData = useResponseData();
+ const setResponse = useSetResponse();
+ const isLoaded = useIsORAConfigLoaded();
+ const isPageDataLoaded = useIsPageDataLoaded();
+ console.log({ pageDataStatus: usePageDataStatus() });
+ React.useEffect(() => {
+ console.log("useAssessmentView useEffect");
+ if (!initialized && isLoaded && isPageDataLoaded) {
+ setResponse(responseData);
+ setInitialized(true);
+ }
+ if (initialized && responseData && response !== responseData) {
+ setResponse(responseData);
+ }
+ }, [responseData, initialized]);
+ return {
+ isLoaded,
+ response,
+ prompts,
+ };
+};
+
+export default useAssessmentData;
diff --git a/src/views/SubmissionView/hooks/useSubmissionViewData.js b/src/views/SubmissionView/hooks/useSubmissionViewData.js
index acf41621..b1248a1e 100644
--- a/src/views/SubmissionView/hooks/useSubmissionViewData.js
+++ b/src/views/SubmissionView/hooks/useSubmissionViewData.js
@@ -1,4 +1,6 @@
-import { useCallback } from 'react';
+import { useCallback, useEffect } from 'react';
+
+import { StrictDict, useKeyedState } from '@edx/react-unit-test-utils';
import {
useGlobalState,
@@ -6,26 +8,42 @@ import {
useSubmitResponse,
useSetHasSubmitted,
useHasSubmitted,
+ useRefreshPageData,
+ useSetResponse,
+ useResponse,
} from 'hooks/app';
+import {
+ useRefreshUpstream,
+} from 'hooks/modal';
import { stepStates, stepNames } from 'constants';
import useTextResponsesData from './useTextResponsesData';
import useUploadedFilesData from './useUploadedFilesData';
+const stateKeys = StrictDict({
+ hasSavedDraft: 'hasSavedDraft',
+});
+
const useSubmissionViewData = () => {
+ const [hasSavedDraft, setHasSavedDraft] = useKeyedState(stateKeys.hasSavedDraft, false);
const hasSubmitted = useHasSubmitted();
const setHasSubmitted = useSetHasSubmitted();
const submitResponseMutation = useSubmitResponse();
const rubricConfig = useRubricConfig();
const globalState = useGlobalState({ step: stepNames.submission });
+ const refreshPageData = useRefreshPageData();
+ const setResponse = useSetResponse();
+ const response = useResponse();
+ const refreshUpstream = useRefreshUpstream();
const stepState = hasSubmitted ? stepStates.submitted : globalState.stepState;
const {
textResponses,
onUpdateTextResponse,
- isDraftSaved,
saveResponse,
saveResponseStatus,
+ finishLater,
+ finishLaterStatus,
} = useTextResponsesData();
const {
uploadedFiles,
@@ -38,23 +56,42 @@ const useSubmissionViewData = () => {
textResponses,
uploadedFiles,
}).then(() => {
+ console.log("submitResponseMutation.then");
+ setResponse({ textResponses, uploadedFiles });
setHasSubmitted(true);
+ refreshPageData();
+ refreshUpstream();
});
}, [setHasSubmitted, submitResponseMutation, textResponses, uploadedFiles]);
+ useEffect(() => {
+ if (!hasSubmitted) {
+ const timer = setTimeout(() => {
+ saveResponse();
+ if (!hasSavedDraft) {
+ setHasSavedDraft(true);
+ }
+ }, 5000);
+ return () => clearTimeout(timer);
+ }
+ }, [saveResponse, hasSubmitted]);
+
return {
actionOptions: {
+ finishLater,
+ finishLaterStatus,
saveResponse,
saveResponseStatus,
submit: submitResponseHandler,
submitStatus: submitResponseMutation.status,
hasSubmitted,
},
+ response: hasSubmitted
+ ? response
+ : { textResponses, uploadedFiles },
hasSubmitted,
- textResponses,
onUpdateTextResponse,
- isDraftSaved,
- uploadedFiles,
+ isDraftSaved: hasSavedDraft,
onDeletedFile,
onFileUploaded,
showRubric: rubricConfig.showDuringResponse,
diff --git a/src/views/SubmissionView/hooks/useTextResponsesData.js b/src/views/SubmissionView/hooks/useTextResponsesData.js
index 462a3552..6b85046d 100644
--- a/src/views/SubmissionView/hooks/useTextResponsesData.js
+++ b/src/views/SubmissionView/hooks/useTextResponsesData.js
@@ -1,7 +1,7 @@
import { useCallback } from 'react';
import { StrictDict, useKeyedState } from '@edx/react-unit-test-utils';
-import { useSaveResponse, useTextResponses } from 'hooks/app';
+import { useFinishLater, useSaveDraftResponse, useTextResponses } from 'hooks/app';
import { MutationStatus } from 'constants';
export const stateKeys = StrictDict({
@@ -15,13 +15,19 @@ const useTextResponsesData = () => {
const [isDirty, setIsDirty] = useKeyedState(stateKeys.isDirty, false);
const [value, setValue] = useKeyedState(stateKeys.textResponses, textResponses);
- const saveResponseMutation = useSaveResponse();
+ const saveResponseMutation = useSaveDraftResponse();
+ const finishLaterMutation = useFinishLater();
const saveResponse = useCallback(() => {
setIsDirty(false);
return saveResponseMutation.mutateAsync({ textResponses: value });
}, [setIsDirty, saveResponseMutation, value]);
+ const finishLater = useCallback(() => {
+ setIsDirty(false);
+ return finishLaterMutation.mutateAsync({ textResponses: value });
+ }, [setIsDirty, finishLaterMutation, value]);
+
const onChange = useCallback((index) => (textResponse) => {
setValue(oldResponses => {
const out = [...oldResponses];
@@ -37,6 +43,8 @@ const useTextResponsesData = () => {
isDraftSaved: saveResponseMutation.status === MutationStatus.success && !isDirty,
saveResponse,
saveResponseStatus: saveResponseMutation.status,
+ finishLater,
+ finishLaterStatus: finishLaterMutation.status,
};
};
diff --git a/src/views/SubmissionView/hooks/useUploadedFilesData.js b/src/views/SubmissionView/hooks/useUploadedFilesData.js
index cde4fce0..163362c2 100644
--- a/src/views/SubmissionView/hooks/useUploadedFilesData.js
+++ b/src/views/SubmissionView/hooks/useUploadedFilesData.js
@@ -22,6 +22,7 @@ const useUploadedFilesData = () => {
);
const onFileUploaded = useCallback(async (data) => {
+ console.log({ onFileUploaded: { data } });
// const { fileData, queryClient } = data;
const uploadResponse = await uploadFilesMutation.mutateAsync(data);
if (uploadResponse) {
diff --git a/src/views/SubmissionView/index.jsx b/src/views/SubmissionView/index.jsx
index 54ecbcec..168cbfb0 100644
--- a/src/views/SubmissionView/index.jsx
+++ b/src/views/SubmissionView/index.jsx
@@ -24,10 +24,12 @@ export const SubmissionView = () => {
const {
actionOptions,
showRubric,
- textResponses,
+ response: {
+ textResponses,
+ uploadedFiles,
+ },
onUpdateTextResponse,
isDraftSaved,
- uploadedFiles,
onDeletedFile,
onFileUploaded,
isReadOnly,