Merge pull request #399 from ThibG/glitch-soc/features/attachments-list

Port attachment lists to glitch-soc flavour
signup-info-prompt
David Yip 2018-03-27 10:20:52 -05:00 committed by GitHub
commit 6af17b79c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 89 additions and 47 deletions

View File

@ -1,5 +1,6 @@
import React from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
import PropTypes from 'prop-types';
import ImmutablePureComponent from 'react-immutable-pure-component';
const filename = url => url.split('/').pop().split('#')[0].split('?')[0];
@ -8,10 +9,29 @@ export default class AttachmentList extends ImmutablePureComponent {
static propTypes = {
media: ImmutablePropTypes.list.isRequired,
compact: PropTypes.bool,
};
render () {
const { media } = this.props;
const { media, compact } = this.props;
if (compact) {
return (
<div className='attachment-list compact'>
<ul className='attachment-list__list'>
{media.map(attachment => {
const displayUrl = attachment.get('remote_url') || attachment.get('url');
return (
<li key={attachment.get('id')}>
<a href={displayUrl} target='_blank' rel='noopener'><i className='fa fa-link' /> {filename(displayUrl)}</a>
</li>
);
})}
</ul>
</div>
);
}
return (
<div className='attachment-list'>
@ -20,11 +40,13 @@ export default class AttachmentList extends ImmutablePureComponent {
</div>
<ul className='attachment-list__list'>
{media.map(attachment =>
(<li key={attachment.get('id')}>
<a href={attachment.get('remote_url')} target='_blank' rel='noopener'>{filename(attachment.get('remote_url'))}</a>
const displayUrl = attachment.get('remote_url') || attachment.get('url');
{media.map(attachment => {
return (<li key={attachment.get('id')}>
<a href={displayUrl} target='_blank' rel='noopener'>{filename(displayUrl)}</a>
</li>)
)}
})}
</ul>
</div>
);

View File

@ -6,6 +6,7 @@ import StatusHeader from './status_header';
import StatusIcons from './status_icons';
import StatusContent from './status_content';
import StatusActionBar from './status_action_bar';
import AttachmentList from './attachment_list';
import ImmutablePureComponent from 'react-immutable-pure-component';
import { MediaGallery, Video } from 'flavours/glitch/util/async-components';
import { HotKeys } from 'react-hotkeys';
@ -301,17 +302,22 @@ export default class Status extends ImmutablePureComponent {
background = status.getIn(['account', 'header']);
}
// This handles our media attachments. Note that we don't show media on
// muted (notification) statuses. If the media type is unknown, then we
// simply ignore it.
// This handles our media attachments.
// If a media file is of unknwon type or if the status is muted
// (notification), we show a list of links instead of embedded media.
// After we have generated our appropriate media element and stored it in
// `media`, we snatch the thumbnail to use as our `background` if media
// backgrounds for collapsed statuses are enabled.
attachments = status.get('media_attachments');
if (attachments.size > 0 && !muted) {
if (attachments.some(item => item.get('type') === 'unknown')) { // Media type is 'unknown'
/* Do nothing */
if (attachments.size > 0) {
if (muted || attachments.some(item => item.get('type') === 'unknown')) {
media = (
<AttachmentList
compact
media={status.get('media_attachments')}
/>
);
} else if (attachments.getIn([0, 'type']) === 'video') { // Media type is 'video'
const video = status.getIn(['media_attachments', 0]);

View File

@ -5,9 +5,8 @@
border-radius: 4px;
margin-top: 14px;
overflow: hidden;
}
.attachment-list__icon {
&__icon {
flex: 0 0 auto;
color: $ui-base-lighter-color;
padding: 8px 18px;
@ -22,9 +21,9 @@
.fa {
display: block;
}
}
}
.attachment-list__list {
&__list {
list-style: none;
padding: 4px 0;
padding-left: 8px;
@ -46,6 +45,21 @@
text-decoration: underline;
}
}
}
&.compact {
border: 0;
margin-top: 4px;
.attachment-list__list {
padding: 0;
display: block;
}
.fa {
color: $ui-base-lighter-color;
}
}
}
.list-editor {