verdnatura-chat/app/containers/Avatar/AvatarWithEdit.tsx

85 lines
1.8 KiB
TypeScript
Raw Normal View History

2023-01-06 20:51:16 +00:00
import React from 'react';
2023-01-14 03:09:16 +00:00
import { StyleSheet } from 'react-native';
2023-01-06 20:51:16 +00:00
import Button from '../Button';
import AvatarContainer from './AvatarContainer';
import { IAvatar } from './interfaces';
import I18n from '../../i18n';
import { useTheme } from '../../theme';
2023-01-06 21:52:48 +00:00
import { BUTTON_HIT_SLOP } from '../message/utils';
2023-01-17 02:12:09 +00:00
import { useAppSelector } from '../../lib/hooks';
import { compareServerVersion } from '../../lib/methods/helpers';
2023-01-06 20:51:16 +00:00
2023-01-14 03:09:16 +00:00
const styles = StyleSheet.create({
editAvatarButton: {
marginTop: 8,
paddingVertical: 8,
paddingHorizontal: 12,
marginBottom: 0,
height: undefined
},
textButton: {
fontSize: 12,
fontWeight: '600'
}
});
interface IAvatarContainer extends Omit<IAvatar, 'size'> {
2023-01-11 17:18:57 +00:00
handleEdit?: () => void;
2023-01-06 20:51:16 +00:00
}
const AvatarWithEdit = ({
style,
text = '',
avatar,
emoji,
borderRadius,
type,
children,
onPress,
getCustomEmoji,
isStatic,
rid,
handleEdit
}: IAvatarContainer): React.ReactElement => {
const { colors } = useTheme();
2023-01-17 02:12:09 +00:00
const { serverVersion } = useAppSelector(state => ({
serverVersion: state.server.version
}));
2023-01-06 20:51:16 +00:00
return (
<>
<AvatarContainer
style={style}
text={text}
avatar={avatar}
emoji={emoji}
2023-01-14 03:09:16 +00:00
size={120}
2023-01-06 20:51:16 +00:00
borderRadius={borderRadius}
type={type}
children={children}
onPress={onPress}
getCustomEmoji={getCustomEmoji}
isStatic={isStatic}
rid={rid}
/>
2023-01-17 02:12:09 +00:00
{handleEdit && serverVersion && compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '3.6.0') ? (
2023-01-11 17:18:57 +00:00
<Button
title={I18n.t('Edit')}
type='secondary'
backgroundColor={colors.editAndUploadButtonAvatar}
onPress={handleEdit}
testID='avatar-edit-button'
style={styles.editAvatarButton}
styleText={[styles.textButton]}
color={colors.titleText}
hitSlop={BUTTON_HIT_SLOP}
/>
) : null}
2023-01-06 20:51:16 +00:00
</>
);
};
export default AvatarWithEdit;