mattermost-mobile/app/screens/more_dms/selected_users/selected_users.js
Elias Nahum 9f238d5ef4
Post List & post components refactored (#5409)
* Update transform to make Android's post list scroll smooth

* set start since metric when appStarted is false

* Refactor Formatted components

* Downgrade RNN to 7.13.0 & patch XCDYouTube to allow video playback

* Refactor Post list and all related components

* review suggestion rename hour12 to isMilitaryTime

* feedback review use aliases

* feedback review deconstruct actions in markdown_link

* feedback review simplify if/else statement in combined_used_activity

* Simplify if statement for consecutive posts

* Specify npm version to build iOS on CI

* Refactor network_indicator

* render Icon in file gallery with transparent background

* Increase timeout to scroll to bottom when posting a new message

* fix: scroll when tapping on the new messages bar

* fix: dismiss all modals

* fix navigation tests

* Handle dismissAllModals for iOS to prevent blank screens

* Prevent modal from dismissing when showing the thread screen in the stack

* Update app/components/image_viewport.tsx

Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>

* Update app/utils/post.ts

Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>

* fix: rename selector and prop

* Fix XCDYouTube patch

* Fix posting from a thread in the right channel

* do not render reply bar on the thread screen

* close previous permalink before showing a new one

* move XCDYouTube patch to ios/patches folder

* closePermalink directly instead of using an onClose prop

Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>
Co-authored-by: Miguel Alatzar <this.migbot@gmail.com>
2021-06-03 11:12:15 -07:00

139 lines
4 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import PropTypes from 'prop-types';
import React from 'react';
import {View} from 'react-native';
import FormattedText from '@components/formatted_text';
import SelectedUser from 'app/screens/more_dms/selected_users/selected_user';
import {changeOpacity, makeStyleSheetFromTheme} from 'app/utils/theme';
export default class SelectedUsers extends React.PureComponent {
static propTypes = {
/*
* The current theme.
*/
theme: PropTypes.object.isRequired,
/*
* An object mapping user ids to a falsey value indicating whether or not they've been selected.
*/
selectedIds: PropTypes.object.isRequired,
/*
* An object mapping user ids to users.
*/
profiles: PropTypes.object.isRequired,
/*
* How to display the names of users.
*/
teammateNameDisplay: PropTypes.string.isRequired,
/*
* The number of users that will be selected when we start to display a message indicating
* the remaining number of users that can be selected.
*/
warnCount: PropTypes.number.isRequired,
/*
* The maximum number of users that can be selected.
*/
maxCount: PropTypes.number.isRequired,
/*
* A handler function that will deselect a user when clicked on.
*/
onRemove: PropTypes.func.isRequired,
};
render() {
const users = [];
for (const id of Object.keys(this.props.selectedIds)) {
if (!this.props.selectedIds[id]) {
continue;
}
users.push(
<SelectedUser
key={id}
user={this.props.profiles[id]}
theme={this.props.theme}
teammateNameDisplay={this.props.teammateNameDisplay}
onRemove={this.props.onRemove}
/>,
);
}
if (users.length === 0) {
return null;
}
const style = getStyleFromTheme(this.props.theme);
let message = null;
if (users.length >= this.props.maxCount) {
message = (
<FormattedText
style={style.message}
id='mobile.more_dms.cannot_add_more'
defaultMessage='You cannot add more users'
/>
);
} else if (users.length >= this.props.warnCount) {
const remaining = this.props.maxCount - users.length;
if (remaining === 1) {
message = (
<FormattedText
style={style.message}
id='mobile.more_dms.one_more'
defaultMessage='You can add 1 more user'
/>
);
} else {
message = (
<FormattedText
style={style.message}
id='mobile.more_dms.add_more'
defaultMessage='You can add {remaining, number} more users'
values={{
remaining,
}}
/>
);
}
}
return (
<View style={style.container}>
<View style={style.users}>
{users}
</View>
{message}
</View>
);
}
}
const getStyleFromTheme = makeStyleSheetFromTheme((theme) => {
return {
container: {
marginLeft: 5,
marginBottom: 5,
},
users: {
alignItems: 'flex-start',
flexDirection: 'row',
flexWrap: 'wrap',
},
message: {
color: changeOpacity(theme.centerChannelColor, 0.6),
fontSize: 12,
marginRight: 5,
marginTop: 10,
marginBottom: 2,
},
};
});