Show file icon and name for other file types

Currently the media preview looks blank when the file type is anything
other than an image, video or audio. This commit inserts a generic file
icon and also a label with the filename for these other extensions.
better-thread-display
Bárbara de Castro Fernandes 2020-09-06 16:08:09 -03:00
rodzic 961b4711c4
commit 01667a005e
2 zmienionych plików z 15 dodań i 0 usunięć

Wyświetl plik

@ -142,11 +142,25 @@ class Item extends React.PureComponent {
let thumbnail = ''; let thumbnail = '';
const MAX_FILENAME_LENGTH = 45;
const getCroppedFilename = () => {
const remoteURL = attachment.get('remote_url');
const filenameLastIndex = remoteURL.lastIndexOf('/');
const filename = remoteURL.substr(filenameLastIndex + 1);
if (filename.length <= MAX_FILENAME_LENGTH)
return filename;
else
return filename.substr(0, MAX_FILENAME_LENGTH/2) + '...' + filename.substr(filename.length - MAX_FILENAME_LENGTH/2);
};
if (attachment.get('type') === 'unknown') { if (attachment.get('type') === 'unknown') {
const filename = getCroppedFilename();
return ( return (
<div className={classNames('media-gallery__item', { standalone })} key={attachment.get('id')} style={{ position, float, left, top, right, bottom, height, width: `${width}%` }}> <div className={classNames('media-gallery__item', { standalone })} key={attachment.get('id')} style={{ position, float, left, top, right, bottom, height, width: `${width}%` }}>
<a className='media-gallery__item-thumbnail' href={attachment.get('remote_url')} target='_blank' style={{ cursor: 'pointer' }}> <a className='media-gallery__item-thumbnail' href={attachment.get('remote_url')} target='_blank' style={{ cursor: 'pointer' }}>
<canvas width={32} height={32} ref={this.setCanvasRef} className='media-gallery__preview' /> <canvas width={32} height={32} ref={this.setCanvasRef} className='media-gallery__preview' />
<span className='media-gallery__item__icons'><Icon id='file' /></span>
<span className='media-gallery__filename__label'>{filename}</span>
</a> </a>
</div> </div>
); );

Wyświetl plik

@ -134,6 +134,7 @@
} }
.media-gallery__gifv__label, .media-gallery__gifv__label,
.media-gallery__filename__label,
.media-gallery__file-extension__label { .media-gallery__file-extension__label {
display: block; display: block;
position: absolute; position: absolute;