Skip to content

Commit

Permalink
load page doenetML if loading old saved state
Browse files Browse the repository at this point in the history
Fix finish assessment button
  • Loading branch information
dqnykamp committed Sep 3, 2023
1 parent ca3c8ab commit e0179bc
Showing 1 changed file with 27 additions and 40 deletions.
67 changes: 27 additions & 40 deletions packages/doenetml/src/Viewer/ActivityViewer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import VisibilitySensor from "react-visibility-sensor-v2";
import { Button } from "@doenet/ui-components";
import { ButtonGroup } from "@doenet/ui-components";
import { ActionButton } from "@doenet/ui-components";
import { clear as idb_clear } from "idb-keyval";
import { returnAllPossibleVariants } from "../Core/utils/returnAllPossibleVariants";

const sendAlert = (msg, type) => console.log(msg);
Expand Down Expand Up @@ -518,7 +517,9 @@ export function ActivityViewer({
newVariantIndex = localInfo.variantIndex;
setVariantIndex(newVariantIndex);
setNPages(newActivityInfo.orderWithCids.length);
setOrder(newActivityInfo.orderWithCids);
setOrder(
await normalizeLoadedOrder(newActivityInfo.orderWithCids),
);
setVariantsByPage(newActivityInfo.variantsByPage);
setItemWeights(newActivityInfo.itemWeights);
newItemWeights = newActivityInfo.itemWeights;
Expand Down Expand Up @@ -592,7 +593,9 @@ export function ActivityViewer({
newVariantIndex = resp.data.variantIndex;
setVariantIndex(newVariantIndex);
setNPages(newActivityInfo.orderWithCids.length);
setOrder(newActivityInfo.orderWithCids);
setOrder(
await normalizeLoadedOrder(newActivityInfo.orderWithCids),
);
setVariantsByPage(newActivityInfo.variantsByPage);
setItemWeights(newActivityInfo.itemWeights);
newItemWeights = newActivityInfo.itemWeights;
Expand Down Expand Up @@ -659,6 +662,26 @@ export function ActivityViewer({
return { newItemWeights, newVariantIndex, loadedFromInitialState };
}

async function normalizeLoadedOrder(order) {
// In case we load an order from the data base that was created before Sept 1, 2023,
// we need to check if the page has a doneetML attribute,
// and load the doenetML if needed

let newOrder = [];

for (let page of order) {
if (page.doenetML === undefined) {
page.doenetML = await retrieveTextFileForCid(
page.cid,
"doenet",
);
}
newOrder.push(page);
}

return newOrder;
}

async function saveLoadedLocalStateToDatabase(localInfo) {
if (!flags.allowSaveState || !apiURLs.saveActivityState) {
return;
Expand Down Expand Up @@ -1105,43 +1128,7 @@ export function ActivityViewer({

await saveState({ overrideThrottle: true });

setActivityAsCompleted?.(itemWeights);

// TODO: the below should be moved into setActivityAsCompleted
// so we dn't hardcode URIs here

// console.log("activityInfo here",activityInfo)

//Clear out history of exam if canViewAfterCompleted setting set as false
if (!activityInfo.canViewAfterCompleted) {
// console.log("CLEAR state from viewer and cache")
//Simple answer for now - lose all state info
//TODO: When should we clear this
//await idb_clear();
}
//Set assignment as completed for the user in the Data Base and Recoil
let resp = await axios.get(apiURLs.saveCompleted, {
params: { activityId, isCompleted: true },
});
// console.log("resp",resp.data)
if (resp.data.success) {
//Mark activity as completed in Recoil
setActivityAsCompleted?.();

//Go to end exam for the specific page
setPageToolView((prev) => {
return {
page: prev.page,
tool: "endExam",
view: "",
params: {
activityId,
attemptNumber,
itemWeights: itemWeights.join(","),
},
};
});
}
setActivityAsCompleted?.();
}

function setPageErrorsAndWarningsCallback(errorsAndWarnings, pageind) {
Expand Down

0 comments on commit e0179bc

Please sign in to comment.