From 89df27a06c69818d38621c1147c6724d76beefde Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 26 Sep 2024 14:31:32 +0200 Subject: [PATCH] Change design of media tab on profiles in web UI (#31967) --- .../mastodon/components/media_gallery.jsx | 13 +- app/javascript/mastodon/components/status.jsx | 38 ++-- .../account_gallery/components/media_item.jsx | 158 -------------- .../account_gallery/components/media_item.tsx | 197 ++++++++++++++++++ .../features/account_gallery/index.jsx | 2 +- .../status/components/detailed_status.tsx | 33 +-- app/javascript/mastodon/models/status.ts | 2 + .../material-icons/400-20px/mood-fill.svg | 2 +- .../material-icons/400-20px/mood.svg | 2 +- .../material-icons/400-20px/warning-fill.svg | 2 +- .../material-icons/400-20px/warning.svg | 2 +- .../400-24px/add_photo_alternate-fill.svg | 2 +- .../400-24px/add_photo_alternate.svg | 2 +- .../400-24px/bookmarks-fill.svg | 2 +- .../material-icons/400-24px/bookmarks.svg | 2 +- .../400-24px/headphones-fill.svg | 1 + .../material-icons/400-24px/headphones.svg | 1 + .../400-24px/manufacturing-fill.svg | 1 + .../material-icons/400-24px/manufacturing.svg | 2 +- .../material-icons/400-24px/movie-fill.svg | 1 + .../material-icons/400-24px/movie.svg | 1 + .../400-24px/quiet_time-fill.svg | 2 +- .../material-icons/400-24px/quiet_time.svg | 2 +- .../material-icons/400-24px/share-fill.svg | 2 +- .../material-icons/400-24px/share.svg | 2 +- .../styles/mastodon/components.scss | 99 +++++---- app/javascript/styles/mastodon/variables.scss | 2 + 27 files changed, 330 insertions(+), 245 deletions(-) delete mode 100644 app/javascript/mastodon/features/account_gallery/components/media_item.jsx create mode 100644 app/javascript/mastodon/features/account_gallery/components/media_item.tsx create mode 100644 app/javascript/material-icons/400-24px/headphones-fill.svg create mode 100644 app/javascript/material-icons/400-24px/headphones.svg create mode 100644 app/javascript/material-icons/400-24px/manufacturing-fill.svg create mode 100644 app/javascript/material-icons/400-24px/movie-fill.svg create mode 100644 app/javascript/material-icons/400-24px/movie.svg diff --git a/app/javascript/mastodon/components/media_gallery.jsx b/app/javascript/mastodon/components/media_gallery.jsx index ba54b7f9036..35924008b5e 100644 --- a/app/javascript/mastodon/components/media_gallery.jsx +++ b/app/javascript/mastodon/components/media_gallery.jsx @@ -11,6 +11,7 @@ import ImmutablePropTypes from 'react-immutable-proptypes'; import { debounce } from 'lodash'; import { Blurhash } from 'mastodon/components/blurhash'; +import { formatTime } from 'mastodon/features/video'; import { autoPlayGif, displayMedia, useBlurhash } from '../initial_state'; @@ -57,7 +58,7 @@ class Item extends PureComponent { hoverToPlay () { const { attachment } = this.props; - return !this.getAutoPlay() && attachment.get('type') === 'gifv'; + return !this.getAutoPlay() && ['gifv', 'video'].includes(attachment.get('type')); } handleClick = (e) => { @@ -150,10 +151,15 @@ class Item extends PureComponent { /> ); - } else if (attachment.get('type') === 'gifv') { + } else if (['gifv', 'video'].includes(attachment.get('type'))) { const autoPlay = this.getAutoPlay(); + const duration = attachment.getIn(['meta', 'original', 'duration']); - badges.push(GIF); + if (attachment.get('type') === 'gifv') { + badges.push(GIF); + } else { + badges.push({formatTime(Math.floor(duration))}); + } thumbnail = (
@@ -167,6 +173,7 @@ class Item extends PureComponent { onClick={this.handleClick} onMouseEnter={this.handleMouseEnter} onMouseLeave={this.handleMouseLeave} + onLoadedData={this.handleImageLoad} autoPlay={autoPlay} playsInline loop diff --git a/app/javascript/mastodon/components/status.jsx b/app/javascript/mastodon/components/status.jsx index 6c32fd245d7..46926b4aaea 100644 --- a/app/javascript/mastodon/components/status.jsx +++ b/app/javascript/mastodon/components/status.jsx @@ -449,7 +449,25 @@ class Status extends ImmutablePureComponent { } else if (status.get('media_attachments').size > 0) { const language = status.getIn(['translation', 'language']) || status.get('language'); - if (status.getIn(['media_attachments', 0, 'type']) === 'audio') { + if (['image', 'gifv'].includes(status.getIn(['media_attachments', 0, 'type'])) || status.get('media_attachments').size > 1) { + media = ( + + {Component => ( + + )} + + ); + } else if (status.getIn(['media_attachments', 0, 'type']) === 'audio') { const attachment = status.getIn(['media_attachments', 0]); const description = attachment.getIn(['translation', 'description']) || attachment.get('description'); @@ -501,24 +519,6 @@ class Status extends ImmutablePureComponent { )} ); - } else { - media = ( - - {Component => ( - - )} - - ); } } else if (status.get('spoiler_text').length === 0 && status.get('card')) { media = ( diff --git a/app/javascript/mastodon/features/account_gallery/components/media_item.jsx b/app/javascript/mastodon/features/account_gallery/components/media_item.jsx deleted file mode 100644 index 087e7757533..00000000000 --- a/app/javascript/mastodon/features/account_gallery/components/media_item.jsx +++ /dev/null @@ -1,158 +0,0 @@ -import PropTypes from 'prop-types'; - -import classNames from 'classnames'; - -import ImmutablePropTypes from 'react-immutable-proptypes'; -import ImmutablePureComponent from 'react-immutable-pure-component'; - -import AudiotrackIcon from '@/material-icons/400-24px/music_note.svg?react'; -import PlayArrowIcon from '@/material-icons/400-24px/play_arrow.svg?react'; -import VisibilityOffIcon from '@/material-icons/400-24px/visibility_off.svg?react'; -import { Blurhash } from 'mastodon/components/blurhash'; -import { Icon } from 'mastodon/components/icon'; -import { autoPlayGif, displayMedia, useBlurhash } from 'mastodon/initial_state'; - -export default class MediaItem extends ImmutablePureComponent { - - static propTypes = { - attachment: ImmutablePropTypes.map.isRequired, - displayWidth: PropTypes.number.isRequired, - onOpenMedia: PropTypes.func.isRequired, - }; - - state = { - visible: displayMedia !== 'hide_all' && !this.props.attachment.getIn(['status', 'sensitive']) || displayMedia === 'show_all', - loaded: false, - }; - - handleImageLoad = () => { - this.setState({ loaded: true }); - }; - - handleMouseEnter = e => { - if (this.hoverToPlay()) { - e.target.play(); - } - }; - - handleMouseLeave = e => { - if (this.hoverToPlay()) { - e.target.pause(); - e.target.currentTime = 0; - } - }; - - hoverToPlay () { - return !autoPlayGif && ['gifv', 'video'].indexOf(this.props.attachment.get('type')) !== -1; - } - - handleClick = e => { - if (e.button === 0 && !(e.ctrlKey || e.metaKey)) { - e.preventDefault(); - - if (this.state.visible) { - this.props.onOpenMedia(this.props.attachment); - } else { - this.setState({ visible: true }); - } - } - }; - - render () { - const { attachment, displayWidth } = this.props; - const { visible, loaded } = this.state; - - const width = `${Math.floor((displayWidth - 4) / 3) - 4}px`; - const height = width; - const status = attachment.get('status'); - const title = status.get('spoiler_text') || attachment.get('description'); - - let thumbnail, label, icon, content; - - if (!visible) { - icon = ( - - - - ); - } else { - if (['audio', 'video'].includes(attachment.get('type'))) { - content = ( - {attachment.get('description')} - ); - - if (attachment.get('type') === 'audio') { - label = ; - } else { - label = ; - } - } else if (attachment.get('type') === 'image') { - const focusX = attachment.getIn(['meta', 'focus', 'x']) || 0; - const focusY = attachment.getIn(['meta', 'focus', 'y']) || 0; - const x = ((focusX / 2) + .5) * 100; - const y = ((focusY / -2) + .5) * 100; - - content = ( - {attachment.get('description')} - ); - } else if (attachment.get('type') === 'gifv') { - content = ( -