From 7f4e4a60e0afe31c4801c00a4f032adca90a9c6b Mon Sep 17 00:00:00 2001 From: Nicole Watts Date: Mon, 23 Sep 2024 11:01:18 -0600 Subject: [PATCH] wip: prevent reinitialize from hiding keyboard invitation right away --- .../reducer/interactive-graph-reducer.ts | 1 + .../widgets/interactive-graphs/stateful-mafs-graph.tsx | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/perseus/src/widgets/interactive-graphs/reducer/interactive-graph-reducer.ts b/packages/perseus/src/widgets/interactive-graphs/reducer/interactive-graph-reducer.ts index c1f537ecfd..b06fe98394 100644 --- a/packages/perseus/src/widgets/interactive-graphs/reducer/interactive-graph-reducer.ts +++ b/packages/perseus/src/widgets/interactive-graphs/reducer/interactive-graph-reducer.ts @@ -215,6 +215,7 @@ function doChangeKeyboardInvitationVisibility( return { ...state, showKeyboardInteractionInvitation: action.shouldShow, + hasBeenInteractedWith: true, }; } diff --git a/packages/perseus/src/widgets/interactive-graphs/stateful-mafs-graph.tsx b/packages/perseus/src/widgets/interactive-graphs/stateful-mafs-graph.tsx index 428ec22d18..8aa6d5d1cc 100644 --- a/packages/perseus/src/widgets/interactive-graphs/stateful-mafs-graph.tsx +++ b/packages/perseus/src/widgets/interactive-graphs/stateful-mafs-graph.tsx @@ -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, @@ -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