From 66bd6c826d6db9e5476d36328a5b7959d910a4ff Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Wed, 18 Jul 2018 16:00:51 -0700 Subject: [PATCH] Fix MediaGallery handling of videos - show thumbnail and overlay --- js/views/conversation_view.js | 16 +++++-- stylesheets/_modules.scss | 34 +++++++++++++- .../media-gallery/MediaGallery.md | 9 ++-- .../media-gallery/MediaGridItem.md | 20 ++++++++- .../media-gallery/MediaGridItem.tsx | 44 +++++++++++++++---- .../media-gallery/types/Message.tsx | 5 ++- 6 files changed, 108 insertions(+), 20 deletions(-) diff --git a/js/views/conversation_view.js b/js/views/conversation_view.js index 4e0ddba8a..876deb6a8 100644 --- a/js/views/conversation_view.js +++ b/js/views/conversation_view.js @@ -623,13 +623,21 @@ } } - const media = rawMedia.map(mediaMessage => - Object.assign({}, mediaMessage, { + const media = rawMedia.map(mediaMessage => { + const { attachments } = mediaMessage; + const first = attachments && attachments[0]; + const { thumbnail } = first; + + return { + ...mediaMessage, + thumbnailObjectUrl: thumbnail + ? getAbsoluteAttachmentPath(thumbnail.path) + : null, objectURL: getAbsoluteAttachmentPath( mediaMessage.attachments[0].path ), - }) - ); + }; + }); const saveAttachment = async ({ message } = {}) => { const attachment = message.attachments[0]; diff --git a/stylesheets/_modules.scss b/stylesheets/_modules.scss index 353c3fcf1..937675c20 100644 --- a/stylesheets/_modules.scss +++ b/stylesheets/_modules.scss @@ -1806,13 +1806,45 @@ margin-right: 4px; margin-bottom: 4px; } + .module-media-grid-item__image { height: 94px; width: 94px; object-fit: cover; } -// Module: Empty State +.module-media-grid-item__image-container { + height: 94px; + width: 94px; + object-fit: cover; + position: relative; +} + +.module-media-grid-item__circle-overlay { + position: absolute; + left: 50%; + top: 50%; + + transform: translate(-50%, -50%); + + width: 42px; + height: 42px; + background-color: $color-white; + border-radius: 21px; +} + +.module-media-grid-item__play-overlay { + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + + height: 36px; + width: 36px; + @include color-svg('../images/play.svg', $color-signal-blue); +} + +/* Module: Empty State*/ .module-empty-state { display: flex; diff --git a/ts/components/conversation/media-gallery/MediaGallery.md b/ts/components/conversation/media-gallery/MediaGallery.md index 1cb8dbe85..415ce721d 100644 --- a/ts/components/conversation/media-gallery/MediaGallery.md +++ b/ts/components/conversation/media-gallery/MediaGallery.md @@ -33,13 +33,14 @@ const createRandomMessage = ({ startTime, timeWindow } = {}) => props => { data: null, fileName, size: _.random(1000, 1000 * 1000 * 50), + contentType: 'image/jpeg', }, ], - objectURL: `https://placekitten.com/${_.random(50, 150)}/${_.random( + thumbnailObjectUrl: `https://placekitten.com/${_.random( 50, 150 - )}`, + )}/${_.random(50, 150)}`, ...props, }; }; @@ -83,11 +84,11 @@ const messages = _.sortBy( const messages = [ { id: '1', - objectURL: 'https://placekitten.com/76/67', + thumbnailObjectUrl: 'https://placekitten.com/76/67', attachments: [ { fileName: 'foo.jpg', - contentType: 'application/json', + contentType: 'image/jpeg', }, ], }, diff --git a/ts/components/conversation/media-gallery/MediaGridItem.md b/ts/components/conversation/media-gallery/MediaGridItem.md index bd7e3cb0d..693945a61 100644 --- a/ts/components/conversation/media-gallery/MediaGridItem.md +++ b/ts/components/conversation/media-gallery/MediaGridItem.md @@ -3,11 +3,27 @@ ```jsx const message = { id: '1', - objectURL: 'https://placekitten.com/76/67', + thumbnailObjectUrl: 'https://placekitten.com/76/67', attachments: [ { fileName: 'foo.jpg', - contentType: 'application/json', + contentType: 'image/jpeg', + }, + ], +}; +; +``` + +## With video + +```jsx +const message = { + id: '1', + thumbnailObjectUrl: 'https://placekitten.com/76/67', + attachments: [ + { + fileName: 'foo.jpg', + contentType: 'video/mp4', }, ], }; diff --git a/ts/components/conversation/media-gallery/MediaGridItem.tsx b/ts/components/conversation/media-gallery/MediaGridItem.tsx index de113e292..0d377fca2 100644 --- a/ts/components/conversation/media-gallery/MediaGridItem.tsx +++ b/ts/components/conversation/media-gallery/MediaGridItem.tsx @@ -1,5 +1,9 @@ import React from 'react'; +import { + isImageTypeSupported, + isVideoTypeSupported, +} from '../../../util/GoogleChrome'; import { Message } from './types/Message'; import { Localizer } from '../../../types/Util'; @@ -12,18 +16,42 @@ interface Props { export class MediaGridItem extends React.Component { public renderContent() { const { message, i18n } = this.props; + const { attachments } = message; - if (!message.objectURL) { + if (!message.thumbnailObjectUrl) { + return null; + } + if (!attachments || !attachments.length) { return null; } - return ( - {i18n('lightboxImageAlt')} - ); + const first = attachments[0]; + const { contentType } = first; + + if (contentType && isImageTypeSupported(contentType)) { + return ( + {i18n('lightboxImageAlt')} + ); + } else if (contentType && isVideoTypeSupported(contentType)) { + return ( +
+ {i18n('lightboxImageAlt')} +
+
+
+
+ ); + } + + return null; } public render() { diff --git a/ts/components/conversation/media-gallery/types/Message.tsx b/ts/components/conversation/media-gallery/types/Message.tsx index c8dbca3ae..94101a9ef 100644 --- a/ts/components/conversation/media-gallery/types/Message.tsx +++ b/ts/components/conversation/media-gallery/types/Message.tsx @@ -10,7 +10,10 @@ export type Message = { id: string; attachments: Array; received_at: number; -} & { objectURL?: string }; +} & { + thumbnailObjectUrl?: string; + objectURL?: string; +}; export const loadWithObjectURL = (loadMessage: MapAsync) => async ( messages: Array