verdnatura-chat/app/views/ChangeAvatarView/AvatarSuggestion.tsx

57 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-12-12 21:13:12 +00:00
import React, { useState, useEffect } from 'react';
2022-12-20 16:40:53 +00:00
import { Text, View } from 'react-native';
2023-01-10 03:38:37 +00:00
import { IAvatar } from '../../definitions';
2022-12-12 21:13:12 +00:00
import { Services } from '../../lib/services';
import I18n from '../../i18n';
import styles from './styles';
import { useTheme } from '../../theme';
2023-01-10 02:39:59 +00:00
import AvatarSuggestionItem from './AvatarSuggestionItem';
const AvatarSuggestion = ({
onPress,
2023-01-10 03:38:37 +00:00
username,
resetAvatar
}: {
onPress: (value: IAvatar) => void;
2023-01-10 03:38:37 +00:00
username?: string;
resetAvatar?: () => void;
2022-12-12 21:13:12 +00:00
}) => {
const [avatarSuggestions, setAvatarSuggestions] = useState<IAvatar[]>([]);
2022-12-20 16:40:53 +00:00
2022-12-15 12:51:26 +00:00
const { colors } = useTheme();
2022-12-20 16:40:53 +00:00
2022-12-12 21:13:12 +00:00
useEffect(() => {
2023-01-14 03:09:16 +00:00
const getAvatarSuggestion = async () => {
const result = await Services.getAvatarSuggestion();
const suggestions = Object.keys(result).map(service => {
const { url, blob, contentType } = result[service];
return {
url,
data: blob,
service,
contentType
};
});
setAvatarSuggestions(suggestions);
};
2022-12-12 21:13:12 +00:00
getAvatarSuggestion();
}, []);
return (
2023-01-10 03:38:37 +00:00
<View style={styles.containerImagesUploaded}>
2022-12-15 12:51:26 +00:00
<Text style={[styles.itemLabel, { color: colors.titleText }]}>{I18n.t('Images_uploaded')}</Text>
2022-12-12 21:13:12 +00:00
<View style={styles.containerAvatarSuggestion}>
2023-01-10 03:38:37 +00:00
{username && resetAvatar ? (
<AvatarSuggestionItem text={`@${username}`} testID={`reset-avatar-suggestion`} onPress={resetAvatar} />
2022-12-14 22:09:14 +00:00
) : null}
2022-12-12 21:13:12 +00:00
{avatarSuggestions.slice(0, 7).map(item => (
2023-01-10 02:39:59 +00:00
<AvatarSuggestionItem item={item} testID={`${item?.service}-avatar-suggestion`} onPress={onPress} />
2022-12-12 21:13:12 +00:00
))}
</View>
</View>
2022-12-12 21:13:12 +00:00
);
};
export default AvatarSuggestion;