From 5fcad8a2680c9fca74251af4ea4241b677126f4d Mon Sep 17 00:00:00 2001 From: Josiah Ivey Date: Wed, 13 Nov 2024 13:35:10 -0800 Subject: [PATCH] use the modal hooks like all the other modals --- .../Toolbar/PracticeQuestionsButton.tsx | 19 ++++--------------- src/app/content/practiceQuestions/actions.ts | 3 +++ .../PracticeQuestionsPopup.spec.tsx | 14 ++++++++------ .../components/PracticeQuestionsPopup.tsx | 18 ++++-------------- .../content/practiceQuestions/hooks/index.tsx | 6 ++++++ 5 files changed, 25 insertions(+), 35 deletions(-) diff --git a/src/app/content/components/Toolbar/PracticeQuestionsButton.tsx b/src/app/content/components/Toolbar/PracticeQuestionsButton.tsx index 75b1062ec7..2e9a163271 100644 --- a/src/app/content/components/Toolbar/PracticeQuestionsButton.tsx +++ b/src/app/content/components/Toolbar/PracticeQuestionsButton.tsx @@ -4,13 +4,7 @@ import { useDispatch, useSelector } from 'react-redux'; import styled from 'styled-components/macro'; import practiceQuestionsIcon from '../../../../assets/practiceQuestionsIcon.svg'; import { useAnalyticsEvent } from '../../../../helpers/analytics'; -import { useServices } from '../../../context/Services'; -import { replace } from '../../../navigation/actions'; -import * as navSelect from '../../../navigation/selectors'; -import { AnyMatch } from '../../../navigation/types'; -import { getQueryForParam } from '../../../navigation/utils'; -import { modalQueryParameterName } from '../../constants'; -import { modalUrlName } from '../../practiceQuestions/constants'; +import { openPracticeQuestions } from '../../practiceQuestions/actions'; import { hasPracticeQuestions, isPracticeQuestionsOpen, @@ -47,9 +41,6 @@ const PracticeQuestionsText = styled.span` const PracticeQuestionsButton = () => { const dispatch = useDispatch(); const intl = useIntl(); - const state = useServices().getState(); - const match = navSelect.match(state); - const existingQuery = navSelect.query(state); const isEnabled = useSelector(practiceQuestionsEnabled); const isPracticeQOpen = useSelector(isPracticeQuestionsOpen); const trackOpenClose = useAnalyticsEvent('openClosePracticeQuestions'); @@ -58,17 +49,15 @@ const PracticeQuestionsButton = () => { if (!isEnabled || !hasPracticeQs || !book || !page) { return null; } - const openPracticeQuestions = () => { - dispatch(replace(match as AnyMatch, { - search: getQueryForParam({[modalQueryParameterName]: modalUrlName}, existingQuery), - })); + const showPracticeQuestions = () => { + dispatch(openPracticeQuestions()); trackOpenClose(); }; const text = intl.formatMessage({id: 'i18n:toolbar:practice-questions:button:text'}); return openPracticeQuestions()} + onClick={() => showPracticeQuestions()} aria-label={text} isActive={isPracticeQOpen}>