From 41dde9448f0c686dfaab287aac162db317fce6df Mon Sep 17 00:00:00 2001 From: danidfra Date: Thu, 10 Oct 2024 14:27:21 -0300 Subject: [PATCH] Refactoring and improving the onboarding trigger --- src/components/modal-root.tsx | 4 ++++ .../components/modals/captcha-modal/captcha-modal.tsx | 10 +++++++++- .../ui/components/modals/captcha-modal/captcha.tsx | 4 ++-- .../modals/nostr-signup-modal/steps/keygen-step.tsx | 8 ++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/components/modal-root.tsx b/src/components/modal-root.tsx index 84b7830e1..5afc25d4a 100644 --- a/src/components/modal-root.tsx +++ b/src/components/modal-root.tsx @@ -6,6 +6,7 @@ import { useHistory } from 'react-router-dom'; import { cancelReplyCompose } from 'soapbox/actions/compose'; import { cancelEventCompose } from 'soapbox/actions/events'; import { openModal, closeModal } from 'soapbox/actions/modals'; +import { startOnboarding } from 'soapbox/actions/onboarding'; import { useAppDispatch, usePrevious } from 'soapbox/hooks'; import type { ModalType } from 'soapbox/features/ui/components/modal-root'; @@ -111,6 +112,9 @@ const ModalRoot: React.FC = ({ children, onCancel, onClose, type }) })); } else if ((hasComposeContent || hasEventComposeContent) && type === 'CONFIRM') { dispatch(closeModal('CONFIRM')); + } else if (type === 'CAPTCHA') { + dispatch(startOnboarding()); + onClose(); } else { onClose(); } diff --git a/src/features/ui/components/modals/captcha-modal/captcha-modal.tsx b/src/features/ui/components/modals/captcha-modal/captcha-modal.tsx index 9b1fcbc63..b6d010ad4 100644 --- a/src/features/ui/components/modals/captcha-modal/captcha-modal.tsx +++ b/src/features/ui/components/modals/captcha-modal/captcha-modal.tsx @@ -1,7 +1,9 @@ import React from 'react'; import { FormattedMessage } from 'react-intl'; +import { startOnboarding } from 'soapbox/actions/onboarding'; import { Modal, Stack } from 'soapbox/components/ui'; +import { useAppDispatch } from 'soapbox/hooks'; import Captcha from './captcha'; @@ -10,8 +12,14 @@ interface ICaptchaModal { } const CaptchaModal: React.FC = ({ onClose }) => { + const dispatch = useAppDispatch(); return ( - } onClose={onClose} width='sm'> + } onClose={() => { + onClose(); + dispatch(startOnboarding()); + }} width='sm' + > diff --git a/src/features/ui/components/modals/captcha-modal/captcha.tsx b/src/features/ui/components/modals/captcha-modal/captcha.tsx index bc85d3f88..a11e01431 100644 --- a/src/features/ui/components/modals/captcha-modal/captcha.tsx +++ b/src/features/ui/components/modals/captcha-modal/captcha.tsx @@ -1,10 +1,10 @@ import React from 'react'; import { FormattedMessage } from 'react-intl'; +import useCaptcha from 'soapbox/api/hooks/captcha/useCaptcha'; import { Button, Spinner, Stack, Text } from 'soapbox/components/ui'; -import { PuzzleCaptcha } from './puzzle'; -import useCaptcha from './useCaptcha'; +import { PuzzleCaptcha } from './components/puzzle'; const Captcha: React.FC = () => { const { diff --git a/src/features/ui/components/modals/nostr-signup-modal/steps/keygen-step.tsx b/src/features/ui/components/modals/nostr-signup-modal/steps/keygen-step.tsx index b923c8aaf..9c90a8a98 100644 --- a/src/features/ui/components/modals/nostr-signup-modal/steps/keygen-step.tsx +++ b/src/features/ui/components/modals/nostr-signup-modal/steps/keygen-step.tsx @@ -5,12 +5,14 @@ import { FormattedMessage } from 'react-intl'; import { fetchAccount } from 'soapbox/actions/accounts'; import { openModal } from 'soapbox/actions/modals'; import { logInNostr } from 'soapbox/actions/nostr'; +import { closeSidebar } from 'soapbox/actions/sidebar'; import CopyableInput from 'soapbox/components/copyable-input'; import EmojiGraphic from 'soapbox/components/emoji-graphic'; import { Button, Stack, Modal, FormGroup, Text, Tooltip, HStack } from 'soapbox/components/ui'; import { useNostr } from 'soapbox/contexts/nostr-context'; import { NKeys } from 'soapbox/features/nostr/keys'; import { useAppDispatch, useInstance } from 'soapbox/hooks'; +import { useIsMobile } from 'soapbox/hooks/useIsMobile'; import { download } from 'soapbox/utils/download'; import { slugify } from 'soapbox/utils/input'; @@ -21,6 +23,7 @@ interface IKeygenStep { const KeygenStep: React.FC = ({ onClose }) => { const instance = useInstance(); const dispatch = useAppDispatch(); + const isMobile = useIsMobile(); const { relay } = useNostr(); const secretKey = useMemo(() => generateSecretKey(), []); @@ -64,6 +67,11 @@ const KeygenStep: React.FC = ({ onClose }) => { await dispatch(logInNostr(pubkey)); onClose(); + + if (isMobile) { + dispatch(closeSidebar()); + } + await dispatch(openModal('CAPTCHA')); };