Convert DetailedStatus to tsx, pretty much
This commit is contained in:
parent
1a4401ce75
commit
d976811cf1
|
@ -1,11 +1,9 @@
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
||||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||||
import { FormattedMessage, injectIntl } from 'react-intl';
|
import { FormattedMessage, injectIntl, WrappedComponentProps as IntlProps } from 'react-intl';
|
||||||
import { FormattedDate } from 'react-intl';
|
import { FormattedDate } from 'react-intl';
|
||||||
import { Link, NavLink } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
import Icon from 'soapbox/components/icon';
|
import Icon from 'soapbox/components/icon';
|
||||||
import QuotedStatus from 'soapbox/features/status/containers/quoted_status_container';
|
import QuotedStatus from 'soapbox/features/status/containers/quoted_status_container';
|
||||||
|
@ -23,27 +21,37 @@ import Video from '../../video';
|
||||||
import Card from './card';
|
import Card from './card';
|
||||||
import StatusInteractionBar from './status_interaction_bar';
|
import StatusInteractionBar from './status_interaction_bar';
|
||||||
|
|
||||||
export default @injectIntl
|
import type { List as ImmutableList } from 'immutable';
|
||||||
class DetailedStatus extends ImmutablePureComponent {
|
import type { Attachment as AttachmentEntity, Status as StatusEntity } from 'soapbox/types/entities';
|
||||||
|
|
||||||
static propTypes = {
|
interface IDetailedStatus extends IntlProps {
|
||||||
status: ImmutablePropTypes.record,
|
status: StatusEntity,
|
||||||
onOpenMedia: PropTypes.func.isRequired,
|
onOpenMedia: (media: ImmutableList<AttachmentEntity>, index: number) => void,
|
||||||
onOpenVideo: PropTypes.func.isRequired,
|
onOpenVideo: (media: ImmutableList<AttachmentEntity>, start: number) => void,
|
||||||
onToggleHidden: PropTypes.func.isRequired,
|
onToggleHidden: (status: StatusEntity) => void,
|
||||||
measureHeight: PropTypes.bool,
|
measureHeight: boolean,
|
||||||
onHeightChange: PropTypes.func,
|
onHeightChange: () => void,
|
||||||
domain: PropTypes.string,
|
domain: string,
|
||||||
compact: PropTypes.bool,
|
compact: boolean,
|
||||||
showMedia: PropTypes.bool,
|
showMedia: boolean,
|
||||||
onToggleMediaVisibility: PropTypes.func,
|
onToggleMediaVisibility: () => void,
|
||||||
};
|
}
|
||||||
|
|
||||||
|
interface IDetailedStatusState {
|
||||||
|
height: number | null,
|
||||||
|
mediaWrapperWidth: number,
|
||||||
|
}
|
||||||
|
|
||||||
|
class DetailedStatus extends ImmutablePureComponent<IDetailedStatus, IDetailedStatusState> {
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
height: null,
|
height: null,
|
||||||
|
mediaWrapperWidth: NaN,
|
||||||
};
|
};
|
||||||
|
|
||||||
handleOpenVideo = (media, startTime) => {
|
node: HTMLDivElement | null = null;
|
||||||
|
|
||||||
|
handleOpenVideo = (media: ImmutableList<AttachmentEntity>, startTime: number) => {
|
||||||
this.props.onOpenVideo(media, startTime);
|
this.props.onOpenVideo(media, startTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +59,7 @@ class DetailedStatus extends ImmutablePureComponent {
|
||||||
this.props.onToggleHidden(this.props.status);
|
this.props.onToggleHidden(this.props.status);
|
||||||
}
|
}
|
||||||
|
|
||||||
_measureHeight(heightJustChanged) {
|
_measureHeight(heightJustChanged = false) {
|
||||||
if (this.props.measureHeight && this.node) {
|
if (this.props.measureHeight && this.node) {
|
||||||
scheduleIdleTask(() => this.node && this.setState({ height: Math.ceil(this.node.scrollHeight) + 1 }));
|
scheduleIdleTask(() => this.node && this.setState({ height: Math.ceil(this.node.scrollHeight) + 1 }));
|
||||||
|
|
||||||
|
@ -61,7 +69,7 @@ class DetailedStatus extends ImmutablePureComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setRef = c => {
|
setRef: React.RefCallback<HTMLDivElement> = c => {
|
||||||
this.node = c;
|
this.node = c;
|
||||||
this._measureHeight();
|
this._measureHeight();
|
||||||
|
|
||||||
|
@ -70,35 +78,41 @@ class DetailedStatus extends ImmutablePureComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps, prevState) {
|
componentDidUpdate(prevProps: IDetailedStatus, prevState: IDetailedStatusState) {
|
||||||
this._measureHeight(prevState.height !== this.state.height);
|
this._measureHeight(prevState.height !== this.state.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleModalLink = e => {
|
// handleModalLink = e => {
|
||||||
e.preventDefault();
|
// e.preventDefault();
|
||||||
|
//
|
||||||
|
// let href;
|
||||||
|
//
|
||||||
|
// if (e.target.nodeName !== 'A') {
|
||||||
|
// href = e.target.parentNode.href;
|
||||||
|
// } else {
|
||||||
|
// href = e.target.href;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// window.open(href, 'soapbox-intent', 'width=445,height=600,resizable=no,menubar=no,status=no,scrollbars=yes');
|
||||||
|
// }
|
||||||
|
|
||||||
let href;
|
getActualStatus = () => {
|
||||||
|
const { status } = this.props;
|
||||||
if (e.target.nodeName !== 'A') {
|
if (!status) return undefined;
|
||||||
href = e.target.parentNode.href;
|
return status.reblog && typeof status.reblog === 'object' ? status.reblog : status;
|
||||||
} else {
|
|
||||||
href = e.target.href;
|
|
||||||
}
|
|
||||||
|
|
||||||
window.open(href, 'soapbox-intent', 'width=445,height=600,resizable=no,menubar=no,status=no,scrollbars=yes');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const status = (this.props.status && this.props.status.get('reblog')) ? this.props.status.get('reblog') : this.props.status;
|
const status = this.getActualStatus();
|
||||||
const outerStyle = { boxSizing: 'border-box' };
|
if (!status) return null;
|
||||||
const { compact } = this.props;
|
const { account } = status;
|
||||||
const favicon = status.getIn(['account', 'pleroma', 'favicon']);
|
if (!account || typeof account !== 'object') return null;
|
||||||
const domain = getDomain(status.get('account'));
|
|
||||||
const size = status.get('media_attachments').size;
|
const outerStyle: React.CSSProperties = { boxSizing: 'border-box' };
|
||||||
|
const { compact } = this.props;
|
||||||
|
const favicon = account.getIn(['pleroma', 'favicon']);
|
||||||
|
const domain = getDomain(account);
|
||||||
|
|
||||||
if (!status) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
let media = null;
|
let media = null;
|
||||||
let statusTypeIcon = null;
|
let statusTypeIcon = null;
|
||||||
|
@ -107,12 +121,15 @@ class DetailedStatus extends ImmutablePureComponent {
|
||||||
outerStyle.height = `${this.state.height}px`;
|
outerStyle.height = `${this.state.height}px`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size > 0) {
|
const size = status.media_attachments.size;
|
||||||
if (size === 1 && status.getIn(['media_attachments', 0, 'type']) === 'video') {
|
const firstAttachment = status.media_attachments.get(0);
|
||||||
const video = status.getIn(['media_attachments', 0]);
|
|
||||||
|
if (size > 0 && firstAttachment) {
|
||||||
|
if (size === 1 && firstAttachment.type === 'video') {
|
||||||
|
const video = firstAttachment;
|
||||||
if (video.external_video_id && status.card?.html) {
|
if (video.external_video_id && status.card?.html) {
|
||||||
const { mediaWrapperWidth } = this.state;
|
const { mediaWrapperWidth } = this.state;
|
||||||
const height = mediaWrapperWidth / (video.getIn(['meta', 'original', 'width']) / video.getIn(['meta', 'original', 'height']));
|
const height = mediaWrapperWidth / Number(video.meta.getIn(['original', 'width'])) / Number(video.meta.getIn(['original', 'height']));
|
||||||
media = (
|
media = (
|
||||||
<div className='status-card horizontal interactive status-card--video'>
|
<div className='status-card horizontal interactive status-card--video'>
|
||||||
<div
|
<div
|
||||||
|
@ -126,33 +143,33 @@ class DetailedStatus extends ImmutablePureComponent {
|
||||||
} else {
|
} else {
|
||||||
media = (
|
media = (
|
||||||
<Video
|
<Video
|
||||||
preview={video.get('preview_url')}
|
preview={video.preview_url}
|
||||||
blurhash={video.get('blurhash')}
|
blurhash={video.blurhash}
|
||||||
src={video.get('url')}
|
src={video.url}
|
||||||
alt={video.get('description')}
|
alt={video.description}
|
||||||
aspectRatio={video.getIn(['meta', 'original', 'aspect'])}
|
aspectRatio={video.meta.getIn(['original', 'aspect'])}
|
||||||
width={300}
|
width={300}
|
||||||
height={150}
|
height={150}
|
||||||
inline
|
inline
|
||||||
onOpenVideo={this.handleOpenVideo}
|
onOpenVideo={this.handleOpenVideo}
|
||||||
sensitive={status.get('sensitive')}
|
sensitive={status.sensitive}
|
||||||
visible={this.props.showMedia}
|
visible={this.props.showMedia}
|
||||||
onToggleVisibility={this.props.onToggleMediaVisibility}
|
onToggleVisibility={this.props.onToggleMediaVisibility}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if (size === 1 && status.getIn(['media_attachments', 0, 'type']) === 'audio' && status.get('media_attachments').size === 1) {
|
} else if (size === 1 && firstAttachment.type === 'audio') {
|
||||||
const attachment = status.getIn(['media_attachments', 0]);
|
const attachment = firstAttachment;
|
||||||
|
|
||||||
media = (
|
media = (
|
||||||
<Audio
|
<Audio
|
||||||
src={attachment.get('url')}
|
src={attachment.url}
|
||||||
alt={attachment.get('description')}
|
alt={attachment.description}
|
||||||
duration={attachment.getIn(['meta', 'original', 'duration'], 0)}
|
duration={attachment.meta.getIn(['original', 'duration', 0])}
|
||||||
poster={attachment.get('preview_url') !== attachment.get('url') ? attachment.get('preview_url') : status.getIn(['account', 'avatar_static'])}
|
poster={attachment.preview_url !== attachment.url ? attachment.preview_url : account.avatar_static}
|
||||||
backgroundColor={attachment.getIn(['meta', 'colors', 'background'])}
|
backgroundColor={attachment.meta.getIn(['colors', 'background'])}
|
||||||
foregroundColor={attachment.getIn(['meta', 'colors', 'foreground'])}
|
foregroundColor={attachment.meta.getIn(['colors', 'foreground'])}
|
||||||
accentColor={attachment.getIn(['meta', 'colors', 'accent'])}
|
accentColor={attachment.meta.getIn(['colors', 'accent'])}
|
||||||
height={150}
|
height={150}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
@ -160,8 +177,8 @@ class DetailedStatus extends ImmutablePureComponent {
|
||||||
media = (
|
media = (
|
||||||
<MediaGallery
|
<MediaGallery
|
||||||
standalone
|
standalone
|
||||||
sensitive={status.get('sensitive')}
|
sensitive={status.sensitive}
|
||||||
media={status.get('media_attachments')}
|
media={status.media_attachments}
|
||||||
height={300}
|
height={300}
|
||||||
onOpenMedia={this.props.onOpenMedia}
|
onOpenMedia={this.props.onOpenMedia}
|
||||||
visible={this.props.showMedia}
|
visible={this.props.showMedia}
|
||||||
|
@ -169,27 +186,27 @@ class DetailedStatus extends ImmutablePureComponent {
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if (status.get('spoiler_text').length === 0 && !status.get('quote')) {
|
} else if (status.spoiler_text.length === 0 && !status.quote) {
|
||||||
media = <Card onOpenMedia={this.props.onOpenMedia} card={status.get('card', null)} />;
|
media = <Card onOpenMedia={this.props.onOpenMedia} card={status.card} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
let quote;
|
let quote;
|
||||||
|
|
||||||
if (status.get('quote')) {
|
if (status.quote) {
|
||||||
if (status.getIn(['pleroma', 'quote_visible'], true) === false) {
|
if (status.pleroma.get('quote_visible', true) === false) {
|
||||||
quote = (
|
quote = (
|
||||||
<div className='quoted-status-tombstone'>
|
<div className='quoted-status-tombstone'>
|
||||||
<p><FormattedMessage id='statuses.quote_tombstone' defaultMessage='Post is unavailable.' /></p>
|
<p><FormattedMessage id='statuses.quote_tombstone' defaultMessage='Post is unavailable.' /></p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
quote = <QuotedStatus statusId={status.get('quote')} />;
|
quote = <QuotedStatus statusId={status.quote} />;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status.get('visibility') === 'direct') {
|
if (status.visibility === 'direct') {
|
||||||
statusTypeIcon = <Icon src={require('@tabler/icons/icons/mail.svg')} />;
|
statusTypeIcon = <Icon src={require('@tabler/icons/icons/mail.svg')} />;
|
||||||
} else if (status.get('visibility') === 'private') {
|
} else if (status.visibility === 'private') {
|
||||||
statusTypeIcon = <Icon src={require('@tabler/icons/icons/lock.svg')} />;
|
statusTypeIcon = <Icon src={require('@tabler/icons/icons/lock.svg')} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,25 +215,25 @@ class DetailedStatus extends ImmutablePureComponent {
|
||||||
<div ref={this.setRef} className={classNames('detailed-status', { compact })}>
|
<div ref={this.setRef} className={classNames('detailed-status', { compact })}>
|
||||||
<div className='mb-4'>
|
<div className='mb-4'>
|
||||||
<AccountContainer
|
<AccountContainer
|
||||||
key={status.getIn(['account', 'id'])}
|
key={account.id}
|
||||||
id={status.getIn(['account', 'id'])}
|
id={account.id}
|
||||||
timestamp={status.get('created_at')}
|
timestamp={status.created_at}
|
||||||
avatarSize={42}
|
avatarSize={42}
|
||||||
hideActions
|
hideActions
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{status.get('group') && (
|
{/* status.group && (
|
||||||
<div className='status__meta'>
|
<div className='status__meta'>
|
||||||
Posted in <NavLink to={`/groups/${status.getIn(['group', 'id'])}`}>{status.getIn(['group', 'title'])}</NavLink>
|
Posted in <NavLink to={`/groups/${status.getIn(['group', 'id'])}`}>{status.getIn(['group', 'title'])}</NavLink>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)*/}
|
||||||
|
|
||||||
<StatusReplyMentions status={status} />
|
<StatusReplyMentions status={status} />
|
||||||
|
|
||||||
<StatusContent
|
<StatusContent
|
||||||
status={status}
|
status={status}
|
||||||
expanded={!status.get('hidden')}
|
expanded={!status.hidden}
|
||||||
onExpandedToggle={this.handleExpandedToggle}
|
onExpandedToggle={this.handleExpandedToggle}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
@ -227,18 +244,19 @@ class DetailedStatus extends ImmutablePureComponent {
|
||||||
<StatusInteractionBar status={status} />
|
<StatusInteractionBar status={status} />
|
||||||
|
|
||||||
<div className='detailed-status__timestamp'>
|
<div className='detailed-status__timestamp'>
|
||||||
{favicon &&
|
{typeof favicon === 'string' && (
|
||||||
<div className='status__favicon'>
|
<div className='status__favicon'>
|
||||||
<Link to={`/timeline/${domain}`}>
|
<Link to={`/timeline/${domain}`}>
|
||||||
<img src={favicon} alt='' title={domain} />
|
<img src={favicon} alt='' title={domain} />
|
||||||
</Link>
|
</Link>
|
||||||
</div>}
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{statusTypeIcon}
|
{statusTypeIcon}
|
||||||
|
|
||||||
<a href={status.get('url')} target='_blank' rel='noopener' className='hover:underline'>
|
<a href={status.url} target='_blank' rel='noopener' className='hover:underline'>
|
||||||
<Text tag='span' theme='muted' size='sm'>
|
<Text tag='span' theme='muted' size='sm'>
|
||||||
<FormattedDate value={new Date(status.get('created_at'))} hour12={false} year='numeric' month='short' day='2-digit' hour='2-digit' minute='2-digit' />
|
<FormattedDate value={new Date(status.created_at)} hour12={false} year='numeric' month='short' day='2-digit' hour='2-digit' minute='2-digit' />
|
||||||
</Text>
|
</Text>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -249,3 +267,5 @@ class DetailedStatus extends ImmutablePureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default injectIntl(DetailedStatus);
|
|
@ -34,7 +34,7 @@ import {
|
||||||
revealStatus,
|
revealStatus,
|
||||||
} from '../../../actions/statuses';
|
} from '../../../actions/statuses';
|
||||||
import { makeGetStatus } from '../../../selectors';
|
import { makeGetStatus } from '../../../selectors';
|
||||||
import DetailedStatus from '../components/detailed_status';
|
import DetailedStatus from '../components/detailed-status';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
deleteConfirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' },
|
deleteConfirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' },
|
||||||
|
|
|
@ -58,7 +58,7 @@ import { makeGetStatus } from '../../selectors';
|
||||||
import { attachFullscreenListener, detachFullscreenListener, isFullscreen } from '../ui/util/fullscreen';
|
import { attachFullscreenListener, detachFullscreenListener, isFullscreen } from '../ui/util/fullscreen';
|
||||||
|
|
||||||
import ActionBar from './components/action-bar';
|
import ActionBar from './components/action-bar';
|
||||||
import DetailedStatus from './components/detailed_status';
|
import DetailedStatus from './components/detailed-status';
|
||||||
import ThreadStatus from './components/thread-status';
|
import ThreadStatus from './components/thread-status';
|
||||||
|
|
||||||
import type { AxiosError } from 'axios';
|
import type { AxiosError } from 'axios';
|
||||||
|
@ -704,6 +704,7 @@ class Status extends ImmutablePureComponent<IStatus, IStatusState> {
|
||||||
// FIXME: no "reblogged by" text is added for the screen reader
|
// FIXME: no "reblogged by" text is added for the screen reader
|
||||||
aria-label={textForScreenReader(intl, status)}
|
aria-label={textForScreenReader(intl, status)}
|
||||||
>
|
>
|
||||||
|
{/* @ts-ignore */}
|
||||||
<DetailedStatus
|
<DetailedStatus
|
||||||
status={status}
|
status={status}
|
||||||
onOpenVideo={this.handleOpenVideo}
|
onOpenVideo={this.handleOpenVideo}
|
||||||
|
|
Loading…
Reference in New Issue