-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15671 from margelo/hanno/feat-tolltip-reaction-se…
…nders [web/desktop] feat: tooltip reaction senders
- Loading branch information
Showing
9 changed files
with
165 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React from 'react'; | ||
import {View} from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
import _ from 'underscore'; | ||
import styles from '../../styles/styles'; | ||
import {withPersonalDetails} from '../OnyxProvider'; | ||
import * as PersonalDetailsUtils from '../../libs/PersonalDetailsUtils'; | ||
import Text from '../Text'; | ||
import withCurrentUserPersonalDetails, { | ||
withCurrentUserPersonalDetailsPropTypes, | ||
} from '../withCurrentUserPersonalDetails'; | ||
import compose from '../../libs/compose'; | ||
import withLocalize from '../withLocalize'; | ||
|
||
const propTypes = { | ||
/** | ||
* A list of emoji codes to display in the tooltip. | ||
*/ | ||
emojiCodes: PropTypes.arrayOf(PropTypes.string).isRequired, | ||
|
||
/** | ||
* The name of the emoji to display in the tooltip. | ||
*/ | ||
emojiName: PropTypes.string.isRequired, | ||
|
||
/** | ||
* A list of account IDs to display in the tooltip. | ||
*/ | ||
accountIDs: PropTypes.arrayOf(PropTypes.string).isRequired, | ||
|
||
...withCurrentUserPersonalDetailsPropTypes, | ||
}; | ||
|
||
const ReactionTooltipContent = (props) => { | ||
const users = PersonalDetailsUtils.getPersonalDetailsByIDs(props.accountIDs, true); | ||
const namesString = _.filter(_.map(users, user => user && user.displayName), n => n).join(', '); | ||
|
||
return ( | ||
<View style={[styles.alignItemsCenter, styles.ph2]}> | ||
<View style={styles.flexRow}> | ||
{_.map(props.emojiCodes, emojiCode => ( | ||
<Text | ||
key={emojiCode} | ||
style={styles.reactionEmojiTitle} | ||
> | ||
{emojiCode} | ||
</Text> | ||
))} | ||
</View> | ||
|
||
<Text style={[ | ||
styles.mt1, | ||
styles.textMicroBold, | ||
styles.textReactionSenders, | ||
]} | ||
> | ||
{namesString} | ||
</Text> | ||
|
||
<Text style={[ | ||
styles.textMicro, | ||
styles.fontColorReactionLabel, | ||
]} | ||
> | ||
{`reacted with :${props.emojiName}:`} | ||
</Text> | ||
</View> | ||
); | ||
}; | ||
|
||
ReactionTooltipContent.propTypes = propTypes; | ||
ReactionTooltipContent.defaultProps = withCurrentUserPersonalDetails; | ||
ReactionTooltipContent.displayName = 'ReactionTooltipContent'; | ||
export default React.memo(compose( | ||
withPersonalDetails(), | ||
withLocalize, | ||
)(ReactionTooltipContent)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import Onyx from 'react-native-onyx'; | ||
import _ from 'underscore'; | ||
import ONYXKEYS from '../ONYXKEYS'; | ||
import * as Report from './actions/Report'; | ||
import * as Localize from './Localize'; | ||
|
||
let personalDetails = []; | ||
Onyx.connect({ | ||
key: ONYXKEYS.PERSONAL_DETAILS, | ||
callback: val => personalDetails = _.values(val), | ||
}); | ||
|
||
/** | ||
* Given a list of account IDs (as string) it will return an array of personal details objects. | ||
* @param {Array<string>} accountIDs - Array of accountIDs | ||
* @param {boolean} shouldChangeUserDisplayName - It will replace the current user's personal detail object's displayName with 'You'. | ||
* @returns {Array} - Array of personal detail objects | ||
*/ | ||
function getPersonalDetailsByIDs(accountIDs, shouldChangeUserDisplayName = false) { | ||
const result = []; | ||
const currentAccountID = Report.getCurrentUserAccountID(); | ||
_.each(personalDetails, (detail) => { | ||
for (let i = 0; i < accountIDs.length; i++) { | ||
if (detail.accountID === accountIDs[i]) { | ||
if (shouldChangeUserDisplayName && currentAccountID.toString() === detail.accountID) { | ||
result[i] = { | ||
...detail, | ||
displayName: Localize.translateLocal('common.you'), | ||
}; | ||
} else { | ||
result[i] = detail; | ||
} | ||
break; | ||
} | ||
} | ||
}); | ||
return result; | ||
} | ||
|
||
export { | ||
// eslint-disable-next-line import/prefer-default-export | ||
getPersonalDetailsByIDs, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters