diff --git a/app/definitions/IProfile.ts b/app/definitions/IProfile.ts index d232672cb..0935c32aa 100644 --- a/app/definitions/IProfile.ts +++ b/app/definitions/IProfile.ts @@ -24,9 +24,7 @@ export interface IAvatar { } export interface IAvatarSuggestion { - [service: string]: { - url: string; - blob: string; - contentType: string; - }; + url: string; + blob: string; + contentType: string; } diff --git a/app/i18n/locales/en.json b/app/i18n/locales/en.json index 0a7b997bf..c3b680f8e 100644 --- a/app/i18n/locales/en.json +++ b/app/i18n/locales/en.json @@ -878,5 +878,6 @@ "room_archived": "archived room", "room_unarchived": "unarchived room", "Upload_image": "Upload image", - "Delete_image": "Delete image" + "Delete_image": "Delete image", + "Images_uploaded": "Images uploaded" } \ No newline at end of file diff --git a/app/lib/services/restApi.ts b/app/lib/services/restApi.ts index 5fa3b1555..6cc55e42d 100644 --- a/app/lib/services/restApi.ts +++ b/app/lib/services/restApi.ts @@ -594,7 +594,7 @@ export const getRoomRoles = ( // RC 0.65.0 sdk.get(`${roomTypeToApiType(type)}.roles`, { roomId }); -export const getAvatarSuggestion = (): Promise => +export const getAvatarSuggestion = (): Promise<{ [service: string]: IAvatarSuggestion }> => // RC 0.51.0 sdk.methodCallWrapper('getAvatarSuggestion'); diff --git a/app/views/ChangeAvatarView/AvatarSuggestion.tsx b/app/views/ChangeAvatarView/AvatarSuggestion.tsx new file mode 100644 index 000000000..1e9f43b6f --- /dev/null +++ b/app/views/ChangeAvatarView/AvatarSuggestion.tsx @@ -0,0 +1,47 @@ +import React from 'react'; +import { Text, View, Alert, TouchableOpacity } from 'react-native'; + +import { IAvatar } from '../../definitions'; +import I18n from '../../i18n'; +import Avatar from '../../containers/Avatar'; +// import Touch from '../../containers/Touch'; +import styles from './styles'; +import { useTheme } from '../../theme'; + +const AvatarSuggestion = ({ avatarSuggestions }: { avatarSuggestions: IAvatar[] }) => { + const { colors } = useTheme(); + const test = [ + ...avatarSuggestions, + ...avatarSuggestions, + ...avatarSuggestions, + ...avatarSuggestions, + ...avatarSuggestions, + ...avatarSuggestions, + ...avatarSuggestions, + ...avatarSuggestions, + ...avatarSuggestions, + ...avatarSuggestions, + ...avatarSuggestions, + ...avatarSuggestions + ]; + const renderItem = () => + test.slice(0, 8).map(item => ( + Alert.alert('aqui')} + style={[styles.avatarButton, { backgroundColor: colors.borderColor }]} + > + + + )); + + return ( + + {I18n.t('Images_uploaded')} + {renderItem()} + + ); +}; + +export default AvatarSuggestion; diff --git a/app/views/ChangeAvatarView/index.tsx b/app/views/ChangeAvatarView/index.tsx index 44a820a66..0f843f58e 100644 --- a/app/views/ChangeAvatarView/index.tsx +++ b/app/views/ChangeAvatarView/index.tsx @@ -1,5 +1,7 @@ -import React, { useState } from 'react'; +import React, { useEffect, useLayoutEffect, useState } from 'react'; import { ScrollView, View } from 'react-native'; +import { RouteProp, useNavigation, useRoute } from '@react-navigation/native'; +import { StackNavigationProp } from '@react-navigation/stack'; import KeyboardView from '../../containers/KeyboardView'; import sharedStyles from '../Styles'; @@ -15,11 +17,45 @@ import Avatar from '../../containers/Avatar'; import AvatarUrl from './AvatarUrl'; import Button from '../../containers/Button'; import I18n from '../../i18n'; +import { ChatsStackParamList } from '../../stacks/types'; +import { IAvatar } from '../../definitions'; +import { Services } from '../../lib/services'; +import AvatarSuggestion from './AvatarSuggestion'; const ChangeAvatarView = () => { const [avatarUrl, setAvatarUrl] = useState(''); + const [avatarSuggestions, setAvatarSuggestions] = useState([]); const { colors } = useTheme(); + const navigation = useNavigation>(); + const { fromUser, titleHeader } = useRoute>().params; + + useLayoutEffect(() => { + if (titleHeader) { + navigation.setOptions({ title: titleHeader }); + } + }, [titleHeader, navigation]); + + 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(() => { + if (fromUser) { + getAvatarSuggestion(); + } + }, [fromUser]); + const user = useAppSelector(state => getUserSelector(state)); return ( @@ -40,6 +76,7 @@ const ChangeAvatarView = () => { setAvatarUrl(value)} /> + {fromUser && avatarSuggestions ? : null}