From 29bdd54dd19e4c16f445632a1b3dc0bf2a7d73dc Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 14 Oct 2024 11:50:51 -0500 Subject: [PATCH] Refactor NIP-05 warnings --- .../compose/components/compose-form.tsx | 30 ++--------- .../compose/containers/warning-container.tsx | 51 ++++++++++++++++++- src/features/compose/editor/index.tsx | 8 +-- src/locales/en.json | 5 +- 4 files changed, 58 insertions(+), 36 deletions(-) diff --git a/src/features/compose/components/compose-form.tsx b/src/features/compose/components/compose-form.tsx index 478a6c0db..8b0f7b19a 100644 --- a/src/features/compose/components/compose-form.tsx +++ b/src/features/compose/components/compose-form.tsx @@ -1,8 +1,8 @@ import clsx from 'clsx'; import { CLEAR_EDITOR_COMMAND, TextNode, type LexicalEditor, $getRoot } from 'lexical'; import React, { Suspense, useCallback, useEffect, useRef, useState } from 'react'; -import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; -import { Link, useHistory } from 'react-router-dom'; +import { defineMessages, useIntl } from 'react-intl'; +import { useHistory } from 'react-router-dom'; import { length } from 'stringz'; import { @@ -17,7 +17,7 @@ import AutosuggestInput, { AutoSuggestion } from 'soapbox/components/autosuggest import { Button, HStack, Stack } from 'soapbox/components/ui'; import EmojiPickerDropdown from 'soapbox/features/emoji/containers/emoji-picker-dropdown-container'; import { ComposeEditor } from 'soapbox/features/ui/util/async-components'; -import { useAppDispatch, useAppSelector, useCompose, useDraggedFiles, useFeatures, useInstance, useOwnAccount, usePrevious } from 'soapbox/hooks'; +import { useAppDispatch, useAppSelector, useCompose, useDraggedFiles, useFeatures, useInstance, usePrevious } from 'soapbox/hooks'; import QuotedStatusContainer from '../containers/quoted-status-container'; import ReplyIndicatorContainer from '../containers/reply-indicator-container'; @@ -39,7 +39,6 @@ import SpoilerInput from './spoiler-input'; import TextCharacterCounter from './text-character-counter'; import UploadForm from './upload-form'; import VisualCharacterCounter from './visual-character-counter'; -import Warning from './warning'; import type { Emoji } from 'soapbox/features/emoji'; @@ -68,13 +67,11 @@ const ComposeForm = ({ id, shouldCondense, autoFocus, clickab const history = useHistory(); const intl = useIntl(); const dispatch = useAppDispatch(); - const { account } = useOwnAccount(); const { instance } = useInstance(); const compose = useCompose(id); const showSearch = useAppSelector((state) => state.search.submitted && !state.search.hidden); const maxTootChars = instance.configuration.statuses.max_characters; - const scheduledStatusCount = useAppSelector((state) => state.scheduled_statuses.size); const features = useFeatures(); const { @@ -109,7 +106,7 @@ const ComposeForm = ({ id, shouldCondense, autoFocus, clickab const isEmpty = !(fulltext.trim() || anyMedia); const condensed = shouldCondense && !isDraggedOver && !composeFocused && isEmpty && !isUploading; const shouldAutoFocus = autoFocus && !showSearch; - const canSubmit = !!editorRef.current && !isSubmitting && !isUploading && !isChangingUpload && !isEmpty && length(fulltext) <= maxTootChars && account?.source?.nostr?.nip05 !== undefined; + const canSubmit = !!editorRef.current && !isSubmitting && !isUploading && !isChangingUpload && !isEmpty && length(fulltext) <= maxTootChars; const getClickableArea = () => { return clickableAreaRef ? clickableAreaRef.current : formRef.current; @@ -247,25 +244,6 @@ const ComposeForm = ({ id, shouldCondense, autoFocus, clickab return ( - {scheduledStatusCount > 0 && !event && !group && ( - - - - ) }} - />) - } - /> - )} - {!shouldCondense && !event && !group && groupId && } diff --git a/src/features/compose/containers/warning-container.tsx b/src/features/compose/containers/warning-container.tsx index 858404c27..1ecc99359 100644 --- a/src/features/compose/containers/warning-container.tsx +++ b/src/features/compose/containers/warning-container.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { FormattedMessage } from 'react-intl'; import { Link } from 'react-router-dom'; -import { useAppSelector, useCompose } from 'soapbox/hooks'; +import { useAppSelector, useCompose, useOwnAccount, useSettingsNotifications } from 'soapbox/hooks'; import { selectOwnAccount } from 'soapbox/selectors'; import Warning from '../components/warning'; @@ -15,11 +15,60 @@ interface IWarningWrapper { const WarningWrapper: React.FC = ({ composeId }) => { const compose = useCompose(composeId); + const scheduledStatusCount = useAppSelector((state) => state.scheduled_statuses.size); + const { account } = useOwnAccount(); + const settingsNotifications = useSettingsNotifications(); const needsLockWarning = useAppSelector((state) => compose.privacy === 'private' && !selectOwnAccount(state)!.locked); const hashtagWarning = (compose.privacy !== 'public' && compose.privacy !== 'group') && APPROX_HASHTAG_RE.test(compose.text); const directMessageWarning = compose.privacy === 'direct'; + if (scheduledStatusCount > 0) { + return ( + + + + ) }} + />) + } + /> + ); + } + + if (account?.source?.nostr?.nip05 === undefined) { + if (settingsNotifications.has('needsNip05')) { + return ( + + + + ), + }} + /> + ); + } else { + return ( + + ); + } + } + if (needsLockWarning) { return ( (({ }, ref) => { const dispatch = useAppDispatch(); const nodes = useNodes(); - const { account } = useOwnAccount(); - const settingsNotifications = useSettingsNotifications(); const [suggestionsHidden, setSuggestionsHidden] = useState(true); @@ -135,9 +132,6 @@ const ComposeEditor = React.forwardRef(({ return ( - { account?.source?.nostr?.nip05 === undefined ? - Identity\' before continuing.'} /> : } /> : null - }
Identity' before continuing.", - "compose_form.warning_waiting": "Warning: To post, you need a valid username. Your username request is pending validation. Please wait until your username is validated.", "compose_group.share_to_followers": "Share with my followers", "confirmation_modal.cancel": "Cancel", "confirmations.admin.deactivate_user.confirm": "Deactivate @{name}",