2017-05-19 19:28:25 -04:00
|
|
|
import React from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import PropTypes from 'prop-types';
|
2021-09-25 23:46:13 -04:00
|
|
|
import { lookupAccount } from 'mastodon/actions/accounts';
|
2018-03-24 10:25:15 -04:00
|
|
|
import { expandAccountMediaTimeline } from '../../actions/timelines';
|
2019-05-02 02:34:32 -04:00
|
|
|
import LoadingIndicator from 'mastodon/components/loading_indicator';
|
2017-05-19 19:28:25 -04:00
|
|
|
import Column from '../ui/components/column';
|
2019-05-02 02:34:32 -04:00
|
|
|
import ColumnBackButton from 'mastodon/components/column_back_button';
|
2017-05-19 19:28:25 -04:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2019-05-02 02:34:32 -04:00
|
|
|
import { getAccountGallery } from 'mastodon/selectors';
|
2017-05-19 19:28:25 -04:00
|
|
|
import MediaItem from './components/media_item';
|
|
|
|
import HeaderContainer from '../account_timeline/containers/header_container';
|
2021-07-13 09:45:17 -04:00
|
|
|
import ScrollContainer from 'mastodon/containers/scroll_container';
|
2019-05-02 02:34:32 -04:00
|
|
|
import LoadMore from 'mastodon/components/load_more';
|
2019-04-08 23:02:48 -04:00
|
|
|
import MissingIndicator from 'mastodon/components/missing_indicator';
|
2019-05-02 02:34:32 -04:00
|
|
|
import { openModal } from 'mastodon/actions/modal';
|
2020-09-09 18:07:19 -04:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2017-05-19 19:28:25 -04:00
|
|
|
|
2021-09-25 23:46:13 -04:00
|
|
|
const mapStateToProps = (state, { params: { acct } }) => {
|
|
|
|
const accountId = state.getIn(['accounts_map', acct]);
|
|
|
|
|
|
|
|
if (!accountId) {
|
|
|
|
return {
|
|
|
|
isLoading: true,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
accountId,
|
|
|
|
isAccount: !!state.getIn(['accounts', accountId]),
|
|
|
|
attachments: getAccountGallery(state, accountId),
|
|
|
|
isLoading: state.getIn(['timelines', `account:${accountId}:media`, 'isLoading']),
|
|
|
|
hasMore: state.getIn(['timelines', `account:${accountId}:media`, 'hasMore']),
|
|
|
|
suspended: state.getIn(['accounts', accountId, 'suspended'], false),
|
|
|
|
blockedBy: state.getIn(['relationships', accountId, 'blocked_by'], false),
|
|
|
|
};
|
|
|
|
};
|
2017-05-19 19:28:25 -04:00
|
|
|
|
2018-03-24 10:25:15 -04:00
|
|
|
class LoadMoreMedia extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
maxId: PropTypes.string,
|
|
|
|
onLoadMore: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
handleLoadMore = () => {
|
|
|
|
this.props.onLoadMore(this.props.maxId);
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<LoadMore
|
|
|
|
disabled={this.props.disabled}
|
2018-12-12 16:32:44 -05:00
|
|
|
onClick={this.handleLoadMore}
|
2018-03-24 10:25:15 -04:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-09-14 11:59:48 -04:00
|
|
|
export default @connect(mapStateToProps)
|
|
|
|
class AccountGallery extends ImmutablePureComponent {
|
2017-05-19 19:28:25 -04:00
|
|
|
|
|
|
|
static propTypes = {
|
2021-09-25 23:46:13 -04:00
|
|
|
params: PropTypes.shape({
|
|
|
|
acct: PropTypes.string.isRequired,
|
|
|
|
}).isRequired,
|
|
|
|
accountId: PropTypes.string,
|
2017-05-19 19:28:25 -04:00
|
|
|
dispatch: PropTypes.func.isRequired,
|
2019-05-02 02:34:32 -04:00
|
|
|
attachments: ImmutablePropTypes.list.isRequired,
|
2017-05-19 19:28:25 -04:00
|
|
|
isLoading: PropTypes.bool,
|
|
|
|
hasMore: PropTypes.bool,
|
2019-04-08 23:02:48 -04:00
|
|
|
isAccount: PropTypes.bool,
|
2020-09-09 18:07:19 -04:00
|
|
|
blockedBy: PropTypes.bool,
|
|
|
|
suspended: PropTypes.bool,
|
2019-08-01 13:17:17 -04:00
|
|
|
multiColumn: PropTypes.bool,
|
2017-05-19 19:28:25 -04:00
|
|
|
};
|
|
|
|
|
2019-05-02 02:34:32 -04:00
|
|
|
state = {
|
|
|
|
width: 323,
|
|
|
|
};
|
|
|
|
|
2021-09-25 23:46:13 -04:00
|
|
|
_load () {
|
|
|
|
const { accountId, dispatch } = this.props;
|
|
|
|
|
|
|
|
dispatch(expandAccountMediaTimeline(accountId));
|
|
|
|
}
|
|
|
|
|
2017-05-19 19:28:25 -04:00
|
|
|
componentDidMount () {
|
2021-09-25 23:46:13 -04:00
|
|
|
const { params: { acct }, accountId, dispatch } = this.props;
|
|
|
|
|
|
|
|
if (accountId) {
|
|
|
|
this._load();
|
|
|
|
} else {
|
|
|
|
dispatch(lookupAccount(acct));
|
|
|
|
}
|
2017-05-19 19:28:25 -04:00
|
|
|
}
|
|
|
|
|
2021-09-25 23:46:13 -04:00
|
|
|
componentDidUpdate (prevProps) {
|
|
|
|
const { params: { acct }, accountId, dispatch } = this.props;
|
|
|
|
|
|
|
|
if (prevProps.accountId !== accountId && accountId) {
|
|
|
|
this._load();
|
|
|
|
} else if (prevProps.params.acct !== acct) {
|
|
|
|
dispatch(lookupAccount(acct));
|
2017-05-19 19:28:25 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-24 23:22:46 -04:00
|
|
|
handleScrollToBottom = () => {
|
|
|
|
if (this.props.hasMore) {
|
2019-05-02 02:34:32 -04:00
|
|
|
this.handleLoadMore(this.props.attachments.size > 0 ? this.props.attachments.last().getIn(['status', 'id']) : undefined);
|
2017-05-24 23:22:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-02 02:34:32 -04:00
|
|
|
handleScroll = e => {
|
2017-05-19 19:28:25 -04:00
|
|
|
const { scrollTop, scrollHeight, clientHeight } = e.target;
|
2017-05-24 23:22:46 -04:00
|
|
|
const offset = scrollHeight - scrollTop - clientHeight;
|
2017-05-19 19:28:25 -04:00
|
|
|
|
2017-05-24 23:22:46 -04:00
|
|
|
if (150 > offset && !this.props.isLoading) {
|
|
|
|
this.handleScrollToBottom();
|
2017-05-19 19:28:25 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-24 10:25:15 -04:00
|
|
|
handleLoadMore = maxId => {
|
2021-09-25 23:46:13 -04:00
|
|
|
this.props.dispatch(expandAccountMediaTimeline(this.props.accountId, { maxId }));
|
2018-03-24 10:25:15 -04:00
|
|
|
};
|
|
|
|
|
2019-05-02 02:34:32 -04:00
|
|
|
handleLoadOlder = e => {
|
2017-05-24 23:22:46 -04:00
|
|
|
e.preventDefault();
|
|
|
|
this.handleScrollToBottom();
|
|
|
|
}
|
|
|
|
|
2019-05-02 02:34:32 -04:00
|
|
|
handleOpenMedia = attachment => {
|
2020-11-26 21:24:11 -05:00
|
|
|
const { dispatch } = this.props;
|
|
|
|
const statusId = attachment.getIn(['status', 'id']);
|
|
|
|
|
2019-10-02 21:34:58 -04:00
|
|
|
if (attachment.get('type') === 'video') {
|
2020-11-26 21:24:11 -05:00
|
|
|
dispatch(openModal('VIDEO', { media: attachment, statusId, options: { autoPlay: true } }));
|
2019-10-02 21:34:58 -04:00
|
|
|
} else if (attachment.get('type') === 'audio') {
|
2020-11-26 21:24:11 -05:00
|
|
|
dispatch(openModal('AUDIO', { media: attachment, statusId, options: { autoPlay: true } }));
|
2019-05-02 02:34:32 -04:00
|
|
|
} else {
|
|
|
|
const media = attachment.getIn(['status', 'media_attachments']);
|
|
|
|
const index = media.findIndex(x => x.get('id') === attachment.get('id'));
|
|
|
|
|
2020-11-26 21:24:11 -05:00
|
|
|
dispatch(openModal('MEDIA', { media, index, statusId }));
|
2019-05-02 02:34:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleRef = c => {
|
|
|
|
if (c) {
|
|
|
|
this.setState({ width: c.offsetWidth });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-19 19:28:25 -04:00
|
|
|
render () {
|
2021-07-13 09:45:17 -04:00
|
|
|
const { attachments, isLoading, hasMore, isAccount, multiColumn, blockedBy, suspended } = this.props;
|
2019-05-02 02:34:32 -04:00
|
|
|
const { width } = this.state;
|
2019-04-08 23:02:48 -04:00
|
|
|
|
|
|
|
if (!isAccount) {
|
|
|
|
return (
|
|
|
|
<Column>
|
|
|
|
<MissingIndicator />
|
|
|
|
</Column>
|
|
|
|
);
|
|
|
|
}
|
2017-05-24 23:22:46 -04:00
|
|
|
|
2019-05-02 02:34:32 -04:00
|
|
|
if (!attachments && isLoading) {
|
2017-05-19 19:28:25 -04:00
|
|
|
return (
|
|
|
|
<Column>
|
|
|
|
<LoadingIndicator />
|
|
|
|
</Column>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-05-02 02:34:32 -04:00
|
|
|
let loadOlder = null;
|
|
|
|
|
|
|
|
if (hasMore && !(isLoading && attachments.size === 0)) {
|
2018-12-12 16:32:44 -05:00
|
|
|
loadOlder = <LoadMore visible={!isLoading} onClick={this.handleLoadOlder} />;
|
2017-05-24 23:22:46 -04:00
|
|
|
}
|
|
|
|
|
2020-12-14 03:08:09 -05:00
|
|
|
let emptyMessage;
|
|
|
|
|
|
|
|
if (suspended) {
|
|
|
|
emptyMessage = <FormattedMessage id='empty_column.account_suspended' defaultMessage='Account suspended' />;
|
|
|
|
} else if (blockedBy) {
|
|
|
|
emptyMessage = <FormattedMessage id='empty_column.account_unavailable' defaultMessage='Profile unavailable' />;
|
|
|
|
}
|
|
|
|
|
2017-05-19 19:28:25 -04:00
|
|
|
return (
|
|
|
|
<Column>
|
2019-08-01 13:17:17 -04:00
|
|
|
<ColumnBackButton multiColumn={multiColumn} />
|
2017-05-19 19:28:25 -04:00
|
|
|
|
2021-07-13 09:45:17 -04:00
|
|
|
<ScrollContainer scrollKey='account_gallery'>
|
2018-12-12 16:32:44 -05:00
|
|
|
<div className='scrollable scrollable--flex' onScroll={this.handleScroll}>
|
2021-09-25 23:46:13 -04:00
|
|
|
<HeaderContainer accountId={this.props.accountId} />
|
2017-05-19 19:28:25 -04:00
|
|
|
|
2020-09-09 18:07:19 -04:00
|
|
|
{(suspended || blockedBy) ? (
|
|
|
|
<div className='empty-column-indicator'>
|
2020-12-14 03:08:09 -05:00
|
|
|
{emptyMessage}
|
2020-09-09 18:07:19 -04:00
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div role='feed' className='account-gallery__container' ref={this.handleRef}>
|
|
|
|
{attachments.map((attachment, index) => attachment === null ? (
|
|
|
|
<LoadMoreMedia key={'more:' + attachments.getIn(index + 1, 'id')} maxId={index > 0 ? attachments.getIn(index - 1, 'id') : null} onLoadMore={this.handleLoadMore} />
|
|
|
|
) : (
|
|
|
|
<MediaItem key={attachment.get('id')} attachment={attachment} displayWidth={width} onOpenMedia={this.handleOpenMedia} />
|
|
|
|
))}
|
|
|
|
|
|
|
|
{loadOlder}
|
|
|
|
</div>
|
|
|
|
)}
|
2018-12-12 16:32:44 -05:00
|
|
|
|
2019-05-02 02:34:32 -04:00
|
|
|
{isLoading && attachments.size === 0 && (
|
2018-12-12 16:32:44 -05:00
|
|
|
<div className='scrollable__append'>
|
|
|
|
<LoadingIndicator />
|
|
|
|
</div>
|
|
|
|
)}
|
2017-05-19 19:28:25 -04:00
|
|
|
</div>
|
|
|
|
</ScrollContainer>
|
|
|
|
</Column>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|