import React, { useState, useEffect } from 'react';
import { Text, View, TouchableOpacity } from 'react-native';
import { IAvatar, IUser } from '../../definitions';
import { Services } from '../../lib/services';
import I18n from '../../i18n';
import Avatar from '../../containers/Avatar';
import styles from './styles';
import { useTheme } from '../../theme';
const Item = ({
item,
onPress,
text,
testID
}: {
item?: IAvatar;
testID?: string;
onPress: (value?: IAvatar) => void;
text?: string;
}) => {
const { colors } = useTheme();
return (
onPress(item)}
style={[styles.avatarButton, { backgroundColor: colors.borderColor }]}
>
);
};
const AvatarSuggestion = ({
onPress,
user,
resetAvatar
}: {
onPress: (value?: IAvatar) => void;
user?: IUser;
resetAvatar?: () => void;
}) => {
const [avatarSuggestions, setAvatarSuggestions] = useState([]);
const { colors } = useTheme();
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);
};
useEffect(() => {
getAvatarSuggestion();
}, []);
return (
{I18n.t('Images_uploaded')}
{user?.username && resetAvatar ? (
) : null}
{avatarSuggestions.slice(0, 7).map(item => (
))}
);
};
export default AvatarSuggestion;