minor tweak

This commit is contained in:
Reinaldo Neto 2023-01-14 00:09:16 -03:00
parent 1255f4ac3b
commit 6d22747707
6 changed files with 37 additions and 48 deletions

View File

@ -1,4 +1,5 @@
import React from 'react'; import React from 'react';
import { StyleSheet } from 'react-native';
import Button from '../Button'; import Button from '../Button';
import AvatarContainer from './AvatarContainer'; import AvatarContainer from './AvatarContainer';
@ -6,9 +7,22 @@ import { IAvatar } from './interfaces';
import I18n from '../../i18n'; import I18n from '../../i18n';
import { useTheme } from '../../theme'; import { useTheme } from '../../theme';
import { BUTTON_HIT_SLOP } from '../message/utils'; import { BUTTON_HIT_SLOP } from '../message/utils';
import styles from './styles';
interface IAvatarContainer extends IAvatar { 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'> {
handleEdit?: () => void; handleEdit?: () => void;
} }
@ -17,7 +31,6 @@ const AvatarWithEdit = ({
text = '', text = '',
avatar, avatar,
emoji, emoji,
size,
borderRadius, borderRadius,
type, type,
children, children,
@ -36,7 +49,7 @@ const AvatarWithEdit = ({
text={text} text={text}
avatar={avatar} avatar={avatar}
emoji={emoji} emoji={emoji}
size={size} size={120}
borderRadius={borderRadius} borderRadius={borderRadius}
type={type} type={type}
children={children} children={children}

View File

@ -1,15 +0,0 @@
import { StyleSheet } from 'react-native';
export default StyleSheet.create({
editAvatarButton: {
marginTop: 8,
paddingVertical: 8,
paddingHorizontal: 12,
marginBottom: 0,
height: undefined
},
textButton: {
fontSize: 12,
fontWeight: '600'
}
});

View File

@ -23,7 +23,7 @@ export const useAvatarETag = ({
useEffect(() => { useEffect(() => {
let subscription: Subscription; let subscription: Subscription;
if (!avatarETag) { if (!avatarETag) {
(async () => { const observeAvatarETag = async () => {
const db = database.active; const db = database.active;
const usersCollection = db.get('users'); const usersCollection = db.get('users');
const subsCollection = db.get('subscriptions'); const subsCollection = db.get('subscriptions');
@ -46,8 +46,8 @@ export const useAvatarETag = ({
setAvatarETag(r.avatarETag); setAvatarETag(r.avatarETag);
}); });
} }
})(); };
observeAvatarETag();
return () => { return () => {
if (subscription?.unsubscribe) { if (subscription?.unsubscribe) {
subscription.unsubscribe(); subscription.unsubscribe();

View File

@ -21,21 +21,20 @@ const AvatarSuggestion = ({
const { colors } = useTheme(); 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(() => { useEffect(() => {
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);
};
getAvatarSuggestion(); getAvatarSuggestion();
}, []); }, []);

View File

@ -1,15 +1,8 @@
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
import { useForm } from 'react-hook-form'; import { useForm } from 'react-hook-form';
import * as yup from 'yup';
import { yupResolver } from '@hookform/resolvers/yup';
import I18n from '../../i18n'; import I18n from '../../i18n';
import { ControlledFormTextInput } from '../../containers/TextInput'; import { ControlledFormTextInput } from '../../containers/TextInput';
import { regExpImageType } from '../../lib/methods/helpers';
const schema = yup.object().shape({
avatarUrl: yup.string().url().matches(regExpImageType).required()
});
interface ISubmit { interface ISubmit {
avatarUrl: string; avatarUrl: string;
@ -18,18 +11,18 @@ interface ISubmit {
const AvatarUrl = ({ submit }: { submit: (value: string) => void }) => { const AvatarUrl = ({ submit }: { submit: (value: string) => void }) => {
const { const {
control, control,
formState: { isValid }, formState: { isDirty },
getValues getValues
} = useForm<ISubmit>({ mode: 'onChange', resolver: yupResolver(schema) }); } = useForm<ISubmit>({ mode: 'onChange', defaultValues: { avatarUrl: '' } });
useEffect(() => { useEffect(() => {
if (isValid) { if (isDirty) {
const { avatarUrl } = getValues(); const { avatarUrl } = getValues();
submit(avatarUrl); submit(avatarUrl);
} else { } else {
submit(''); submit('');
} }
}, [isValid]); }, [isDirty]);
return ( return (
<ControlledFormTextInput <ControlledFormTextInput

View File

@ -31,7 +31,6 @@ const RESET_ROOM_AVATAR = 'resetRoomAvatar';
const ChangeAvatarView = () => { const ChangeAvatarView = () => {
const [avatar, setAvatarState] = useState<IAvatar | null>(null); const [avatar, setAvatarState] = useState<IAvatar | null>(null);
const [textAvatar, setTextAvatar] = useState(''); const [textAvatar, setTextAvatar] = useState('');
const [saving, setSaving] = useState(false); const [saving, setSaving] = useState(false);
const { colors } = useTheme(); const { colors } = useTheme();