refactor avatar component
This commit is contained in:
parent
d46c86778c
commit
80c358838f
|
@ -1,14 +1,10 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { shallowEqual, useSelector } from 'react-redux';
|
import { shallowEqual, useSelector } from 'react-redux';
|
||||||
|
|
||||||
import Button from '../Button';
|
|
||||||
import { IApplicationState } from '../../definitions';
|
import { IApplicationState } from '../../definitions';
|
||||||
import { getUserSelector } from '../../selectors/login';
|
import { getUserSelector } from '../../selectors/login';
|
||||||
import Avatar from './Avatar';
|
import Avatar from './Avatar';
|
||||||
import { IAvatar } from './interfaces';
|
import { IAvatar } from './interfaces';
|
||||||
import I18n from '../../i18n';
|
|
||||||
import { useTheme } from '../../theme';
|
|
||||||
import styles from './styles';
|
|
||||||
import { useAvatarETag } from './useAvatarETag';
|
import { useAvatarETag } from './useAvatarETag';
|
||||||
|
|
||||||
interface IAvatarContainer extends IAvatar {
|
interface IAvatarContainer extends IAvatar {
|
||||||
|
@ -27,11 +23,8 @@ const AvatarContainer = ({
|
||||||
onPress,
|
onPress,
|
||||||
getCustomEmoji,
|
getCustomEmoji,
|
||||||
isStatic,
|
isStatic,
|
||||||
rid,
|
rid
|
||||||
handleEdit
|
|
||||||
}: IAvatarContainer): React.ReactElement => {
|
}: IAvatarContainer): React.ReactElement => {
|
||||||
const { colors } = useTheme();
|
|
||||||
|
|
||||||
const server = useSelector((state: IApplicationState) => state.share.server.server || state.server.server);
|
const server = useSelector((state: IApplicationState) => state.share.server.server || state.server.server);
|
||||||
const serverVersion = useSelector((state: IApplicationState) => state.share.server.version || state.server.version);
|
const serverVersion = useSelector((state: IApplicationState) => state.share.server.version || state.server.version);
|
||||||
const { id, token, username } = useSelector(
|
const { id, token, username } = useSelector(
|
||||||
|
@ -56,40 +49,27 @@ const AvatarContainer = ({
|
||||||
const { avatarETag } = useAvatarETag({ username, text, type, rid });
|
const { avatarETag } = useAvatarETag({ username, text, type, rid });
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<Avatar
|
||||||
<Avatar
|
server={server}
|
||||||
server={server}
|
style={style}
|
||||||
style={style}
|
text={text}
|
||||||
text={text}
|
avatar={avatar}
|
||||||
avatar={avatar}
|
emoji={emoji}
|
||||||
emoji={emoji}
|
size={size}
|
||||||
size={size}
|
borderRadius={borderRadius}
|
||||||
borderRadius={borderRadius}
|
type={type}
|
||||||
type={type}
|
children={children}
|
||||||
children={children}
|
userId={id}
|
||||||
userId={id}
|
token={token}
|
||||||
token={token}
|
onPress={onPress}
|
||||||
onPress={onPress}
|
getCustomEmoji={getCustomEmoji}
|
||||||
getCustomEmoji={getCustomEmoji}
|
isStatic={isStatic}
|
||||||
isStatic={isStatic}
|
rid={rid}
|
||||||
rid={rid}
|
blockUnauthenticatedAccess={blockUnauthenticatedAccess}
|
||||||
blockUnauthenticatedAccess={blockUnauthenticatedAccess}
|
externalProviderUrl={externalProviderUrl}
|
||||||
externalProviderUrl={externalProviderUrl}
|
avatarETag={avatarETag}
|
||||||
avatarETag={avatarETag}
|
serverVersion={serverVersion}
|
||||||
serverVersion={serverVersion}
|
/>
|
||||||
/>
|
|
||||||
{handleEdit ? (
|
|
||||||
<Button
|
|
||||||
title={I18n.t('Edit')}
|
|
||||||
type='secondary'
|
|
||||||
backgroundColor={colors.editAndUploadButtonAvatar}
|
|
||||||
onPress={handleEdit}
|
|
||||||
testID='avatar-edit-button'
|
|
||||||
style={styles.editAvatarButton}
|
|
||||||
color={colors.titleText}
|
|
||||||
/>
|
|
||||||
) : null}
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import Button from '../Button';
|
||||||
|
import AvatarContainer from './AvatarContainer';
|
||||||
|
import { IAvatar } from './interfaces';
|
||||||
|
import I18n from '../../i18n';
|
||||||
|
import { useTheme } from '../../theme';
|
||||||
|
import styles from './styles';
|
||||||
|
|
||||||
|
interface IAvatarContainer extends IAvatar {
|
||||||
|
handleEdit?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const AvatarWithEdit = ({
|
||||||
|
style,
|
||||||
|
text = '',
|
||||||
|
avatar,
|
||||||
|
emoji,
|
||||||
|
size,
|
||||||
|
borderRadius,
|
||||||
|
type,
|
||||||
|
children,
|
||||||
|
onPress,
|
||||||
|
getCustomEmoji,
|
||||||
|
isStatic,
|
||||||
|
rid,
|
||||||
|
handleEdit
|
||||||
|
}: IAvatarContainer): React.ReactElement => {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<AvatarContainer
|
||||||
|
style={style}
|
||||||
|
text={text}
|
||||||
|
avatar={avatar}
|
||||||
|
emoji={emoji}
|
||||||
|
size={size}
|
||||||
|
borderRadius={borderRadius}
|
||||||
|
type={type}
|
||||||
|
children={children}
|
||||||
|
onPress={onPress}
|
||||||
|
getCustomEmoji={getCustomEmoji}
|
||||||
|
isStatic={isStatic}
|
||||||
|
rid={rid}
|
||||||
|
/>
|
||||||
|
{handleEdit ? (
|
||||||
|
<Button
|
||||||
|
title={I18n.t('Edit')}
|
||||||
|
type='secondary'
|
||||||
|
backgroundColor={colors.editAndUploadButtonAvatar}
|
||||||
|
onPress={handleEdit}
|
||||||
|
testID='avatar-edit-button'
|
||||||
|
style={styles.editAvatarButton}
|
||||||
|
color={colors.titleText}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AvatarWithEdit;
|
|
@ -0,0 +1,5 @@
|
||||||
|
import Avatar from './AvatarContainer';
|
||||||
|
|
||||||
|
export { default as AvatarWithEdit } from './AvatarWithEdit';
|
||||||
|
|
||||||
|
export default Avatar;
|
|
@ -18,7 +18,7 @@ import { FormTextInput } from '../../containers/TextInput';
|
||||||
import { events, logEvent } from '../../lib/methods/helpers/log';
|
import { events, logEvent } from '../../lib/methods/helpers/log';
|
||||||
import I18n from '../../i18n';
|
import I18n from '../../i18n';
|
||||||
import Button from '../../containers/Button';
|
import Button from '../../containers/Button';
|
||||||
import Avatar from '../../containers/Avatar';
|
import { AvatarWithEdit } from '../../containers/Avatar';
|
||||||
import { setUser } from '../../actions/login';
|
import { setUser } from '../../actions/login';
|
||||||
import * as HeaderButton from '../../containers/HeaderButton';
|
import * as HeaderButton from '../../containers/HeaderButton';
|
||||||
import StatusBar from '../../containers/StatusBar';
|
import StatusBar from '../../containers/StatusBar';
|
||||||
|
@ -411,7 +411,7 @@ class ProfileView extends React.Component<IProfileViewProps, IProfileViewState>
|
||||||
<SafeAreaView testID='profile-view'>
|
<SafeAreaView testID='profile-view'>
|
||||||
<ScrollView contentContainerStyle={sharedStyles.containerScrollView} testID='profile-view-list' {...scrollPersistTaps}>
|
<ScrollView contentContainerStyle={sharedStyles.containerScrollView} testID='profile-view-list' {...scrollPersistTaps}>
|
||||||
<View style={styles.avatarContainer} testID='profile-view-avatar'>
|
<View style={styles.avatarContainer} testID='profile-view-avatar'>
|
||||||
<Avatar
|
<AvatarWithEdit
|
||||||
text={user.username}
|
text={user.username}
|
||||||
avatarETag={user.avatarETag}
|
avatarETag={user.avatarETag}
|
||||||
size={100}
|
size={100}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { Subscription } from 'rxjs';
|
||||||
|
|
||||||
import { deleteRoom } from '../../actions/room';
|
import { deleteRoom } from '../../actions/room';
|
||||||
import { themes } from '../../lib/constants';
|
import { themes } from '../../lib/constants';
|
||||||
import Avatar from '../../containers/Avatar';
|
import { AvatarWithEdit } from '../../containers/Avatar';
|
||||||
import { sendLoadingEvent } from '../../containers/Loading';
|
import { sendLoadingEvent } from '../../containers/Loading';
|
||||||
import SafeAreaView from '../../containers/SafeAreaView';
|
import SafeAreaView from '../../containers/SafeAreaView';
|
||||||
import StatusBar from '../../containers/StatusBar';
|
import StatusBar from '../../containers/StatusBar';
|
||||||
|
@ -527,7 +527,7 @@ class RoomInfoEditView extends React.Component<IRoomInfoEditViewProps, IRoomInfo
|
||||||
{...scrollPersistTaps}
|
{...scrollPersistTaps}
|
||||||
>
|
>
|
||||||
<View style={styles.avatarContainer}>
|
<View style={styles.avatarContainer}>
|
||||||
<Avatar type={room.t} text={room.name} rid={room.rid} size={100} handleEdit={this.handleEditAvatar} />
|
<AvatarWithEdit type={room.t} text={room.name} rid={room.rid} size={100} handleEdit={this.handleEditAvatar} />
|
||||||
</View>
|
</View>
|
||||||
<FormTextInput
|
<FormTextInput
|
||||||
inputRef={e => {
|
inputRef={e => {
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { Observable, Subscription } from 'rxjs';
|
||||||
|
|
||||||
import { CustomIcon, TIconsName } from '../../containers/CustomIcon';
|
import { CustomIcon, TIconsName } from '../../containers/CustomIcon';
|
||||||
import Status from '../../containers/Status';
|
import Status from '../../containers/Status';
|
||||||
import Avatar from '../../containers/Avatar';
|
import { AvatarWithEdit } from '../../containers/Avatar';
|
||||||
import sharedStyles from '../Styles';
|
import sharedStyles from '../Styles';
|
||||||
import RoomTypeIcon from '../../containers/RoomTypeIcon';
|
import RoomTypeIcon from '../../containers/RoomTypeIcon';
|
||||||
import I18n from '../../i18n';
|
import I18n from '../../i18n';
|
||||||
|
@ -183,17 +183,17 @@ class RoomInfoView extends React.Component<IRoomInfoViewProps, IRoomInfoViewStat
|
||||||
title: t === SubscriptionType.DIRECT ? I18n.t('User_Info') : I18n.t('Room_Info'),
|
title: t === SubscriptionType.DIRECT ? I18n.t('User_Info') : I18n.t('Room_Info'),
|
||||||
headerRight: showEdit
|
headerRight: showEdit
|
||||||
? () => (
|
? () => (
|
||||||
<HeaderButton.Container>
|
<HeaderButton.Container>
|
||||||
<HeaderButton.Item
|
<HeaderButton.Item
|
||||||
iconName='edit'
|
iconName='edit'
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
const isLivechat = t === SubscriptionType.OMNICHANNEL;
|
const isLivechat = t === SubscriptionType.OMNICHANNEL;
|
||||||
logEvent(events[`RI_GO_${isLivechat ? 'LIVECHAT' : 'RI'}_EDIT`]);
|
logEvent(events[`RI_GO_${isLivechat ? 'LIVECHAT' : 'RI'}_EDIT`]);
|
||||||
navigation.navigate(isLivechat ? 'LivechatEditView' : 'RoomInfoEditView', { rid, room, roomUser });
|
navigation.navigate(isLivechat ? 'LivechatEditView' : 'RoomInfoEditView', { rid, room, roomUser });
|
||||||
}}
|
}}
|
||||||
testID='room-info-view-edit-button'
|
testID='room-info-view-edit-button'
|
||||||
/>
|
/>
|
||||||
</HeaderButton.Container>
|
</HeaderButton.Container>
|
||||||
)
|
)
|
||||||
: undefined
|
: undefined
|
||||||
});
|
});
|
||||||
|
@ -404,7 +404,7 @@ class RoomInfoView extends React.Component<IRoomInfoViewProps, IRoomInfoViewStat
|
||||||
const { navigation } = this.props;
|
const { navigation } = this.props;
|
||||||
const { room } = this.state;
|
const { room } = this.state;
|
||||||
navigation.navigate('ChangeAvatarView', { titleHeader: I18n.t('Room_Info'), room, t: this.t });
|
navigation.navigate('ChangeAvatarView', { titleHeader: I18n.t('Room_Info'), room, t: this.t });
|
||||||
}
|
};
|
||||||
|
|
||||||
renderAvatar = (room: ISubscription, roomUser: IUserParsed) => {
|
renderAvatar = (room: ISubscription, roomUser: IUserParsed) => {
|
||||||
const { theme } = this.props;
|
const { theme } = this.props;
|
||||||
|
@ -412,7 +412,7 @@ class RoomInfoView extends React.Component<IRoomInfoViewProps, IRoomInfoViewStat
|
||||||
const showAvatarEdit = showEdit && this.t !== SubscriptionType.OMNICHANNEL;
|
const showAvatarEdit = showEdit && this.t !== SubscriptionType.OMNICHANNEL;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Avatar
|
<AvatarWithEdit
|
||||||
text={room.name || roomUser.username}
|
text={room.name || roomUser.username}
|
||||||
style={styles.avatar}
|
style={styles.avatar}
|
||||||
type={this.t}
|
type={this.t}
|
||||||
|
@ -425,7 +425,7 @@ class RoomInfoView extends React.Component<IRoomInfoViewProps, IRoomInfoViewStat
|
||||||
<Status size={20} id={roomUser._id} />
|
<Status size={20} id={roomUser._id} />
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
</Avatar>
|
</AvatarWithEdit>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue