Fix account notes not being displayed (#34166)

This commit is contained in:
Claire 2025-03-18 11:32:35 +01:00 committed by GitHub
parent 6bce43cdb8
commit 9d5cbbbf0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 12 deletions

View File

@ -4,7 +4,6 @@ import { PureComponent } from 'react';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import { is } from 'immutable'; import { is } from 'immutable';
import ImmutablePropTypes from 'react-immutable-proptypes';
import ImmutablePureComponent from 'react-immutable-pure-component'; import ImmutablePureComponent from 'react-immutable-pure-component';
import Textarea from 'react-textarea-autosize'; import Textarea from 'react-textarea-autosize';
@ -49,7 +48,7 @@ class InlineAlert extends PureComponent {
class AccountNote extends ImmutablePureComponent { class AccountNote extends ImmutablePureComponent {
static propTypes = { static propTypes = {
account: ImmutablePropTypes.record.isRequired, accountId: PropTypes.string.isRequired,
value: PropTypes.string, value: PropTypes.string,
onSave: PropTypes.func.isRequired, onSave: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired, intl: PropTypes.object.isRequired,
@ -66,7 +65,7 @@ class AccountNote extends ImmutablePureComponent {
} }
UNSAFE_componentWillReceiveProps (nextProps) { UNSAFE_componentWillReceiveProps (nextProps) {
const accountWillChange = !is(this.props.account, nextProps.account); const accountWillChange = !is(this.props.accountId, nextProps.accountId);
const newState = {}; const newState = {};
if (accountWillChange && this._isDirty()) { if (accountWillChange && this._isDirty()) {
@ -141,21 +140,21 @@ class AccountNote extends ImmutablePureComponent {
} }
render () { render () {
const { account, intl } = this.props; const { accountId, intl } = this.props;
const { value, saved } = this.state; const { value, saved } = this.state;
if (!account) { if (!accountId) {
return null; return null;
} }
return ( return (
<div className='account__header__account-note'> <div className='account__header__account-note'>
<label htmlFor={`account-note-${account.get('id')}`}> <label htmlFor={`account-note-${accountId}`}>
<FormattedMessage id='account.account_note_header' defaultMessage='Personal note' /> <InlineAlert show={saved} /> <FormattedMessage id='account.account_note_header' defaultMessage='Personal note' /> <InlineAlert show={saved} />
</label> </label>
<Textarea <Textarea
id={`account-note-${account.get('id')}`} id={`account-note-${accountId}`}
className='account__header__account-note__content' className='account__header__account-note__content'
disabled={this.props.value === null || value === null} disabled={this.props.value === null || value === null}
placeholder={intl.formatMessage(messages.placeholder)} placeholder={intl.formatMessage(messages.placeholder)}

View File

@ -4,14 +4,14 @@ import { submitAccountNote } from 'mastodon/actions/account_notes';
import AccountNote from '../components/account_note'; import AccountNote from '../components/account_note';
const mapStateToProps = (state, { account }) => ({ const mapStateToProps = (state, { accountId }) => ({
value: account.getIn(['relationship', 'note']), value: state.relationships.getIn([accountId, 'note']),
}); });
const mapDispatchToProps = (dispatch, { account }) => ({ const mapDispatchToProps = (dispatch, { accountId }) => ({
onSave (value) { onSave (value) {
dispatch(submitAccountNote({ accountId: account.get('id'), note: value })); dispatch(submitAccountNote({ accountId: accountId, note: value }));
}, },
}); });

View File

@ -919,7 +919,7 @@ export const AccountHeader: React.FC<{
onClickCapture={handleLinkClick} onClickCapture={handleLinkClick}
> >
{account.id !== me && signedIn && ( {account.id !== me && signedIn && (
<AccountNoteContainer account={account} /> <AccountNoteContainer accountId={accountId} />
)} )}
{account.note.length > 0 && account.note !== '<p></p>' && ( {account.note.length > 0 && account.note !== '<p></p>' && (