From c46f1412f6b2a55de860dd08401b35fec576dc7a Mon Sep 17 00:00:00 2001 From: Doug Martin Date: Thu, 20 Jun 2024 09:38:12 -0400 Subject: [PATCH] fix: Authored state lookup in authoring mode [PT-187809702] This fixes a couple of issues found when testing out authoring: In authoring mode the authoredState comes in as a string which was causing the authoring preview to show an error that the experiment was not selected. There was still a reference to the "Save Authored State" button, which I believe came from the S3 authoring version. --- src/lara-app/components/authoring.tsx | 1 - src/lara-app/hooks/interactive-api.ts | 17 ++++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/lara-app/components/authoring.tsx b/src/lara-app/components/authoring.tsx index ff9805f..ff27f7a 100644 --- a/src/lara-app/components/authoring.tsx +++ b/src/lara-app/components/authoring.tsx @@ -38,7 +38,6 @@ export const AuthoringComponent = (props : IProps) => { })} -
Once you select an experiment please click the "Save authored state" button above to save your choice.
); }; diff --git a/src/lara-app/hooks/interactive-api.ts b/src/lara-app/hooks/interactive-api.ts index 857448b..48d7a8e 100644 --- a/src/lara-app/hooks/interactive-api.ts +++ b/src/lara-app/hooks/interactive-api.ts @@ -70,9 +70,19 @@ export const useInteractiveApi = (options: {setError: (error: any) => void}) => setConnectedToLara(true); let _experiment; - if (data.authoredState && (data.authoredState.version === "1.0")) { - experimentId.current = data.authoredState.experimentId; - _experiment = findExperiment(data.authoredState.experimentId); + let authoredState = data.authoredState; + // In authoring mode the authored state comes in as a string + // which causes the authoring preview to show an error + if (typeof authoredState === "string") { + try { + authoredState = JSON.parse(authoredState); + } catch (e) { + // noop + } + } + if (authoredState?.version === "1.0") { + experimentId.current = authoredState.experimentId; + _experiment = findExperiment(authoredState.experimentId); setExperiment(_experiment); } @@ -119,6 +129,7 @@ export const useInteractiveApi = (options: {setError: (error: any) => void}) => if (data.mode === "runtime" && isGetFirebaseJwtSupported(data)) { _phone.addListener("firebaseJWT", (result: any) => { + debugger; if (result.response_type === "ERROR") { // Switch to preview mode. Most likely it means that user is not logged in (anonymous), a teacher, // or a student running the activity not from the Portal. In all that cases API will return