2017-05-20 02:28:25 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-28 17:38:10 +03:00
|
|
|
|
|
|
|
import { FormattedMessage } from 'react-intl';
|
|
|
|
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
2021-09-27 08:23:48 +03:00
|
|
|
import { lookupAccount, fetchAccount } from 'flavours/glitch/actions/accounts';
|
2023-05-28 17:38:10 +03:00
|
|
|
import { openModal } from 'flavours/glitch/actions/modal';
|
2018-05-27 20:10:37 +03:00
|
|
|
import { expandAccountMediaTimeline } from 'flavours/glitch/actions/timelines';
|
2023-05-28 17:38:10 +03:00
|
|
|
import LoadMore from 'flavours/glitch/components/load_more';
|
2017-12-04 09:26:40 +02:00
|
|
|
import LoadingIndicator from 'flavours/glitch/components/loading_indicator';
|
2023-05-28 17:38:10 +03:00
|
|
|
import ScrollContainer from 'flavours/glitch/containers/scroll_container';
|
2019-02-27 14:36:40 +02:00
|
|
|
import ProfileColumnHeader from 'flavours/glitch/features/account/components/profile_column_header';
|
2017-12-04 09:26:40 +02:00
|
|
|
import HeaderContainer from 'flavours/glitch/features/account_timeline/containers/header_container';
|
2023-04-12 13:44:58 +03:00
|
|
|
import BundleColumnError from 'flavours/glitch/features/ui/components/bundle_column_error';
|
2023-05-28 17:38:10 +03:00
|
|
|
import Column from 'flavours/glitch/features/ui/components/column';
|
|
|
|
import { normalizeForLookup } from 'flavours/glitch/reducers/accounts_map';
|
|
|
|
import { getAccountGallery } from 'flavours/glitch/selectors';
|
|
|
|
|
|
|
|
import MediaItem from './components/media_item';
|
|
|
|
|
2017-05-20 02:28:25 +03:00
|
|
|
|
2021-09-27 08:23:48 +03:00
|
|
|
const mapStateToProps = (state, { params: { acct, id } }) => {
|
2022-10-24 00:38:08 +03:00
|
|
|
const accountId = id || state.getIn(['accounts_map', normalizeForLookup(acct)]);
|
2021-09-26 06:46:13 +03:00
|
|
|
|
|
|
|
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),
|
|
|
|
};
|
|
|
|
};
|
2017-05-20 02:28:25 +03:00
|
|
|
|
2018-05-27 20:10:37 +03:00
|
|
|
class LoadMoreMedia extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
maxId: PropTypes.string,
|
|
|
|
onLoadMore: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
handleLoadMore = () => {
|
|
|
|
this.props.onLoadMore(this.props.maxId);
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2018-05-27 20:10:37 +03:00
|
|
|
|
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<LoadMore
|
|
|
|
disabled={this.props.disabled}
|
2018-12-11 19:51:01 +02:00
|
|
|
onClick={this.handleLoadMore}
|
2018-05-27 20:10:37 +03:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-09-09 16:16:08 +03:00
|
|
|
class AccountGallery extends ImmutablePureComponent {
|
2017-05-20 02:28:25 +03:00
|
|
|
|
|
|
|
static propTypes = {
|
2021-09-26 06:46:13 +03:00
|
|
|
params: PropTypes.shape({
|
2021-09-27 08:23:48 +03:00
|
|
|
acct: PropTypes.string,
|
|
|
|
id: PropTypes.string,
|
2021-09-26 06:46:13 +03:00
|
|
|
}).isRequired,
|
|
|
|
accountId: PropTypes.string,
|
2017-05-20 02:28:25 +03:00
|
|
|
dispatch: PropTypes.func.isRequired,
|
2019-05-02 09:34:32 +03:00
|
|
|
attachments: ImmutablePropTypes.list.isRequired,
|
2017-05-20 02:28:25 +03:00
|
|
|
isLoading: PropTypes.bool,
|
|
|
|
hasMore: PropTypes.bool,
|
2019-04-09 06:02:48 +03:00
|
|
|
isAccount: PropTypes.bool,
|
2020-09-10 01:07:19 +03:00
|
|
|
suspended: PropTypes.bool,
|
2023-05-07 22:43:25 +03:00
|
|
|
multiColumn: PropTypes.bool,
|
2017-05-20 02:28:25 +03:00
|
|
|
};
|
|
|
|
|
2019-05-02 09:34:32 +03:00
|
|
|
state = {
|
|
|
|
width: 323,
|
|
|
|
};
|
|
|
|
|
2021-09-26 06:46:13 +03:00
|
|
|
_load () {
|
2021-09-27 08:23:48 +03:00
|
|
|
const { accountId, isAccount, dispatch } = this.props;
|
2021-09-26 06:46:13 +03:00
|
|
|
|
2021-09-27 08:23:48 +03:00
|
|
|
if (!isAccount) dispatch(fetchAccount(accountId));
|
2021-09-26 06:46:13 +03:00
|
|
|
dispatch(expandAccountMediaTimeline(accountId));
|
|
|
|
}
|
|
|
|
|
2017-05-20 02:28:25 +03:00
|
|
|
componentDidMount () {
|
2021-09-26 06:46:13 +03:00
|
|
|
const { params: { acct }, accountId, dispatch } = this.props;
|
|
|
|
|
|
|
|
if (accountId) {
|
|
|
|
this._load();
|
|
|
|
} else {
|
|
|
|
dispatch(lookupAccount(acct));
|
|
|
|
}
|
2017-05-20 02:28:25 +03:00
|
|
|
}
|
|
|
|
|
2021-09-26 06:46:13 +03: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-20 02:28:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-08 21:34:31 +02:00
|
|
|
handleHeaderClick = () => {
|
|
|
|
this.column.scrollTop();
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2019-03-08 21:34:31 +02:00
|
|
|
|
2017-05-25 06:22:46 +03:00
|
|
|
handleScrollToBottom = () => {
|
|
|
|
if (this.props.hasMore) {
|
2019-05-02 09:34:32 +03:00
|
|
|
this.handleLoadMore(this.props.attachments.size > 0 ? this.props.attachments.last().getIn(['status', 'id']) : undefined);
|
2017-05-25 06:22:46 +03:00
|
|
|
}
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2017-05-25 06:22:46 +03:00
|
|
|
|
2019-05-02 09:34:32 +03:00
|
|
|
handleScroll = e => {
|
2017-05-20 02:28:25 +03:00
|
|
|
const { scrollTop, scrollHeight, clientHeight } = e.target;
|
2017-05-25 06:22:46 +03:00
|
|
|
const offset = scrollHeight - scrollTop - clientHeight;
|
2017-05-20 02:28:25 +03:00
|
|
|
|
2017-05-25 06:22:46 +03:00
|
|
|
if (150 > offset && !this.props.isLoading) {
|
|
|
|
this.handleScrollToBottom();
|
2017-05-20 02:28:25 +03:00
|
|
|
}
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2017-05-20 02:28:25 +03:00
|
|
|
|
2018-05-27 20:10:37 +03:00
|
|
|
handleLoadMore = maxId => {
|
2021-09-26 06:46:13 +03:00
|
|
|
this.props.dispatch(expandAccountMediaTimeline(this.props.accountId, { maxId }));
|
2018-05-27 20:10:37 +03:00
|
|
|
};
|
|
|
|
|
2019-05-02 09:34:32 +03:00
|
|
|
handleLoadOlder = e => {
|
2017-05-25 06:22:46 +03:00
|
|
|
e.preventDefault();
|
|
|
|
this.handleScrollToBottom();
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2017-05-25 06:22:46 +03:00
|
|
|
|
2019-05-02 09:34:32 +03:00
|
|
|
setColumnRef = c => {
|
2019-03-08 21:34:31 +02:00
|
|
|
this.column = c;
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2019-03-08 21:34:31 +02:00
|
|
|
|
2019-05-02 09:34:32 +03:00
|
|
|
handleOpenMedia = attachment => {
|
2020-11-27 04:24:11 +02:00
|
|
|
const { dispatch } = this.props;
|
|
|
|
const statusId = attachment.getIn(['status', 'id']);
|
2023-05-11 13:41:55 +03:00
|
|
|
const lang = attachment.getIn(['status', 'language']);
|
2020-11-27 04:24:11 +02:00
|
|
|
|
2019-10-03 04:34:58 +03:00
|
|
|
if (attachment.get('type') === 'video') {
|
2023-05-11 13:41:55 +03:00
|
|
|
dispatch(openModal('VIDEO', { media: attachment, statusId, lang, options: { autoPlay: true } }));
|
2019-10-03 04:34:58 +03:00
|
|
|
} else if (attachment.get('type') === 'audio') {
|
2023-05-11 13:41:55 +03:00
|
|
|
dispatch(openModal('AUDIO', { media: attachment, statusId, lang, options: { autoPlay: true } }));
|
2019-05-02 09:34:32 +03:00
|
|
|
} else {
|
|
|
|
const media = attachment.getIn(['status', 'media_attachments']);
|
|
|
|
const index = media.findIndex(x => x.get('id') === attachment.get('id'));
|
|
|
|
|
2023-05-11 13:41:55 +03:00
|
|
|
dispatch(openModal('MEDIA', { media, index, statusId, lang }));
|
2019-05-02 09:34:32 +03:00
|
|
|
}
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2019-05-02 09:34:32 +03:00
|
|
|
|
|
|
|
handleRef = c => {
|
|
|
|
if (c) {
|
|
|
|
this.setState({ width: c.offsetWidth });
|
|
|
|
}
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2019-05-02 09:34:32 +03:00
|
|
|
|
2017-05-20 02:28:25 +03:00
|
|
|
render () {
|
2020-09-10 01:07:19 +03:00
|
|
|
const { attachments, isLoading, hasMore, isAccount, multiColumn, suspended } = this.props;
|
2019-05-02 09:34:32 +03:00
|
|
|
const { width } = this.state;
|
2019-04-09 06:02:48 +03:00
|
|
|
|
|
|
|
if (!isAccount) {
|
|
|
|
return (
|
2023-04-12 13:44:58 +03:00
|
|
|
<BundleColumnError multiColumn={multiColumn} errorType='routing' />
|
2019-04-09 06:02:48 +03:00
|
|
|
);
|
|
|
|
}
|
2017-05-25 06:22:46 +03:00
|
|
|
|
2019-05-02 09:34:32 +03:00
|
|
|
if (!attachments && isLoading) {
|
2017-05-20 02:28:25 +03:00
|
|
|
return (
|
|
|
|
<Column>
|
|
|
|
<LoadingIndicator />
|
|
|
|
</Column>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:34:32 +03:00
|
|
|
let loadOlder = null;
|
|
|
|
|
|
|
|
if (hasMore && !(isLoading && attachments.size === 0)) {
|
2018-12-12 19:06:00 +02:00
|
|
|
loadOlder = <LoadMore visible={!isLoading} onClick={this.handleLoadOlder} />;
|
2017-05-25 06:22:46 +03:00
|
|
|
}
|
|
|
|
|
2017-05-20 02:28:25 +03:00
|
|
|
return (
|
2019-05-02 09:34:32 +03:00
|
|
|
<Column ref={this.setColumnRef}>
|
2019-08-01 20:17:17 +03:00
|
|
|
<ProfileColumnHeader onClick={this.handleHeaderClick} multiColumn={multiColumn} />
|
2017-05-20 02:28:25 +03:00
|
|
|
|
2021-07-13 13:40:15 +03:00
|
|
|
<ScrollContainer scrollKey='account_gallery'>
|
2018-12-12 19:06:00 +02:00
|
|
|
<div className='scrollable scrollable--flex' onScroll={this.handleScroll}>
|
2021-09-26 06:46:13 +03:00
|
|
|
<HeaderContainer accountId={this.props.accountId} />
|
2017-05-20 02:28:25 +03:00
|
|
|
|
2020-09-10 01:07:19 +03:00
|
|
|
{suspended ? (
|
|
|
|
<div className='empty-column-indicator'>
|
2020-12-14 10:08:09 +02:00
|
|
|
<FormattedMessage id='empty_column.account_suspended' defaultMessage='Account suspended' />
|
2020-09-10 01:07:19 +03: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 19:06:00 +02:00
|
|
|
|
2019-05-02 09:34:32 +03:00
|
|
|
{isLoading && attachments.size === 0 && (
|
2018-12-12 19:06:00 +02:00
|
|
|
<div className='scrollable__append'>
|
|
|
|
<LoadingIndicator />
|
|
|
|
</div>
|
|
|
|
)}
|
2017-05-20 02:28:25 +03:00
|
|
|
</div>
|
|
|
|
</ScrollContainer>
|
|
|
|
</Column>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-03-25 00:15:25 +02:00
|
|
|
|
|
|
|
export default connect(mapStateToProps)(AccountGallery);
|