2020-01-23 21:00:13 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-23 15:15:17 +00:00
|
|
|
import { PureComponent } from 'react';
|
|
|
|
|
2020-01-25 04:23:05 +00:00
|
|
|
import { defineMessages, injectIntl, FormattedMessage, FormattedDate } from 'react-intl';
|
2023-05-23 15:15:17 +00:00
|
|
|
|
2020-01-23 21:00:13 +00:00
|
|
|
import classNames from 'classnames';
|
2023-10-19 17:44:55 +00:00
|
|
|
import { withRouter } from 'react-router-dom';
|
2023-05-23 15:15:17 +00:00
|
|
|
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
|
|
|
|
2020-01-27 10:03:45 +00:00
|
|
|
import TransitionMotion from 'react-motion/lib/TransitionMotion';
|
|
|
|
import spring from 'react-motion/lib/spring';
|
2023-05-23 15:15:17 +00:00
|
|
|
import ReactSwipeableViews from 'react-swipeable-views';
|
|
|
|
|
2024-01-16 10:27:26 +00:00
|
|
|
import elephantUIPlane from '@/images/elephant_ui_plane.svg';
|
|
|
|
import AddIcon from '@/material-icons/400-24px/add.svg?react';
|
|
|
|
import ChevronLeftIcon from '@/material-icons/400-24px/chevron_left.svg?react';
|
|
|
|
import ChevronRightIcon from '@/material-icons/400-24px/chevron_right.svg?react';
|
2023-05-23 15:15:17 +00:00
|
|
|
import { AnimatedNumber } from 'mastodon/components/animated_number';
|
|
|
|
import { Icon } from 'mastodon/components/icon';
|
|
|
|
import { IconButton } from 'mastodon/components/icon_button';
|
|
|
|
import EmojiPickerDropdown from 'mastodon/features/compose/containers/emoji_picker_dropdown_container';
|
2023-10-24 08:06:14 +00:00
|
|
|
import { unicodeMapping } from 'mastodon/features/emoji/emoji_unicode_mapping_light';
|
2023-05-23 15:15:17 +00:00
|
|
|
import { autoPlayGif, reduceMotion, disableSwiping, mascot } from 'mastodon/initial_state';
|
2020-10-12 23:19:35 +00:00
|
|
|
import { assetHost } from 'mastodon/utils/config';
|
2023-10-19 17:44:55 +00:00
|
|
|
import { WithRouterPropTypes } from 'mastodon/utils/react_router';
|
2020-01-23 21:00:13 +00:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
close: { id: 'lightbox.close', defaultMessage: 'Close' },
|
|
|
|
previous: { id: 'lightbox.previous', defaultMessage: 'Previous' },
|
|
|
|
next: { id: 'lightbox.next', defaultMessage: 'Next' },
|
|
|
|
});
|
|
|
|
|
2023-10-19 17:44:55 +00:00
|
|
|
class ContentWithRouter extends ImmutablePureComponent {
|
2020-01-23 21:00:13 +00:00
|
|
|
static propTypes = {
|
|
|
|
announcement: ImmutablePropTypes.map.isRequired,
|
2023-10-19 17:44:55 +00:00
|
|
|
...WithRouterPropTypes,
|
2020-01-23 21:00:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
setRef = c => {
|
|
|
|
this.node = c;
|
2023-01-30 00:45:35 +00:00
|
|
|
};
|
2020-01-23 21:00:13 +00:00
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
this._updateLinks();
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate () {
|
|
|
|
this._updateLinks();
|
|
|
|
}
|
|
|
|
|
|
|
|
_updateLinks () {
|
|
|
|
const node = this.node;
|
|
|
|
|
|
|
|
if (!node) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const links = node.querySelectorAll('a');
|
|
|
|
|
|
|
|
for (var i = 0; i < links.length; ++i) {
|
|
|
|
let link = links[i];
|
|
|
|
|
|
|
|
if (link.classList.contains('status-link')) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
link.classList.add('status-link');
|
|
|
|
|
|
|
|
let mention = this.props.announcement.get('mentions').find(item => link.href === item.get('url'));
|
|
|
|
|
|
|
|
if (mention) {
|
|
|
|
link.addEventListener('click', this.onMentionClick.bind(this, mention), false);
|
|
|
|
link.setAttribute('title', mention.get('acct'));
|
|
|
|
} else if (link.textContent[0] === '#' || (link.previousSibling && link.previousSibling.textContent && link.previousSibling.textContent[link.previousSibling.textContent.length - 1] === '#')) {
|
|
|
|
link.addEventListener('click', this.onHashtagClick.bind(this, link.text), false);
|
|
|
|
} else {
|
2020-03-08 15:10:48 +00:00
|
|
|
let status = this.props.announcement.get('statuses').find(item => link.href === item.get('url'));
|
|
|
|
if (status) {
|
|
|
|
link.addEventListener('click', this.onStatusClick.bind(this, status), false);
|
|
|
|
}
|
2020-01-23 21:00:13 +00:00
|
|
|
link.setAttribute('title', link.href);
|
|
|
|
link.classList.add('unhandled-link');
|
|
|
|
}
|
|
|
|
|
|
|
|
link.setAttribute('target', '_blank');
|
|
|
|
link.setAttribute('rel', 'noopener noreferrer');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onMentionClick = (mention, e) => {
|
2023-10-19 17:44:55 +00:00
|
|
|
if (this.props.history && e.button === 0 && !(e.ctrlKey || e.metaKey)) {
|
2020-01-23 21:00:13 +00:00
|
|
|
e.preventDefault();
|
2023-10-19 17:44:55 +00:00
|
|
|
this.props.history.push(`/@${mention.get('acct')}`);
|
2020-01-23 21:00:13 +00:00
|
|
|
}
|
2023-01-30 00:45:35 +00:00
|
|
|
};
|
2020-01-23 21:00:13 +00:00
|
|
|
|
|
|
|
onHashtagClick = (hashtag, e) => {
|
|
|
|
hashtag = hashtag.replace(/^#/, '');
|
|
|
|
|
2023-10-19 17:44:55 +00:00
|
|
|
if (this.props.history&& e.button === 0 && !(e.ctrlKey || e.metaKey)) {
|
2020-01-23 21:00:13 +00:00
|
|
|
e.preventDefault();
|
2023-10-19 17:44:55 +00:00
|
|
|
this.props.history.push(`/tags/${hashtag}`);
|
2020-01-23 21:00:13 +00:00
|
|
|
}
|
2023-01-30 00:45:35 +00:00
|
|
|
};
|
2020-01-23 21:00:13 +00:00
|
|
|
|
2020-03-08 15:10:48 +00:00
|
|
|
onStatusClick = (status, e) => {
|
2023-10-19 17:44:55 +00:00
|
|
|
if (this.props.history && e.button === 0 && !(e.ctrlKey || e.metaKey)) {
|
2020-03-08 15:10:48 +00:00
|
|
|
e.preventDefault();
|
2023-10-19 17:44:55 +00:00
|
|
|
this.props.history.push(`/@${status.getIn(['account', 'acct'])}/${status.get('id')}`);
|
2020-03-08 15:10:48 +00:00
|
|
|
}
|
2023-01-30 00:45:35 +00:00
|
|
|
};
|
2020-03-08 15:10:48 +00:00
|
|
|
|
2021-01-31 20:25:31 +00:00
|
|
|
handleMouseEnter = ({ currentTarget }) => {
|
|
|
|
if (autoPlayGif) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const emojis = currentTarget.querySelectorAll('.custom-emoji');
|
|
|
|
|
|
|
|
for (var i = 0; i < emojis.length; i++) {
|
|
|
|
let emoji = emojis[i];
|
|
|
|
emoji.src = emoji.getAttribute('data-original');
|
|
|
|
}
|
2023-01-30 00:45:35 +00:00
|
|
|
};
|
2020-01-23 21:00:13 +00:00
|
|
|
|
2021-01-31 20:25:31 +00:00
|
|
|
handleMouseLeave = ({ currentTarget }) => {
|
|
|
|
if (autoPlayGif) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const emojis = currentTarget.querySelectorAll('.custom-emoji');
|
|
|
|
|
|
|
|
for (var i = 0; i < emojis.length; i++) {
|
|
|
|
let emoji = emojis[i];
|
|
|
|
emoji.src = emoji.getAttribute('data-static');
|
|
|
|
}
|
2023-01-30 00:45:35 +00:00
|
|
|
};
|
2020-01-23 21:00:13 +00:00
|
|
|
|
|
|
|
render () {
|
|
|
|
const { announcement } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
2021-01-21 13:29:54 +00:00
|
|
|
className='announcements__item__content translate'
|
2020-01-23 21:00:13 +00:00
|
|
|
ref={this.setRef}
|
|
|
|
dangerouslySetInnerHTML={{ __html: announcement.get('contentHtml') }}
|
2021-01-31 20:25:31 +00:00
|
|
|
onMouseEnter={this.handleMouseEnter}
|
|
|
|
onMouseLeave={this.handleMouseLeave}
|
2020-01-23 21:00:13 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-10-19 17:44:55 +00:00
|
|
|
const Content = withRouter(ContentWithRouter);
|
|
|
|
|
2023-05-23 08:52:27 +00:00
|
|
|
class Emoji extends PureComponent {
|
2020-01-23 21:00:13 +00:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
emoji: PropTypes.string.isRequired,
|
|
|
|
emojiMap: ImmutablePropTypes.map.isRequired,
|
|
|
|
hovered: PropTypes.bool.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { emoji, emojiMap, hovered } = this.props;
|
|
|
|
|
|
|
|
if (unicodeMapping[emoji]) {
|
|
|
|
const { filename, shortCode } = unicodeMapping[this.props.emoji];
|
|
|
|
const title = shortCode ? `:${shortCode}:` : '';
|
|
|
|
|
|
|
|
return (
|
|
|
|
<img
|
|
|
|
draggable='false'
|
|
|
|
className='emojione'
|
|
|
|
alt={emoji}
|
|
|
|
title={title}
|
|
|
|
src={`${assetHost}/emoji/${filename}.svg`}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} else if (emojiMap.get(emoji)) {
|
|
|
|
const filename = (autoPlayGif || hovered) ? emojiMap.getIn([emoji, 'url']) : emojiMap.getIn([emoji, 'static_url']);
|
|
|
|
const shortCode = `:${emoji}:`;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<img
|
|
|
|
draggable='false'
|
|
|
|
className='emojione custom-emoji'
|
|
|
|
alt={shortCode}
|
|
|
|
title={shortCode}
|
|
|
|
src={filename}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class Reaction extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
announcementId: PropTypes.string.isRequired,
|
|
|
|
reaction: ImmutablePropTypes.map.isRequired,
|
|
|
|
addReaction: PropTypes.func.isRequired,
|
|
|
|
removeReaction: PropTypes.func.isRequired,
|
|
|
|
emojiMap: ImmutablePropTypes.map.isRequired,
|
2020-01-27 10:03:45 +00:00
|
|
|
style: PropTypes.object,
|
2020-01-23 21:00:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
hovered: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
handleClick = () => {
|
|
|
|
const { reaction, announcementId, addReaction, removeReaction } = this.props;
|
|
|
|
|
|
|
|
if (reaction.get('me')) {
|
|
|
|
removeReaction(announcementId, reaction.get('name'));
|
|
|
|
} else {
|
|
|
|
addReaction(announcementId, reaction.get('name'));
|
|
|
|
}
|
2023-01-30 00:45:35 +00:00
|
|
|
};
|
2020-01-23 21:00:13 +00:00
|
|
|
|
2023-01-30 00:45:35 +00:00
|
|
|
handleMouseEnter = () => this.setState({ hovered: true });
|
2020-01-23 21:00:13 +00:00
|
|
|
|
2023-01-30 00:45:35 +00:00
|
|
|
handleMouseLeave = () => this.setState({ hovered: false });
|
2020-01-23 21:00:13 +00:00
|
|
|
|
|
|
|
render () {
|
|
|
|
const { reaction } = this.props;
|
|
|
|
|
|
|
|
let shortCode = reaction.get('name');
|
|
|
|
|
|
|
|
if (unicodeMapping[shortCode]) {
|
|
|
|
shortCode = unicodeMapping[shortCode].shortCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2020-01-27 10:03:45 +00:00
|
|
|
<button className={classNames('reactions-bar__item', { active: reaction.get('me') })} onClick={this.handleClick} onMouseEnter={this.handleMouseEnter} onMouseLeave={this.handleMouseLeave} title={`:${shortCode}:`} style={this.props.style}>
|
2020-01-23 21:00:13 +00:00
|
|
|
<span className='reactions-bar__item__emoji'><Emoji hovered={this.state.hovered} emoji={reaction.get('name')} emojiMap={this.props.emojiMap} /></span>
|
2020-01-25 04:23:05 +00:00
|
|
|
<span className='reactions-bar__item__count'><AnimatedNumber value={reaction.get('count')} /></span>
|
2020-01-23 21:00:13 +00:00
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class ReactionsBar extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
announcementId: PropTypes.string.isRequired,
|
|
|
|
reactions: ImmutablePropTypes.list.isRequired,
|
|
|
|
addReaction: PropTypes.func.isRequired,
|
|
|
|
removeReaction: PropTypes.func.isRequired,
|
|
|
|
emojiMap: ImmutablePropTypes.map.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
handleEmojiPick = data => {
|
|
|
|
const { addReaction, announcementId } = this.props;
|
|
|
|
addReaction(announcementId, data.native.replace(/:/g, ''));
|
2023-01-30 00:45:35 +00:00
|
|
|
};
|
2020-01-23 21:00:13 +00:00
|
|
|
|
2020-01-27 10:03:45 +00:00
|
|
|
willEnter () {
|
|
|
|
return { scale: reduceMotion ? 1 : 0 };
|
|
|
|
}
|
|
|
|
|
|
|
|
willLeave () {
|
|
|
|
return { scale: reduceMotion ? 0 : spring(0, { stiffness: 170, damping: 26 }) };
|
|
|
|
}
|
|
|
|
|
2020-01-23 21:00:13 +00:00
|
|
|
render () {
|
|
|
|
const { reactions } = this.props;
|
|
|
|
const visibleReactions = reactions.filter(x => x.get('count') > 0);
|
|
|
|
|
2020-01-27 10:03:45 +00:00
|
|
|
const styles = visibleReactions.map(reaction => ({
|
|
|
|
key: reaction.get('name'),
|
|
|
|
data: reaction,
|
|
|
|
style: { scale: reduceMotion ? 1 : spring(1, { stiffness: 150, damping: 13 }) },
|
|
|
|
})).toArray();
|
|
|
|
|
2020-01-23 21:00:13 +00:00
|
|
|
return (
|
2020-01-27 10:03:45 +00:00
|
|
|
<TransitionMotion styles={styles} willEnter={this.willEnter} willLeave={this.willLeave}>
|
|
|
|
{items => (
|
|
|
|
<div className={classNames('reactions-bar', { 'reactions-bar--empty': visibleReactions.isEmpty() })}>
|
|
|
|
{items.map(({ key, data, style }) => (
|
|
|
|
<Reaction
|
|
|
|
key={key}
|
|
|
|
reaction={data}
|
|
|
|
style={{ transform: `scale(${style.scale})`, position: style.scale < 0.5 ? 'absolute' : 'static' }}
|
|
|
|
announcementId={this.props.announcementId}
|
|
|
|
addReaction={this.props.addReaction}
|
|
|
|
removeReaction={this.props.removeReaction}
|
|
|
|
emojiMap={this.props.emojiMap}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
|
2023-10-24 17:45:08 +00:00
|
|
|
{visibleReactions.size < 8 && <EmojiPickerDropdown onPickEmoji={this.handleEmojiPick} button={<Icon id='plus' icon={AddIcon} />} />}
|
2020-01-27 10:03:45 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</TransitionMotion>
|
2020-01-23 21:00:13 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class Announcement extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
announcement: ImmutablePropTypes.map.isRequired,
|
|
|
|
emojiMap: ImmutablePropTypes.map.isRequired,
|
|
|
|
addReaction: PropTypes.func.isRequired,
|
|
|
|
removeReaction: PropTypes.func.isRequired,
|
|
|
|
intl: PropTypes.object.isRequired,
|
2020-02-03 00:53:09 +00:00
|
|
|
selected: PropTypes.bool,
|
2020-01-23 21:00:13 +00:00
|
|
|
};
|
|
|
|
|
2020-02-03 00:53:09 +00:00
|
|
|
state = {
|
|
|
|
unread: !this.props.announcement.get('read'),
|
|
|
|
};
|
|
|
|
|
|
|
|
componentDidUpdate () {
|
|
|
|
const { selected, announcement } = this.props;
|
|
|
|
if (!selected && this.state.unread !== !announcement.get('read')) {
|
|
|
|
this.setState({ unread: !announcement.get('read') });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-23 21:00:13 +00:00
|
|
|
render () {
|
2020-01-25 15:35:33 +00:00
|
|
|
const { announcement } = this.props;
|
2020-02-03 00:53:09 +00:00
|
|
|
const { unread } = this.state;
|
2020-01-23 21:00:13 +00:00
|
|
|
const startsAt = announcement.get('starts_at') && new Date(announcement.get('starts_at'));
|
|
|
|
const endsAt = announcement.get('ends_at') && new Date(announcement.get('ends_at'));
|
|
|
|
const now = new Date();
|
|
|
|
const hasTimeRange = startsAt && endsAt;
|
|
|
|
const skipYear = hasTimeRange && startsAt.getFullYear() === endsAt.getFullYear() && endsAt.getFullYear() === now.getFullYear();
|
|
|
|
const skipEndDate = hasTimeRange && startsAt.getDate() === endsAt.getDate() && startsAt.getMonth() === endsAt.getMonth() && startsAt.getFullYear() === endsAt.getFullYear();
|
|
|
|
const skipTime = announcement.get('all_day');
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='announcements__item'>
|
|
|
|
<strong className='announcements__item__range'>
|
|
|
|
<FormattedMessage id='announcement.announcement' defaultMessage='Announcement' />
|
2024-02-29 09:40:13 +00:00
|
|
|
{hasTimeRange && <span> · <FormattedDate value={startsAt} year={(skipYear || startsAt.getFullYear() === now.getFullYear()) ? undefined : 'numeric'} month='short' day='2-digit' hour={skipTime ? undefined : '2-digit'} minute={skipTime ? undefined : '2-digit'} /> - <FormattedDate value={endsAt} year={(skipYear || endsAt.getFullYear() === now.getFullYear()) ? undefined : 'numeric'} month={skipEndDate ? undefined : 'short'} day={skipEndDate ? undefined : '2-digit'} hour={skipTime ? undefined : '2-digit'} minute={skipTime ? undefined : '2-digit'} /></span>}
|
2020-01-23 21:00:13 +00:00
|
|
|
</strong>
|
|
|
|
|
|
|
|
<Content announcement={announcement} />
|
|
|
|
|
|
|
|
<ReactionsBar
|
|
|
|
reactions={announcement.get('reactions')}
|
|
|
|
announcementId={announcement.get('id')}
|
|
|
|
addReaction={this.props.addReaction}
|
|
|
|
removeReaction={this.props.removeReaction}
|
|
|
|
emojiMap={this.props.emojiMap}
|
|
|
|
/>
|
2020-02-03 00:53:09 +00:00
|
|
|
|
|
|
|
{unread && <span className='announcements__item__unread' />}
|
2020-01-23 21:00:13 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class Announcements extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
announcements: ImmutablePropTypes.list,
|
|
|
|
emojiMap: ImmutablePropTypes.map.isRequired,
|
2020-02-03 00:53:09 +00:00
|
|
|
dismissAnnouncement: PropTypes.func.isRequired,
|
2020-01-23 21:00:13 +00:00
|
|
|
addReaction: PropTypes.func.isRequired,
|
|
|
|
removeReaction: PropTypes.func.isRequired,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
index: 0,
|
|
|
|
};
|
|
|
|
|
2020-03-25 21:39:55 +00:00
|
|
|
static getDerivedStateFromProps(props, state) {
|
|
|
|
if (props.announcements.size > 0 && state.index >= props.announcements.size) {
|
|
|
|
return { index: props.announcements.size - 1 };
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-03 00:53:09 +00:00
|
|
|
componentDidMount () {
|
|
|
|
this._markAnnouncementAsRead();
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate () {
|
|
|
|
this._markAnnouncementAsRead();
|
|
|
|
}
|
|
|
|
|
|
|
|
_markAnnouncementAsRead () {
|
|
|
|
const { dismissAnnouncement, announcements } = this.props;
|
|
|
|
const { index } = this.state;
|
2020-11-19 16:40:18 +00:00
|
|
|
const announcement = announcements.get(announcements.size - 1 - index);
|
2020-02-03 00:53:09 +00:00
|
|
|
if (!announcement.get('read')) dismissAnnouncement(announcement.get('id'));
|
|
|
|
}
|
|
|
|
|
2020-01-23 21:00:13 +00:00
|
|
|
handleChangeIndex = index => {
|
|
|
|
this.setState({ index: index % this.props.announcements.size });
|
2023-01-30 00:45:35 +00:00
|
|
|
};
|
2020-01-23 21:00:13 +00:00
|
|
|
|
|
|
|
handleNextClick = () => {
|
|
|
|
this.setState({ index: (this.state.index + 1) % this.props.announcements.size });
|
2023-01-30 00:45:35 +00:00
|
|
|
};
|
2020-01-23 21:00:13 +00:00
|
|
|
|
|
|
|
handlePrevClick = () => {
|
|
|
|
this.setState({ index: (this.props.announcements.size + this.state.index - 1) % this.props.announcements.size });
|
2023-01-30 00:45:35 +00:00
|
|
|
};
|
2020-01-23 21:00:13 +00:00
|
|
|
|
|
|
|
render () {
|
|
|
|
const { announcements, intl } = this.props;
|
2020-03-25 21:39:55 +00:00
|
|
|
const { index } = this.state;
|
2020-01-23 21:00:13 +00:00
|
|
|
|
|
|
|
if (announcements.isEmpty()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='announcements'>
|
|
|
|
<img className='announcements__mastodon' alt='' draggable='false' src={mascot || elephantUIPlane} />
|
|
|
|
|
|
|
|
<div className='announcements__container'>
|
2023-04-05 12:58:10 +00:00
|
|
|
<ReactSwipeableViews animateHeight animateTransitions={!reduceMotion} index={index} onChangeIndex={this.handleChangeIndex}>
|
2020-02-03 00:53:09 +00:00
|
|
|
{announcements.map((announcement, idx) => (
|
2020-01-23 21:00:13 +00:00
|
|
|
<Announcement
|
|
|
|
key={announcement.get('id')}
|
|
|
|
announcement={announcement}
|
|
|
|
emojiMap={this.props.emojiMap}
|
|
|
|
addReaction={this.props.addReaction}
|
|
|
|
removeReaction={this.props.removeReaction}
|
|
|
|
intl={intl}
|
2020-02-03 00:53:09 +00:00
|
|
|
selected={index === idx}
|
2020-09-30 17:31:03 +00:00
|
|
|
disabled={disableSwiping}
|
2020-01-23 21:00:13 +00:00
|
|
|
/>
|
2020-10-30 12:09:51 +00:00
|
|
|
)).reverse()}
|
2020-01-23 21:00:13 +00:00
|
|
|
</ReactSwipeableViews>
|
|
|
|
|
2020-01-26 19:07:26 +00:00
|
|
|
{announcements.size > 1 && (
|
|
|
|
<div className='announcements__pagination'>
|
2023-10-24 17:45:08 +00:00
|
|
|
<IconButton disabled={announcements.size === 1} title={intl.formatMessage(messages.previous)} icon='chevron-left' iconComponent={ChevronLeftIcon} onClick={this.handlePrevClick} size={13} />
|
2020-01-26 19:07:26 +00:00
|
|
|
<span>{index + 1} / {announcements.size}</span>
|
2023-10-24 17:45:08 +00:00
|
|
|
<IconButton disabled={announcements.size === 1} title={intl.formatMessage(messages.next)} icon='chevron-right' iconComponent={ChevronRightIcon} onClick={this.handleNextClick} size={13} />
|
2020-01-26 19:07:26 +00:00
|
|
|
</div>
|
|
|
|
)}
|
2020-01-23 21:00:13 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-03-24 02:17:53 +00:00
|
|
|
|
|
|
|
export default injectIntl(Announcements);
|