From d19d6be716a7676e0fa0c971054ffefadef5ee3a Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Wed, 12 Dec 2018 09:34:41 -0300 Subject: [PATCH] Fix edit profile image (#2448) --- app/components/attachment_button.js | 31 +++++++++++++----------- app/screens/edit_profile/edit_profile.js | 20 +++++++++++++-- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/app/components/attachment_button.js b/app/components/attachment_button.js index 37be60462..eddf52718 100644 --- a/app/components/attachment_button.js +++ b/app/components/attachment_button.js @@ -28,7 +28,8 @@ export default class AttachmentButton extends PureComponent { blurTextBox: PropTypes.func.isRequired, browseFileTypes: PropTypes.string, canBrowseFiles: PropTypes.bool, - canBrowseLibrary: PropTypes.bool, + canBrowsePhotoLibrary: PropTypes.bool, + canBrowseVideoLibrary: PropTypes.bool, canTakePhoto: PropTypes.bool, canTakeVideo: PropTypes.bool, children: PropTypes.node, @@ -46,7 +47,8 @@ export default class AttachmentButton extends PureComponent { static defaultProps = { browseFileTypes: Platform.OS === 'ios' ? 'public.item' : '*/*', canBrowseFiles: true, - canBrowseLibrary: true, + canBrowsePhotoLibrary: true, + canBrowseVideoLibrary: true, canTakePhoto: true, canTakeVideo: true, maxFileCount: 5, @@ -342,7 +344,8 @@ export default class AttachmentButton extends PureComponent { showFileAttachmentOptions = () => { const { canBrowseFiles, - canBrowseLibrary, + canBrowsePhotoLibrary, + canBrowseVideoLibrary, canTakePhoto, canTakeVideo, fileCount, @@ -380,7 +383,7 @@ export default class AttachmentButton extends PureComponent { }); } - if (canBrowseLibrary) { + if (canBrowsePhotoLibrary) { items.push({ action: () => this.handleFileAttachmentOption(this.attachFileFromLibrary), text: { @@ -389,17 +392,17 @@ export default class AttachmentButton extends PureComponent { }, icon: 'photo', }); + } - if (Platform.OS === 'android') { - items.push({ - action: () => this.handleFileAttachmentOption(this.attachVideoFromLibraryAndroid), - text: { - id: t('mobile.file_upload.video'), - defaultMessage: 'Video Library', - }, - icon: 'file-video-o', - }); - } + if (canBrowseVideoLibrary && Platform.OS === 'android') { + items.push({ + action: () => this.handleFileAttachmentOption(this.attachVideoFromLibraryAndroid), + text: { + id: t('mobile.file_upload.video'), + defaultMessage: 'Video Library', + }, + icon: 'file-video-o', + }); } if (canBrowseFiles) { diff --git a/app/screens/edit_profile/edit_profile.js b/app/screens/edit_profile/edit_profile.js index d172b52e7..5ca9a7f34 100644 --- a/app/screens/edit_profile/edit_profile.js +++ b/app/screens/edit_profile/edit_profile.js @@ -4,7 +4,7 @@ import React, {PureComponent} from 'react'; import PropTypes from 'prop-types'; import {intlShape} from 'react-intl'; -import {View} from 'react-native'; +import {Alert, View} from 'react-native'; import RNFetchBlob from 'rn-fetch-blob'; import {KeyboardAwareScrollView} from 'react-native-keyboard-aware-scroll-view'; import {DocumentPickerUtil} from 'react-native-document-picker'; @@ -25,8 +25,9 @@ import ProfilePicture from 'app/components/profile_picture'; import AttachmentButton from 'app/components/attachment_button'; import mattermostBucket from 'app/mattermost_bucket'; import LocalConfig from 'assets/config'; +import {getFormattedFileSize} from 'mattermost-redux/utils/file_utils'; -const MAX_SIZE = 20 * 1024; +const MAX_SIZE = 20 * 1024 * 1024; const holders = { firstName: { id: t('user.settings.general.firstName'), @@ -242,6 +243,19 @@ export default class EditProfile extends PureComponent { } }; + onShowFileSizeWarning = (filename) => { + const {formatMessage} = this.context.intl; + const fileSizeWarning = formatMessage({ + id: 'file_upload.fileAbove', + defaultMessage: 'File above {max}MB cannot be uploaded: {filename}', + }, { + max: getFormattedFileSize({size: MAX_SIZE}), + filename, + }); + + Alert.alert(fileSizeWarning); + }; + renderFirstNameSettings = () => { const {formatMessage} = this.context.intl; const {config, currentUser, theme} = this.props; @@ -492,11 +506,13 @@ export default class EditProfile extends PureComponent { blurTextBox={emptyFunction} browseFileTypes={DocumentPickerUtil.images()} canTakeVideo={false} + canBrowseVideoLibrary={false} maxFileSize={MAX_SIZE} theme={theme} navigator={navigator} wrapper={true} uploadFiles={this.handleUploadProfileImage} + onShowFileSizeWarning={this.onShowFileSizeWarning} >