Skip to content

Commit

Permalink
Merge pull request #6061 from kakajann/add-tooltip-for-user-avatar
Browse files Browse the repository at this point in the history
Add a tooltip for profile avatar and online status icon
  • Loading branch information
mountiny authored Nov 1, 2021
2 parents 973dcf4 + 899d640 commit 0c44613
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 28 deletions.
60 changes: 45 additions & 15 deletions src/components/AvatarWithIndicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import styles from '../styles/styles';
import Icon from './Icon';
import {Sync} from './Icon/Expensicons';
import SpinningIndicatorAnimation from '../styles/animation/SpinningIndicatorAnimation';
import Tooltip from './Tooltip';
import withLocalize, {withLocalizePropTypes} from './withLocalize';

const propTypes = {
/** Is user active? */
Expand All @@ -22,12 +24,18 @@ const propTypes = {

// Whether we show the sync indicator
isSyncing: PropTypes.bool,

/** To show a tooltip on hover */
tooltipText: PropTypes.string,

...withLocalizePropTypes,
};

const defaultProps = {
isActive: false,
size: 'default',
isSyncing: false,
tooltipText: '',
};

class AvatarWithIndicator extends PureComponent {
Expand Down Expand Up @@ -55,6 +63,24 @@ class AvatarWithIndicator extends PureComponent {
this.animation.stop();
}

/**
* Returns user status as text
*
* @returns {String}
*/
userStatus() {
if (this.props.isSyncing) {
return this.props.translate('profilePage.syncing');
}

if (this.props.isActive) {
return this.props.translate('profilePage.online');
}

if (!this.props.isActive) {
return this.props.translate('profilePage.offline');
}
}

render() {
const indicatorStyles = [
Expand All @@ -69,25 +95,29 @@ class AvatarWithIndicator extends PureComponent {
<View
style={[this.props.size === 'large' ? styles.avatarLarge : styles.sidebarAvatar]}
>
<Avatar
imageStyles={[this.props.size === 'large' ? styles.avatarLarge : null]}
source={this.props.source}
/>
<Animated.View style={StyleSheet.flatten(indicatorStyles)}>
{this.props.isSyncing && (
<Icon
src={Sync}
fill={themeColors.textReversed}
width={6}
height={6}
/>
)}
</Animated.View>
<Tooltip text={this.props.tooltipText}>
<Avatar
imageStyles={[this.props.size === 'large' ? styles.avatarLarge : null]}
source={this.props.source}
/>
</Tooltip>
<Tooltip text={this.userStatus()} absolute>
<Animated.View style={StyleSheet.flatten(indicatorStyles)}>
{this.props.isSyncing && (
<Icon
src={Sync}
fill={themeColors.textReversed}
width={6}
height={6}
/>
)}
</Animated.View>
</Tooltip>
</View>
);
}
}

AvatarWithIndicator.defaultProps = defaultProps;
AvatarWithIndicator.propTypes = propTypes;
export default AvatarWithIndicator;
export default withLocalize(AvatarWithIndicator);
3 changes: 3 additions & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ export default {
setMyTimezoneAutomatically: 'Set my timezone automatically',
timezone: 'Timezone',
growlMessageOnSave: 'Your profile was successfully saved',
online: 'Online',
offline: 'Offline',
syncing: 'Syncing',
},
addSecondaryLoginPage: {
addPhoneNumber: 'Add phone number',
Expand Down
3 changes: 3 additions & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ export default {
setMyTimezoneAutomatically: 'Configura mi zona horaria automáticamente',
timezone: 'Zona horaria',
growlMessageOnSave: 'Tu perfil se ha guardado correctamente',
online: 'En línea',
offline: 'Desconectado',
syncing: 'Sincronizando',
},
addSecondaryLoginPage: {
addPhoneNumber: 'Agregar número de teléfono',
Expand Down
25 changes: 12 additions & 13 deletions src/pages/home/sidebar/SidebarLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,19 +213,18 @@ class SidebarLinks extends React.Component {
<Icon src={MagnifyingGlass} />
</TouchableOpacity>
</Tooltip>
<Tooltip text={this.props.translate('common.settings')}>
<TouchableOpacity
accessibilityLabel={this.props.translate('sidebarScreen.buttonMySettings')}
accessibilityRole="button"
onPress={this.props.onAvatarClick}
>
<AvatarWithIndicator
source={this.props.myPersonalDetails.avatar}
isActive={this.props.network && !this.props.network.isOffline}
isSyncing={this.props.network && !this.props.network.isOffline && this.props.isSyncingData}
/>
</TouchableOpacity>
</Tooltip>
<TouchableOpacity
accessibilityLabel={this.props.translate('sidebarScreen.buttonMySettings')}
accessibilityRole="button"
onPress={this.props.onAvatarClick}
>
<AvatarWithIndicator
source={this.props.myPersonalDetails.avatar}
isActive={this.props.network && !this.props.network.isOffline}
isSyncing={this.props.network && !this.props.network.isOffline && this.props.isSyncingData}
tooltipText={this.props.myPersonalDetails.displayName}
/>
</TouchableOpacity>
</View>
<OptionsList
contentContainerStyles={[
Expand Down
1 change: 1 addition & 0 deletions src/pages/settings/InitialPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ const InitialSettingsPage = ({
size="large"
source={myPersonalDetails.avatar}
isActive={network.isOffline === false}
tooltipText={myPersonalDetails.displayName}
/>
</Pressable>

Expand Down

0 comments on commit 0c44613

Please sign in to comment.