From 15d9342536d3bae14f75fbfe2452c8e6249c5532 Mon Sep 17 00:00:00 2001 From: Alina086 Date: Mon, 16 Jun 2025 14:13:39 -0400 Subject: [PATCH 1/2] In process of refactoring studypage related code --- frontend/src/editor/index.tsx | 39 ++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/frontend/src/editor/index.tsx b/frontend/src/editor/index.tsx index f725213b..521d8320 100644 --- a/frontend/src/editor/index.tsx +++ b/frontend/src/editor/index.tsx @@ -114,19 +114,19 @@ function EditorScreen() { } const studyPageNames = [ - 'study-introSurvey', 'study-intro', + 'study-introSurvey', 'study-task1', - 'study-posttask1', + 'study-postTask1', 'study-task2', - 'study-posttask2', + 'study-postTask2', 'study-task3', - 'study-posttask3', + 'study-postTask3', 'study-final' ]; const SURVEY_URLS = { - preStudy: 'https://calvin.co1.qualtrics.com/jfe/form/SV_eM6R5Yw7nnJ3jh4', // Pre-study survey + preStudy: 'https://calvin.co1.qualtrics.com/jfe/form/SV_eM6R5Yw7nnJ3jh4', postTask1: 'https://calvin.co1.qualtrics.com/jfe/form/SV_6Vuc9vgqMuEqzVY', postTask2: 'https://calvin.co1.qualtrics.com/jfe/form/SV_7X8tAiech6zP79A', postTask3: 'https://calvin.co1.qualtrics.com/jfe/form/SV_1M8MN5b0H9pfYsm', @@ -148,22 +148,23 @@ function Router({ return ; } else if (page.startsWith('study')) { + + getDefaultStore().set(pageNameAtom, PageName.Study); + getDefaultStore().set(overallModeAtom, OverallMode.study); + const urlParams = new URLSearchParams(window.location.search); const username = urlParams.get('username'); if (!username) { - return
Please provide an username in the URL parameter.
; + return
Please provide a username in the URL parameter.
; } - getDefaultStore().set(pageNameAtom, PageName.Study); - getDefaultStore().set(overallModeAtom, OverallMode.study); - const studyPageIndex = studyPageNames.indexOf(page); if (studyPageIndex === -1) { return
Unknown study page
; } - - //const nextPage = studyPageNames[studyPageIndex + 1] || 'study-intro'; - + + const nextPage = studyPageNames[studyPageIndex + 1] || 'study-intro'; + if (page === 'study-intro') { // TODO: consent form return
@@ -196,12 +197,12 @@ function Router({ const nextUrlParams = new URLSearchParams(window.location.search); nextUrlParams.set('page', 'study-task1'); const redirectURL = encodeURIComponent(window.location.origin + `/editor.html?${nextUrlParams.toString()}`); - + //const redirectURL = encodeURIComponent(window.location.origin + `/editor.html?page=study-task1`); const introSurveyURL = 'https://calvin.co1.qualtrics.com/jfe/form/SV_eM6R5Yw7nnJ3jh4'; return (
- { log ({ username: username, @@ -219,10 +220,10 @@ function Router({
); } - + else if (page === 'study-task1') { const nextUrlParams = new URLSearchParams(window.location.search); - nextUrlParams.set('page', 'study-posttask1'); + nextUrlParams.set('page', 'study-postTask1'); const condition = 'Completion'; // This would be dynamically set based on the study task getDefaultStore().set(studyConditionAtom, condition); @@ -241,18 +242,18 @@ function Router({ event: 'FinishTask1', interaction: 'User finished Task 1' }); - urlParams.set('page', 'study-posttask1') + urlParams.set('page', 'study-postTask1') window.location.search = urlParams.toString() ; }} className={classes.doneButton}> Save and Continue
; } - else if (page === 'study-posttask1') { + else if (page === 'study-postTask1') { const nextUrlParams = new URLSearchParams(window.location.search); nextUrlParams.set('page', 'study-task2'); const redirectURL = encodeURIComponent(window.location.origin + `/editor.html?${nextUrlParams.toString()}`); - + return

Thank you for completing Task 1. Please take a moment to complete a brief survey.

-
; - } - else if (page === 'study-postTask1') { - const nextUrlParams = new URLSearchParams(window.location.search); - nextUrlParams.set('page', 'study-task2'); - const redirectURL = encodeURIComponent(window.location.origin + `/editor.html?${nextUrlParams.toString()}`); - - return
-

Thank you for completing Task 1. Please take a moment to complete a brief survey.

- -
; - } - else if (page === 'study-task2') { - const nextUrlParams = new URLSearchParams(window.location.search); - nextUrlParams.set('page', 'study-posttask2'); - - const condition = 'Question' // This would be dynamically set based on the study task - getDefaultStore().set(studyConditionAtom, condition); - const taskDescription = 'Task 2: Write a cover letter for the position described. The applicant is a recent college graduate with a major in Environmental Sustainability and a minor in Marketing, with relevant internship experience. Demonstrate how their background aligns with the company’s mission and requirements. [Details are given below in the editor document]'; - getDefaultStore().set(taskDescriptionAtom, taskDescription); - - return
-
{taskDescription}
- - - - - -
; - } - else if (page === 'study-posttask2') { - const nextUrlParams = new URLSearchParams(window.location.search); - nextUrlParams.set('page', 'study-task3'); - const redirectURL = encodeURIComponent(window.location.origin + `/editor.html?${nextUrlParams.toString()}`); + else if (page.startsWith('study-task')){ + const urlParams = new URLSearchParams(window.location.search); - return
-

Thank you for completing Task 2. Please take a moment to complete a brief survey.

- -
; + const taskNumber = page.replace('study-task', ''); + const taskConfig = taskConfigs[taskNumber as keyof typeof taskConfigs]; + if (!taskConfig) { + return
Invalid task number
; } - else if (page === 'study-task3') { - const nextUrlParams = new URLSearchParams(window.location.search); - nextUrlParams.set('page', 'study-posttask3'); - - const condition = 'RMove' // This would be dynamically set based on the study task - getDefaultStore().set(studyConditionAtom, condition); - const taskDescription = 'Task 3: After reading these paragraphs, write a summary that explains CRISPR gene editing to your 11th grade biology classmates. Your goal is to help them understand what CRISPR is, how it works, and why it matters, using language and examples they would find clear and engaging.'; - getDefaultStore().set(taskDescriptionAtom, taskDescription); - - return
-
{taskDescription}
+ getDefaultStore().set(studyConditionAtom, taskConfig.condition); + getDefaultStore().set(taskDescriptionAtom, taskConfig.taskDescription); - + return ( +
+
{taskConfig.taskDescription}
- + -
; + +
+ ); } - else if (page === 'study-posttask3') { + else if (page.startsWith('study-postTask')) { const nextUrlParams = new URLSearchParams(window.location.search); - nextUrlParams.set('page', 'study-final'); - const redirectURL = encodeURIComponent(window.location.origin + `/editor.html?${nextUrlParams.toString()}`); + nextUrlParams.set('page', nextPage); + const redirectURL = encodeURIComponent(window.location.origin + `/editor.html?${nextUrlParams.toString()}`); + const postTaskNumber = page.replace('study-postTask', ''); + const postTaskSurveyURL = SURVEY_URLS[`postTask${postTaskNumber}` as keyof typeof SURVEY_URLS]; return
-

Thank you for completing Task 3. Please take a moment to complete a brief survey.

-
+
; } else if (page === 'study-final') {