Skip to content

Commit

Permalink
wip: prevent reinitialize from hiding keyboard invitation right away
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicole Watts committed Sep 23, 2024
1 parent 0c97879 commit 7f4e4a6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ function doChangeKeyboardInvitationVisibility(
return {
...state,
showKeyboardInteractionInvitation: action.shouldShow,
hasBeenInteractedWith: true,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,19 @@ export const StatefulMafsGraph = React.forwardRef<
const originalPropsRef = useRef(props);
const latestPropsRef = useLatestRef(props);
useEffect(() => {
if (state.hasBeenInteractedWith) {
return;
}
// This conditional prevents the state from being "reinitialized" right
// after the first render. This is an optimization, but also prevents
// a bug where the graph would be marked "incorrect" during grading
// even if the user never interacted with it.
if (latestPropsRef.current !== originalPropsRef.current) {
dispatch(reinitialize(latestPropsRef.current));
dispatch(
reinitialize({
...latestPropsRef.current,
}),
);
}
}, [
graph.type,
Expand All @@ -133,6 +140,7 @@ export const StatefulMafsGraph = React.forwardRef<
showSides,
latestPropsRef,
startCoords,
state.hasBeenInteractedWith,
]);

// If the graph is static, it always displays the correct answer. This is
Expand Down

0 comments on commit 7f4e4a6

Please sign in to comment.