Skip to content

Commit

Permalink
Update survey to use new data structure
Browse files Browse the repository at this point in the history
  • Loading branch information
okaycj committed Apr 3, 2024
1 parent 5ba5109 commit 2bfc2d7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 35 deletions.
2 changes: 1 addition & 1 deletion packages/surveys/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"test": "jest --coverage"
},
"dependencies": {
"@lookit/lookit-api": "^0.0.1",
"@lookit/data": "^0.0.1",
"dompurify": "^3.0.11",
"marked": "^12.0.1",
"survey-jquery": "^1.9.136"
Expand Down
2 changes: 1 addition & 1 deletion packages/surveys/rollup.config.dev.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { makeDevConfig } from "../../rollup-dev.mjs";
import rollupConfig from "./rollup.config.mjs";
const port = 10004; // this needs to change for each package
const port = 10003; // this needs to change for each package
export default makeDevConfig(rollupConfig, port);
2 changes: 1 addition & 1 deletion packages/surveys/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { makeRollupConfig } from "@jspsych/config/rollup";
// This package name needs to be unique
export default makeRollupConfig("CHSSurvey");
export default makeRollupConfig("chsSurvey");
18 changes: 8 additions & 10 deletions packages/surveys/src/exit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ParameterType, TrialType } from "jspsych";
import { Model } from "survey-jquery";
import SurveyPlugin from "../../../../jsPsych/packages/plugin-survey/dist";
import surveyJSON from "./survey.json";
import { LookitAPISurveyPlugin, survey_function } from "./utils";
import { survey_function } from "./utils";

const info = <const>{
...SurveyPlugin.info,
Expand Down Expand Up @@ -45,7 +45,7 @@ function showDatabraryOptions(trial: Trial) {
}

function includeWithdrawalExample(trial: Trial) {
const study = window.lookit.study;
const study = window.chs.study;
const withdrawal_element = surveyJSON.pages[0].elements.find(
(element) => element.name === "withdrawal",
);
Expand Down Expand Up @@ -113,15 +113,13 @@ function exit_survey_function(survey: Model) {
});
}

export class ExitSurveyPlugin extends LookitAPISurveyPlugin {
export class ExitSurveyPlugin extends SurveyPlugin {
static readonly info = info;
async trial(display_element: HTMLElement, trial: Trial) {
this.lookitData().then(() => {
super.trial(display_element, {
...trial,
survey_json: surveyParameters(trial),
survey_function: exit_survey_function,
});
trial(display_element: HTMLElement, trial: Trial) {
super.trial(display_element, {
...trial,
survey_json: surveyParameters(trial),
survey_function: exit_survey_function,
});
}
}
11 changes: 11 additions & 0 deletions packages/surveys/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
import { Child, PastSession, Study } from "@lookit/data/dist/types";
import { ExitSurveyPlugin } from "./exit";

declare global {
interface Window {
chs: {
study: Study;
child: Child;
pastSessions: PastSession[];
};
}
}

export default { exit: ExitSurveyPlugin };
22 changes: 0 additions & 22 deletions packages/surveys/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
import Api from "@lookit/lookit-api";
import { Study } from "@lookit/lookit-api/dist/types";
import DOMPurify from "dompurify";
import { marked } from "marked";
import { Model } from "survey-jquery";
import SurveyPlugin from "../../../../jsPsych/packages/plugin-survey/dist";

declare global {
interface Window {
lookit: {
study: Study;
};
}
}

const CONFIG = <const>{
marked: { async: false },
Expand All @@ -28,14 +17,3 @@ export function survey_function(survey: Model) {
});
return survey;
}

export class LookitAPISurveyPlugin extends SurveyPlugin {
async lookitData() {
!window.lookit &&
Object.assign(window, {
lookit: {
study: await Api.retreiveStudy(),
},
});
}
}

0 comments on commit 2bfc2d7

Please sign in to comment.