Merge branch 'conditional-attachments' into 'develop'
Compose: pull accept content types from backend if available, fallback to all types See merge request soapbox-pub/soapbox-fe!835
This commit is contained in:
commit
e64afb5d40
|
@ -10,9 +10,13 @@ const messages = defineMessages({
|
||||||
upload: { id: 'upload_button.label', defaultMessage: 'Add media attachment' },
|
upload: { id: 'upload_button.label', defaultMessage: 'Add media attachment' },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const onlyImages = types => {
|
||||||
|
return Boolean(types && types.every(type => type.startsWith('image/')));
|
||||||
|
};
|
||||||
|
|
||||||
const makeMapStateToProps = () => {
|
const makeMapStateToProps = () => {
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
acceptContentTypes: state.getIn(['media_attachments', 'accept_content_types']),
|
attachmentTypes: state.getIn(['instance', 'configuration', 'media_attachments', 'supported_mime_types']),
|
||||||
});
|
});
|
||||||
|
|
||||||
return mapStateToProps;
|
return mapStateToProps;
|
||||||
|
@ -28,7 +32,7 @@ class UploadButton extends ImmutablePureComponent {
|
||||||
onSelectFile: PropTypes.func.isRequired,
|
onSelectFile: PropTypes.func.isRequired,
|
||||||
style: PropTypes.object,
|
style: PropTypes.object,
|
||||||
resetFileKey: PropTypes.number,
|
resetFileKey: PropTypes.number,
|
||||||
acceptContentTypes: ImmutablePropTypes.listOf(PropTypes.string).isRequired,
|
attachmentTypes: ImmutablePropTypes.listOf(PropTypes.string),
|
||||||
intl: PropTypes.object.isRequired,
|
intl: PropTypes.object.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -47,17 +51,21 @@ class UploadButton extends ImmutablePureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { intl, resetFileKey, unavailable, disabled } = this.props;
|
const { intl, resetFileKey, attachmentTypes, unavailable, disabled } = this.props;
|
||||||
|
|
||||||
if (unavailable) {
|
if (unavailable) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const src = onlyImages(attachmentTypes)
|
||||||
|
? require('@tabler/icons/icons/photo.svg')
|
||||||
|
: require('@tabler/icons/icons/paperclip.svg');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='compose-form__upload-button'>
|
<div className='compose-form__upload-button'>
|
||||||
<IconButton
|
<IconButton
|
||||||
className='compose-form__upload-button-icon'
|
className='compose-form__upload-button-icon'
|
||||||
src={require('@tabler/icons/icons/paperclip.svg')}
|
src={src}
|
||||||
title={intl.formatMessage(messages.upload)}
|
title={intl.formatMessage(messages.upload)}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
onClick={this.handleClick}
|
onClick={this.handleClick}
|
||||||
|
@ -69,8 +77,7 @@ class UploadButton extends ImmutablePureComponent {
|
||||||
ref={this.setRef}
|
ref={this.setRef}
|
||||||
type='file'
|
type='file'
|
||||||
multiple
|
multiple
|
||||||
// Accept all types for now.
|
accept={attachmentTypes && attachmentTypes.toArray().join(',')}
|
||||||
// accept={acceptContentTypes.toArray().join(',')}
|
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
style={{ display: 'none' }}
|
style={{ display: 'none' }}
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
import reducer from '../media_attachments';
|
|
||||||
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
|
||||||
|
|
||||||
describe('media_attachments reducer', () => {
|
|
||||||
it('should return the initial state', () => {
|
|
||||||
expect(reducer(undefined, {})).toEqual(ImmutableMap({
|
|
||||||
accept_content_types: ImmutableList([
|
|
||||||
'.jpg',
|
|
||||||
'.jpeg',
|
|
||||||
'.png',
|
|
||||||
'.gif',
|
|
||||||
'.webp',
|
|
||||||
'.webm',
|
|
||||||
'.mp4',
|
|
||||||
'.m4v',
|
|
||||||
'.mov',
|
|
||||||
'.mp3',
|
|
||||||
'.ogg',
|
|
||||||
'.wav',
|
|
||||||
'image/jpeg',
|
|
||||||
'image/png',
|
|
||||||
'image/gif',
|
|
||||||
'image/webp',
|
|
||||||
'video/webm',
|
|
||||||
'video/mp4',
|
|
||||||
'video/quicktime',
|
|
||||||
'audio/mp3',
|
|
||||||
'audio/mpeg',
|
|
||||||
'audio/ogg',
|
|
||||||
'audio/wav',
|
|
||||||
]),
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -20,7 +20,6 @@ import reports from './reports';
|
||||||
import contexts from './contexts';
|
import contexts from './contexts';
|
||||||
import compose from './compose';
|
import compose from './compose';
|
||||||
import search from './search';
|
import search from './search';
|
||||||
import media_attachments from './media_attachments';
|
|
||||||
import notifications from './notifications';
|
import notifications from './notifications';
|
||||||
import height_cache from './height_cache';
|
import height_cache from './height_cache';
|
||||||
import custom_emojis from './custom_emojis';
|
import custom_emojis from './custom_emojis';
|
||||||
|
@ -76,7 +75,6 @@ const appReducer = combineReducers({
|
||||||
contexts,
|
contexts,
|
||||||
compose,
|
compose,
|
||||||
search,
|
search,
|
||||||
media_attachments,
|
|
||||||
notifications,
|
notifications,
|
||||||
height_cache,
|
height_cache,
|
||||||
custom_emojis,
|
custom_emojis,
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
import {
|
|
||||||
Map as ImmutableMap,
|
|
||||||
List as ImmutableList,
|
|
||||||
} from 'immutable';
|
|
||||||
|
|
||||||
const initialState = ImmutableMap({
|
|
||||||
// FIXME: Leave this empty and pull from backend
|
|
||||||
accept_content_types: ImmutableList([
|
|
||||||
'.jpg',
|
|
||||||
'.jpeg',
|
|
||||||
'.png',
|
|
||||||
'.gif',
|
|
||||||
'.webp',
|
|
||||||
'.webm',
|
|
||||||
'.mp4',
|
|
||||||
'.m4v',
|
|
||||||
'.mov',
|
|
||||||
'.mp3',
|
|
||||||
'.ogg',
|
|
||||||
'.wav',
|
|
||||||
'image/jpeg',
|
|
||||||
'image/png',
|
|
||||||
'image/gif',
|
|
||||||
'image/webp',
|
|
||||||
'video/webm',
|
|
||||||
'video/mp4',
|
|
||||||
'video/quicktime',
|
|
||||||
'audio/mp3',
|
|
||||||
'audio/mpeg',
|
|
||||||
'audio/ogg',
|
|
||||||
'audio/wav',
|
|
||||||
]),
|
|
||||||
});
|
|
||||||
|
|
||||||
export default function meta(state = initialState, action) {
|
|
||||||
switch(action.type) {
|
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue