change avatar view and avatar suggestion

This commit is contained in:
Reinaldo Neto 2022-12-07 02:01:00 -03:00
parent 49f2c28b3e
commit cc9a9d523d
7 changed files with 114 additions and 9 deletions

View File

@ -24,9 +24,7 @@ export interface IAvatar {
} }
export interface IAvatarSuggestion { export interface IAvatarSuggestion {
[service: string]: { url: string;
url: string; blob: string;
blob: string; contentType: string;
contentType: string;
};
} }

View File

@ -878,5 +878,6 @@
"room_archived": "archived room", "room_archived": "archived room",
"room_unarchived": "unarchived room", "room_unarchived": "unarchived room",
"Upload_image": "Upload image", "Upload_image": "Upload image",
"Delete_image": "Delete image" "Delete_image": "Delete image",
"Images_uploaded": "Images uploaded"
} }

View File

@ -594,7 +594,7 @@ export const getRoomRoles = (
// RC 0.65.0 // RC 0.65.0
sdk.get(`${roomTypeToApiType(type)}.roles`, { roomId }); sdk.get(`${roomTypeToApiType(type)}.roles`, { roomId });
export const getAvatarSuggestion = (): Promise<IAvatarSuggestion> => export const getAvatarSuggestion = (): Promise<{ [service: string]: IAvatarSuggestion }> =>
// RC 0.51.0 // RC 0.51.0
sdk.methodCallWrapper('getAvatarSuggestion'); sdk.methodCallWrapper('getAvatarSuggestion');

View File

@ -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 => (
<TouchableOpacity
key={item.service}
testID={`${item.service}-avatar-suggestion`}
onPress={() => Alert.alert('aqui')}
style={[styles.avatarButton, { backgroundColor: colors.borderColor }]}
>
<Avatar avatar={item.url} size={64} />
</TouchableOpacity>
));
return (
<View style={{ flex: 1 }}>
<Text style={styles.itemLabel}>{I18n.t('Images_uploaded')}</Text>
<View style={styles.containerAvatarSuggestion}>{renderItem()}</View>
</View>
);
};
export default AvatarSuggestion;

View File

@ -1,5 +1,7 @@
import React, { useState } from 'react'; import React, { useEffect, useLayoutEffect, useState } from 'react';
import { ScrollView, View } from 'react-native'; 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 KeyboardView from '../../containers/KeyboardView';
import sharedStyles from '../Styles'; import sharedStyles from '../Styles';
@ -15,11 +17,45 @@ import Avatar from '../../containers/Avatar';
import AvatarUrl from './AvatarUrl'; import AvatarUrl from './AvatarUrl';
import Button from '../../containers/Button'; import Button from '../../containers/Button';
import I18n from '../../i18n'; 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 ChangeAvatarView = () => {
const [avatarUrl, setAvatarUrl] = useState(''); const [avatarUrl, setAvatarUrl] = useState('');
const [avatarSuggestions, setAvatarSuggestions] = useState<IAvatar[]>([]);
const { colors } = useTheme(); const { colors } = useTheme();
const navigation = useNavigation<StackNavigationProp<ChatsStackParamList, 'ChangeAvatarView'>>();
const { fromUser, titleHeader } = useRoute<RouteProp<ChatsStackParamList, 'ChangeAvatarView'>>().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)); const user = useAppSelector(state => getUserSelector(state));
return ( return (
@ -40,6 +76,7 @@ const ChangeAvatarView = () => {
</View> </View>
<AvatarUrl onSubmit={(value: string) => setAvatarUrl(value)} /> <AvatarUrl onSubmit={(value: string) => setAvatarUrl(value)} />
<List.Separator style={styles.separator} /> <List.Separator style={styles.separator} />
{fromUser && avatarSuggestions ? <AvatarSuggestion avatarSuggestions={avatarSuggestions} /> : null}
<Button <Button
title={I18n.t('Upload_image')} title={I18n.t('Upload_image')}

View File

@ -1,5 +1,7 @@
import { StyleSheet } from 'react-native'; import { StyleSheet } from 'react-native';
import sharedStyles from '../Styles';
export default StyleSheet.create({ export default StyleSheet.create({
disabled: { disabled: {
opacity: 0.3 opacity: 0.3
@ -11,5 +13,24 @@ export default StyleSheet.create({
}, },
separator: { separator: {
marginVertical: 16 marginVertical: 16
},
itemLabel: {
marginBottom: 10,
fontSize: 14,
...sharedStyles.textMedium
},
avatarButton: {
width: 64,
height: 64,
alignItems: 'center',
justifyContent: 'center',
marginRight: 20,
marginBottom: 12,
borderRadius: 4
},
containerAvatarSuggestion: {
flex: 1,
flexWrap: 'wrap',
flexDirection: 'row'
} }
}); });

View File

@ -69,7 +69,7 @@ interface IProfileViewState {
currentPassword: string | null; currentPassword: string | null;
avatarUrl: string | null; avatarUrl: string | null;
avatar: IAvatar; avatar: IAvatar;
avatarSuggestions: IAvatarSuggestion; avatarSuggestions: { [service: string]: IAvatarSuggestion };
customFields: { customFields: {
[key: string | number]: string; [key: string | number]: string;
}; };
@ -415,6 +415,7 @@ class ProfileView extends React.Component<IProfileViewProps, IProfileViewState>
})} })}
{Object.keys(avatarSuggestions).map(service => { {Object.keys(avatarSuggestions).map(service => {
const { url, blob, contentType } = avatarSuggestions[service]; const { url, blob, contentType } = avatarSuggestions[service];
console.log('🚀 ~ file: index.tsx:418 ~ ProfileView ~ {Object.keys ~ url', url);
return this.renderAvatarButton({ return this.renderAvatarButton({
disabled: !Accounts_AllowUserAvatarChange, disabled: !Accounts_AllowUserAvatarChange,
key: `profile-view-avatar-${service}`, key: `profile-view-avatar-${service}`,