Skip to content

Commit

Permalink
fix: Authored state lookup in authoring mode [PT-187809702]
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dougmartin committed Jun 20, 2024
1 parent cacc372 commit c46f141
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/lara-app/components/authoring.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const AuthoringComponent = (props : IProps) => {
})}
</>
</select>
<div className={css.note}>Once you select an experiment please click the "Save authored state" button above to save your choice.</div>
</div>
);
};
17 changes: 14 additions & 3 deletions src/lara-app/hooks/interactive-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c46f141

Please sign in to comment.