Update: Add NIP-05 warning to Post Composer

This commit is contained in:
danidfra 2024-10-03 15:30:51 -03:00
parent 3533fb2591
commit 8380c8e091
2 changed files with 10 additions and 3 deletions

View File

@ -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, usePrevious } from 'soapbox/hooks';
import { useAppDispatch, useAppSelector, useCompose, useDraggedFiles, useFeatures, useInstance, useOwnAccount, usePrevious } from 'soapbox/hooks';
import QuotedStatusContainer from '../containers/quoted-status-container';
import ReplyIndicatorContainer from '../containers/reply-indicator-container';
@ -69,6 +69,7 @@ const ComposeForm = <ID extends string>({ id, shouldCondense, autoFocus, clickab
const intl = useIntl();
const dispatch = useAppDispatch();
const { configuration } = useInstance();
const { account } = useOwnAccount();
const compose = useCompose(id);
const showSearch = useAppSelector((state) => state.search.submitted && !state.search.hidden);
@ -108,7 +109,7 @@ const ComposeForm = <ID extends string>({ 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;
const canSubmit = !!editorRef.current && !isSubmitting && !isUploading && !isChangingUpload && !isEmpty && length(fulltext) <= maxTootChars && account?.source?.nostr?.nip05 !== undefined;
const getClickableArea = () => {
return clickableAreaRef ? clickableAreaRef.current : formRef.current;

View File

@ -18,7 +18,8 @@ import { $createParagraphNode, $createTextNode, $getRoot, type LexicalEditor } f
import React, { useMemo, useState } from 'react';
import { FormattedMessage } from 'react-intl';
import { useAppDispatch } from 'soapbox/hooks';
import Warning from 'soapbox/features/compose/components/warning';
import { useAppDispatch, useOwnAccount, useSettingsNotifications } from 'soapbox/hooks';
import { useNodes } from './nodes';
import AutosuggestPlugin from './plugins/autosuggest-plugin';
@ -84,6 +85,8 @@ const ComposeEditor = React.forwardRef<LexicalEditor, IComposeEditor>(({
}, ref) => {
const dispatch = useAppDispatch();
const nodes = useNodes();
const { account } = useOwnAccount();
const settingsNotifications = useSettingsNotifications();
const [suggestionsHidden, setSuggestionsHidden] = useState(true);
@ -132,6 +135,9 @@ const ComposeEditor = React.forwardRef<LexicalEditor, IComposeEditor>(({
return (
<LexicalComposer initialConfig={initialConfig}>
{ account?.source?.nostr?.nip05 === undefined ?
<Warning message={settingsNotifications.has('needsNip05') ? <FormattedMessage id='compose_form.warning' defaultMessage={'Warning: To post, you need a valid username. Please configure your username in \'Settings > Identity\' before continuing.'} /> : <FormattedMessage id='compose_form.warning_waiting' defaultMessage='Warning: To post, you need a valid username. Your username request is pending validation. Please wait until your username is validated.' />} /> : null
}
<div className={clsx('relative', className)}>
<PlainTextPlugin
contentEditable={