QuotedStatus: convert to FC
This commit is contained in:
parent
de2c9148eb
commit
71362a922a
1 changed files with 59 additions and 75 deletions
|
@ -1,9 +1,7 @@
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { History } from 'history';
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
import { defineMessages, useIntl, FormattedMessage, FormattedList } from 'react-intl';
|
||||||
import { defineMessages, injectIntl, FormattedMessage, IntlShape, FormattedList } from 'react-intl';
|
import { useHistory } from 'react-router-dom';
|
||||||
import { withRouter } from 'react-router-dom';
|
|
||||||
|
|
||||||
import StatusMedia from 'soapbox/components/status-media';
|
import StatusMedia from 'soapbox/components/status-media';
|
||||||
import { Stack, Text } from 'soapbox/components/ui';
|
import { Stack, Text } from 'soapbox/components/ui';
|
||||||
|
@ -16,49 +14,42 @@ const messages = defineMessages({
|
||||||
});
|
});
|
||||||
|
|
||||||
interface IQuotedStatus {
|
interface IQuotedStatus {
|
||||||
|
/** The quoted status entity. */
|
||||||
status?: StatusEntity,
|
status?: StatusEntity,
|
||||||
|
/** Callback when cancelled (during compose). */
|
||||||
onCancel?: Function,
|
onCancel?: Function,
|
||||||
intl: IntlShape,
|
/** Whether the status is shown in the post composer. */
|
||||||
compose?: boolean,
|
compose?: boolean,
|
||||||
history: History,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class QuotedStatus extends ImmutablePureComponent<IQuotedStatus> {
|
/** Status embedded in a quote post. */
|
||||||
|
const QuotedStatus: React.FC<IQuotedStatus> = ({ status, onCancel, compose }) => {
|
||||||
handleExpandClick = (e: React.MouseEvent<HTMLDivElement>) => {
|
const intl = useIntl();
|
||||||
const { compose, status } = this.props;
|
const history = useHistory();
|
||||||
|
|
||||||
|
const handleExpandClick = (e: React.MouseEvent<HTMLDivElement>) => {
|
||||||
if (!status) return;
|
if (!status) return;
|
||||||
|
|
||||||
const account = status.account as AccountEntity;
|
const account = status.account as AccountEntity;
|
||||||
|
|
||||||
if (!compose && e.button === 0) {
|
if (!compose && e.button === 0) {
|
||||||
if (!this.props.history) {
|
history.push(`/@${account.acct}/posts/${status.id}`);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.props.history.push(`/@${account.acct}/posts/${status.id}`);
|
|
||||||
|
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
handleClose = () => {
|
const handleClose = () => {
|
||||||
if (this.props.onCancel) {
|
if (onCancel) {
|
||||||
this.props.onCancel();
|
onCancel();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
renderReplyMentions = () => {
|
|
||||||
const { status } = this.props;
|
|
||||||
|
|
||||||
|
const renderReplyMentions = () => {
|
||||||
if (!status?.in_reply_to_id) {
|
if (!status?.in_reply_to_id) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const account = status.account as AccountEntity;
|
const account = status.account as AccountEntity;
|
||||||
|
|
||||||
const to = status.mentions || [];
|
const to = status.mentions || [];
|
||||||
|
|
||||||
if (to.size === 0) {
|
if (to.size === 0) {
|
||||||
|
@ -102,58 +93,51 @@ class QuotedStatus extends ImmutablePureComponent<IQuotedStatus> {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!status) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
const account = status.account as AccountEntity;
|
||||||
const { status, onCancel, intl, compose } = this.props;
|
|
||||||
|
|
||||||
if (!status) {
|
let actions = {};
|
||||||
return null;
|
if (onCancel) {
|
||||||
}
|
actions = {
|
||||||
|
onActionClick: handleClose,
|
||||||
const account = status.account as AccountEntity;
|
actionIcon: require('@tabler/icons/icons/x.svg'),
|
||||||
|
actionAlignment: 'top',
|
||||||
let actions = {};
|
actionTitle: intl.formatMessage(messages.cancel),
|
||||||
if (onCancel) {
|
};
|
||||||
actions = {
|
|
||||||
onActionClick: this.handleClose,
|
|
||||||
actionIcon: require('@tabler/icons/icons/x.svg'),
|
|
||||||
actionAlignment: 'top',
|
|
||||||
actionTitle: intl.formatMessage(messages.cancel),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const quotedStatus = (
|
|
||||||
<Stack
|
|
||||||
space={2}
|
|
||||||
className={classNames('mt-3 p-4 rounded-lg border border-solid border-gray-100 dark:border-slate-700 cursor-pointer', {
|
|
||||||
'hover:bg-gray-50 dark:hover:bg-slate-700': !compose,
|
|
||||||
})}
|
|
||||||
onClick={this.handleExpandClick}
|
|
||||||
>
|
|
||||||
<AccountContainer
|
|
||||||
{...actions}
|
|
||||||
id={account.id}
|
|
||||||
timestamp={status.created_at}
|
|
||||||
withRelationship={false}
|
|
||||||
showProfileHoverCard={!compose}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{this.renderReplyMentions()}
|
|
||||||
|
|
||||||
<Text
|
|
||||||
className='break-words'
|
|
||||||
size='sm'
|
|
||||||
dangerouslySetInnerHTML={{ __html: status.contentHtml }}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<StatusMedia status={status} />
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
|
|
||||||
return quotedStatus;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
return (
|
||||||
|
<Stack
|
||||||
|
space={2}
|
||||||
|
className={classNames('mt-3 p-4 rounded-lg border border-solid border-gray-100 dark:border-slate-700 cursor-pointer', {
|
||||||
|
'hover:bg-gray-50 dark:hover:bg-slate-700': !compose,
|
||||||
|
})}
|
||||||
|
onClick={handleExpandClick}
|
||||||
|
>
|
||||||
|
<AccountContainer
|
||||||
|
{...actions}
|
||||||
|
id={account.id}
|
||||||
|
timestamp={status.created_at}
|
||||||
|
withRelationship={false}
|
||||||
|
showProfileHoverCard={!compose}
|
||||||
|
/>
|
||||||
|
|
||||||
export default withRouter(injectIntl(QuotedStatus) as any);
|
{renderReplyMentions()}
|
||||||
|
|
||||||
|
<Text
|
||||||
|
className='break-words'
|
||||||
|
size='sm'
|
||||||
|
dangerouslySetInnerHTML={{ __html: status.contentHtml }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<StatusMedia status={status} />
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default QuotedStatus;
|
||||||
|
|
Loading…
Reference in a new issue