app
controllers
helpers
javascript
fonts
images
mastodon
actions
components
containers
features
account
account_gallery
account_timeline
blocks
community_timeline
compose
favourited_statuses
favourites
follow_requests
followers
following
generic_not_found
getting_started
hashtag_timeline
home_timeline
mutes
notifications
public_timeline
reblogs
report
status
ui
components
boost_modal.js
column.js
column_header.js
column_link.js
column_subheading.js
columns_area.js
confirmation_modal.js
media_modal.js
modal_root.js
onboarding_modal.js
tabs_bar.js
upload_area.js
video_modal.js
containers
util
index.js
locales
middleware
reducers
selectors
store
.gitkeep
api.js
base_polyfills.js
emoji.js
extra_polyfills.js
is_mobile.js
link_header.js
main.js
performance.js
rtl.js
stream.js
uuid.js
packs
styles
lib
mailers
models
presenters
services
validators
views
workers
bin
config
db
docs
lib
log
nanobox
public
spec
storybook
streaming
vendor
.babelrc
.buildpacks
.codeclimate.yml
.dockerignore
.editorconfig
.env.nanobox
.env.production.sample
.env.test
.env.vagrant
.eslintignore
.eslintrc.yml
.foreman
.gitignore
.haml-lint.yml
.nanoignore
.nvmrc
.postcssrc.yml
.profile
.rspec
.rubocop.yml
.ruby-version
.scss-lint.yml
.slugignore
.travis.yml
Aptfile
CONTRIBUTING.md
Capfile
Dockerfile
Gemfile
Gemfile.lock
ISSUE_TEMPLATE.md
LICENSE
Procfile
Procfile.dev
README.md
Rakefile
Vagrantfile
app.json
boxfile.yml
config.ru
docker-compose.yml
docker_entrypoint.sh
package.json
scalingo.json
yarn.lock
* Add semi to ESLint rules * Add padded-blocks to ESLint rules * Add comma-dangle to ESLint rules * add config/webpack and storyboard * add streaming/ * yarn test:lint -- --fix
98 lines
2.8 KiB
JavaScript
98 lines
2.8 KiB
JavaScript
import React from 'react';
|
|
import LoadingIndicator from '../../../components/loading_indicator';
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
import PropTypes from 'prop-types';
|
|
import ExtendedVideoPlayer from '../../../components/extended_video_player';
|
|
import ImageLoader from 'react-imageloader';
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
import IconButton from '../../../components/icon_button';
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
|
|
|
const messages = defineMessages({
|
|
close: { id: 'lightbox.close', defaultMessage: 'Close' },
|
|
});
|
|
|
|
class MediaModal extends ImmutablePureComponent {
|
|
|
|
static propTypes = {
|
|
media: ImmutablePropTypes.list.isRequired,
|
|
index: PropTypes.number.isRequired,
|
|
onClose: PropTypes.func.isRequired,
|
|
intl: PropTypes.object.isRequired,
|
|
};
|
|
|
|
state = {
|
|
index: null,
|
|
};
|
|
|
|
handleNextClick = () => {
|
|
this.setState({ index: (this.getIndex() + 1) % this.props.media.size});
|
|
}
|
|
|
|
handlePrevClick = () => {
|
|
this.setState({ index: (this.getIndex() - 1) % this.props.media.size});
|
|
}
|
|
|
|
handleKeyUp = (e) => {
|
|
switch(e.key) {
|
|
case 'ArrowLeft':
|
|
this.handlePrevClick();
|
|
break;
|
|
case 'ArrowRight':
|
|
this.handleNextClick();
|
|
break;
|
|
}
|
|
}
|
|
|
|
componentDidMount () {
|
|
window.addEventListener('keyup', this.handleKeyUp, false);
|
|
}
|
|
|
|
componentWillUnmount () {
|
|
window.removeEventListener('keyup', this.handleKeyUp);
|
|
}
|
|
|
|
getIndex () {
|
|
return this.state.index !== null ? this.state.index : this.props.index;
|
|
}
|
|
|
|
render () {
|
|
const { media, intl, onClose } = this.props;
|
|
|
|
const index = this.getIndex();
|
|
const attachment = media.get(index);
|
|
const url = attachment.get('url');
|
|
|
|
let leftNav, rightNav, content;
|
|
|
|
leftNav = rightNav = content = '';
|
|
|
|
if (media.size > 1) {
|
|
leftNav = <div role='button' tabIndex='0' className='modal-container__nav modal-container__nav--left' onClick={this.handlePrevClick}><i className='fa fa-fw fa-chevron-left' /></div>;
|
|
rightNav = <div role='button' tabIndex='0' className='modal-container__nav modal-container__nav--right' onClick={this.handleNextClick}><i className='fa fa-fw fa-chevron-right' /></div>;
|
|
}
|
|
|
|
if (attachment.get('type') === 'image') {
|
|
content = <ImageLoader src={url} imgProps={{ style: { display: 'block' } }} />;
|
|
} else if (attachment.get('type') === 'gifv') {
|
|
content = <ExtendedVideoPlayer src={url} muted={true} controls={false} />;
|
|
}
|
|
|
|
return (
|
|
<div className='modal-root__modal media-modal'>
|
|
{leftNav}
|
|
|
|
<div className='media-modal__content'>
|
|
<IconButton className='media-modal__close' title={intl.formatMessage(messages.close)} icon='times' onClick={onClose} size={16} />
|
|
{content}
|
|
</div>
|
|
|
|
{rightNav}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
}
|
|
|
|
export default injectIntl(MediaModal);
|