diff --git a/app/javascript/mastodon/features/account/components/account_note.tsx b/app/javascript/mastodon/features/account/components/account_note.tsx index 990544e9fa8..cc8b97681b9 100644 --- a/app/javascript/mastodon/features/account/components/account_note.tsx +++ b/app/javascript/mastodon/features/account/components/account_note.tsx @@ -9,7 +9,10 @@ import { submitAccountNote } from 'mastodon/actions/account_notes'; import { useAppDispatch, useAppSelector } from 'mastodon/store'; const messages = defineMessages({ - placeholder: { id: 'account_note.placeholder', defaultMessage: 'Click to add a note' }, + placeholder: { + id: 'account_note.placeholder', + defaultMessage: 'Click to add a note', + }, }); const InlineAlert: React.FC<{ show: boolean }> = ({ show }) => { @@ -26,8 +29,15 @@ const InlineAlert: React.FC<{ show: boolean }> = ({ show }) => { }, [show, setMountMessage]); return ( - - {mountMessage && } + + {mountMessage && ( + + )} ); }; @@ -39,7 +49,9 @@ interface Props { const InnerAccountNote: React.FC = ({ accountId }) => { const intl = useIntl(); const dispatch = useAppDispatch(); - const initialValue = useAppSelector(state => state.relationships.get(accountId)?.get('note')); + const initialValue = useAppSelector((state) => + state.relationships.get(accountId)?.get('note'), + ); const [value, setValue] = useState(initialValue ?? ''); const [saved, setSaved] = useState(false); @@ -60,14 +72,17 @@ const InnerAccountNote: React.FC = ({ accountId }) => { dirtyRef.current = initialValue !== undefined && initialValue !== value; }, [initialValue, value]); - const onSave = useCallback((value: string) => { - void dispatch(submitAccountNote({ accountId, note: value })); + const onSave = useCallback( + (value: string) => { + void dispatch(submitAccountNote({ accountId, note: value })); - setSaved(true); - setTimeout(() => { - setSaved(false); - }, 2000); - }, [accountId, dispatch, setSaved]); + setSaved(true); + setTimeout(() => { + setSaved(false); + }, 2000); + }, + [accountId, dispatch, setSaved], + ); // Save changes on unmount useEffect(() => { @@ -76,33 +91,43 @@ const InnerAccountNote: React.FC = ({ accountId }) => { }; }, [onSave]); - const handleChange = useCallback>((e) => { - setValue(e.target.value); - }, [setValue]); + const handleChange = useCallback>( + (e) => { + setValue(e.target.value); + }, + [setValue], + ); - const handleKeyDown = useCallback>((e) => { - if (e.key === 'Escape') { - e.preventDefault(); + const handleKeyDown = useCallback>( + (e) => { + if (e.key === 'Escape') { + e.preventDefault(); - setValue(initialValue ?? ''); - e.currentTarget.blur(); - } else if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) { - e.preventDefault(); + setValue(initialValue ?? ''); + e.currentTarget.blur(); + } else if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) { + e.preventDefault(); - onSave(valueRef.current); + onSave(value); - e.currentTarget.blur(); - } - }, [onSave, initialValue]); + e.currentTarget.blur(); + } + }, + [onSave, initialValue, value, setValue], + ); const handleBlur = useCallback(() => { - if (dirtyRef.current) onSave(valueRef.current); - }, [onSave]); + if (dirtyRef.current) onSave(value); + }, [onSave, value]); return (