mattermost-mobile/app/components/channel_icon.tsx
Mattermost Build a60d3eeb92
MM-34407 Use Avatars for Sidebar DMs (#5334) (#5358)
* MM-34407 Use Avatars for Sidebar DMs

* Update app/components/channel_icon.js

Co-authored-by: Joseph Baylon <joseph.baylon@mattermost.com>

* UI feedback

* Align the private channel icon

Co-authored-by: Joseph Baylon <joseph.baylon@mattermost.com>
(cherry picked from commit 1b36529853)

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2021-04-29 09:18:48 -04:00

184 lines
5.2 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {StyleProp, Text, View, ViewStyle} from 'react-native';
import CompassIcon from '@components/compass_icon';
import ProfilePicture from '@components/profile_picture';
import {General} from '@mm-redux/constants';
import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme';
import type {Theme} from '@mm-redux/types/preferences';
type Props = {
hasDraft: boolean;
isActive: boolean;
isArchived: boolean;
isInfo: boolean;
isUnread: boolean;
membersCount: number;
size: number;
statusStyle?: StyleProp<ViewStyle>;
testID?: string;
theme: Theme;
type: string;
userId?: string;
};
const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => {
return {
container: {
alignItems: 'center',
justifyContent: 'center',
},
icon: {
color: changeOpacity(theme.sidebarText, 0.4),
},
iconActive: {
color: theme.sidebarTextActiveColor,
},
iconUnread: {
color: theme.sidebarUnreadText,
},
iconInfo: {
color: theme.centerChannelColor,
},
groupBox: {
alignItems: 'center',
backgroundColor: changeOpacity(theme.sidebarText, 0.16),
borderRadius: 4,
justifyContent: 'center',
},
groupBoxActive: {
backgroundColor: changeOpacity(theme.sidebarTextActiveColor, 0.3),
},
groupBoxUnread: {
backgroundColor: changeOpacity(theme.sidebarUnreadText, 0.3),
},
groupBoxInfo: {
backgroundColor: changeOpacity(theme.centerChannelColor, 0.3),
},
group: {
color: theme.sidebarText,
fontSize: 10,
fontWeight: '600',
},
groupActive: {
color: theme.sidebarTextActiveColor,
},
groupUnread: {
color: theme.sidebarUnreadText,
},
groupInfo: {
color: theme.centerChannelColor,
},
};
});
const ChannelIcon = (props: Props) => {
const style = getStyleSheet(props.theme);
let activeIcon;
let unreadIcon;
let activeGroupBox;
let unreadGroupBox;
let activeGroup;
let unreadGroup;
if (props.isUnread) {
unreadIcon = style.iconUnread;
unreadGroupBox = style.groupBoxUnread;
unreadGroup = style.groupUnread;
}
if (props.isActive) {
activeIcon = style.iconActive;
activeGroupBox = style.groupBoxActive;
activeGroup = style.groupActive;
}
if (props.isInfo) {
activeIcon = style.iconInfo;
activeGroupBox = style.groupBoxInfo;
activeGroup = style.groupInfo;
}
let icon;
let extraStyle;
if (props.isArchived) {
icon = (
<CompassIcon
name='archive-outline'
style={[style.icon, unreadIcon, activeIcon, {fontSize: props.size, left: 1}]}
testID={`${props.testID}.archive`}
/>
);
} else if (props.hasDraft) {
icon = (
<CompassIcon
name='pencil-outline'
style={[style.icon, unreadIcon, activeIcon, {fontSize: props.size, left: 2}]}
testID={`${props.testID}.draft`}
/>
);
} else if (props.type === General.OPEN_CHANNEL) {
icon = (
<CompassIcon
name='globe'
style={[style.icon, unreadIcon, activeIcon, {fontSize: props.size, left: 1}]}
testID={`${props.testID}.public`}
/>
);
} else if (props.type === General.PRIVATE_CHANNEL) {
icon = (
<CompassIcon
name='lock-outline'
style={[style.icon, unreadIcon, activeIcon, {fontSize: props.size, left: 0.5}]}
testID={`${props.testID}.private`}
/>
);
} else if (props.type === General.GM_CHANNEL) {
const fontSize = (props.size - 12);
const boxSize = (props.size - 4);
icon = (
<View style={[style.groupBox, unreadGroupBox, activeGroupBox, {width: boxSize, height: boxSize}]}>
<Text
style={[style.group, unreadGroup, activeGroup, {fontSize}]}
testID={`${props.testID}.gm_member_count`}
>
{props.membersCount}
</Text>
</View>
);
} else if (props.type === General.DM_CHANNEL) {
// extraStyle = {marginRight: 6};
icon = (
<ProfilePicture
size={props.size}
statusSize={12}
userId={props.userId}
testID={props.testID}
statusStyle={props.statusStyle}
/>
);
}
return (
<View style={[style.container, extraStyle, {width: props.size, height: props.size}]}>
{icon}
</View>
);
};
ChannelIcon.defaultProps = {
hasDraft: false,
isActive: false,
isArchived: false,
isInfo: false,
isUnread: false,
membersCount: 0,
size: 12,
};
export default ChannelIcon;