mirror of
https://github.com/mastodon/mastodon.git
synced 2025-10-05 16:42:47 +00:00
Convert InlineAlert to functional component
This commit is contained in:
parent
547658f086
commit
3b3f3787d7
|
@ -1,5 +1,5 @@
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { PureComponent } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
|
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
|
||||||
|
|
||||||
|
@ -12,38 +12,27 @@ 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' },
|
||||||
});
|
});
|
||||||
|
|
||||||
class InlineAlert extends PureComponent {
|
const InlineAlert = ({ show }) => {
|
||||||
|
const [mountMessage, setMountMessage] = useState(false);
|
||||||
|
|
||||||
static propTypes = {
|
useEffect(() => {
|
||||||
show: PropTypes.bool,
|
if (show) {
|
||||||
};
|
setMountMessage(true);
|
||||||
|
} else {
|
||||||
state = {
|
setTimeout(() => setMountMessage(false), 200);
|
||||||
mountMessage: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
static TRANSITION_DELAY = 200;
|
|
||||||
|
|
||||||
UNSAFE_componentWillReceiveProps (nextProps) {
|
|
||||||
if (!this.props.show && nextProps.show) {
|
|
||||||
this.setState({ mountMessage: true });
|
|
||||||
} else if (this.props.show && !nextProps.show) {
|
|
||||||
setTimeout(() => this.setState({ mountMessage: false }), InlineAlert.TRANSITION_DELAY);
|
|
||||||
}
|
}
|
||||||
}
|
}, [show, setMountMessage]);
|
||||||
|
|
||||||
render () {
|
return (
|
||||||
const { show } = this.props;
|
<span aria-live='polite' role='status' className='inline-alert' style={{ opacity: show ? 1 : 0 }}>
|
||||||
const { mountMessage } = this.state;
|
{mountMessage && <FormattedMessage id='generic.saved' defaultMessage='Saved' />}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
InlineAlert.propTypes = {
|
||||||
<span aria-live='polite' role='status' className='inline-alert' style={{ opacity: show ? 1 : 0 }}>
|
show: PropTypes.bool,
|
||||||
{mountMessage && <FormattedMessage id='generic.saved' defaultMessage='Saved' />}
|
};
|
||||||
</span>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class AccountNote extends ImmutablePureComponent {
|
class AccountNote extends ImmutablePureComponent {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user