room info edit view
This commit is contained in:
parent
e48b174118
commit
a7a4d9bb00
|
@ -58,6 +58,12 @@ export type ModalStackParamList = {
|
||||||
onSearch?: Function;
|
onSearch?: Function;
|
||||||
isRadio?: boolean;
|
isRadio?: boolean;
|
||||||
};
|
};
|
||||||
|
ChangeAvatarView: {
|
||||||
|
fromUser?: boolean;
|
||||||
|
titleHeader?: string;
|
||||||
|
room?: ISubscription;
|
||||||
|
t?: SubscriptionType;
|
||||||
|
};
|
||||||
RoomInfoEditView: {
|
RoomInfoEditView: {
|
||||||
rid: string;
|
rid: string;
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { RouteProp, useNavigation, useRoute } from '@react-navigation/native';
|
||||||
import { StackNavigationProp } from '@react-navigation/stack';
|
import { StackNavigationProp } from '@react-navigation/stack';
|
||||||
import ImagePicker, { Image } from 'react-native-image-crop-picker';
|
import ImagePicker, { Image } from 'react-native-image-crop-picker';
|
||||||
|
|
||||||
|
import { compareServerVersion } from '../../lib/methods/helpers';
|
||||||
import KeyboardView from '../../containers/KeyboardView';
|
import KeyboardView from '../../containers/KeyboardView';
|
||||||
import sharedStyles from '../Styles';
|
import sharedStyles from '../Styles';
|
||||||
import scrollPersistTaps from '../../lib/methods/helpers/scrollPersistTaps';
|
import scrollPersistTaps from '../../lib/methods/helpers/scrollPersistTaps';
|
||||||
|
@ -27,13 +28,14 @@ import log from '../../lib/methods/helpers/log';
|
||||||
|
|
||||||
const ChangeAvatarView = () => {
|
const ChangeAvatarView = () => {
|
||||||
const [avatar, setAvatarState] = useState<IAvatar>();
|
const [avatar, setAvatarState] = useState<IAvatar>();
|
||||||
|
|
||||||
const [textAvatar, setTextAvatar] = useState('');
|
const [textAvatar, setTextAvatar] = useState('');
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
const { colors } = useTheme();
|
const { colors } = useTheme();
|
||||||
const { user } = useAppSelector(state => ({
|
const { user, serverVersion } = useAppSelector(state => ({
|
||||||
user: getUserSelector(state),
|
user: getUserSelector(state),
|
||||||
isMasterDetail: state.app.isMasterDetail
|
isMasterDetail: state.app.isMasterDetail,
|
||||||
|
serverVersion: state.server.version
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const avatarUrl = useRef<string | undefined>('');
|
const avatarUrl = useRef<string | undefined>('');
|
||||||
|
@ -182,7 +184,7 @@ const ChangeAvatarView = () => {
|
||||||
onPress={pickImage}
|
onPress={pickImage}
|
||||||
testID='change-avatar-view-logout-other-locations'
|
testID='change-avatar-view-logout-other-locations'
|
||||||
/>
|
/>
|
||||||
{!fromUser ? (
|
{!fromUser && serverVersion && compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '3.6.0') ? (
|
||||||
<Button
|
<Button
|
||||||
title={I18n.t('Delete_image')}
|
title={I18n.t('Delete_image')}
|
||||||
type='primary'
|
type='primary'
|
||||||
|
|
|
@ -2,9 +2,7 @@ import React from 'react';
|
||||||
import { Q } from '@nozbe/watermelondb';
|
import { Q } from '@nozbe/watermelondb';
|
||||||
import { BlockContext } from '@rocket.chat/ui-kit';
|
import { BlockContext } from '@rocket.chat/ui-kit';
|
||||||
import { dequal } from 'dequal';
|
import { dequal } from 'dequal';
|
||||||
import isEmpty from 'lodash/isEmpty';
|
|
||||||
import { Alert, Keyboard, ScrollView, Text, TextInput, TouchableOpacity, View, StyleSheet } from 'react-native';
|
import { Alert, Keyboard, ScrollView, Text, TextInput, TouchableOpacity, View, StyleSheet } from 'react-native';
|
||||||
import ImagePicker, { Image } from 'react-native-image-crop-picker';
|
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
|
|
||||||
|
@ -23,13 +21,11 @@ import {
|
||||||
IRoomSettings,
|
IRoomSettings,
|
||||||
ISubscription,
|
ISubscription,
|
||||||
SubscriptionType,
|
SubscriptionType,
|
||||||
TSubscriptionModel,
|
TSubscriptionModel
|
||||||
IAvatar
|
|
||||||
} from '../../definitions';
|
} from '../../definitions';
|
||||||
import { ERoomType } from '../../definitions/ERoomType';
|
import { ERoomType } from '../../definitions/ERoomType';
|
||||||
import I18n from '../../i18n';
|
import I18n from '../../i18n';
|
||||||
import database from '../../lib/database';
|
import database from '../../lib/database';
|
||||||
import { CustomIcon } from '../../containers/CustomIcon';
|
|
||||||
import KeyboardView from '../../containers/KeyboardView';
|
import KeyboardView from '../../containers/KeyboardView';
|
||||||
import { TSupportedPermissions } from '../../reducers/permissions';
|
import { TSupportedPermissions } from '../../reducers/permissions';
|
||||||
import { ModalStackParamList } from '../../stacks/MasterDetailStack/types';
|
import { ModalStackParamList } from '../../stacks/MasterDetailStack/types';
|
||||||
|
@ -54,7 +50,6 @@ import { Services } from '../../lib/services';
|
||||||
|
|
||||||
interface IRoomInfoEditViewState {
|
interface IRoomInfoEditViewState {
|
||||||
room: ISubscription;
|
room: ISubscription;
|
||||||
avatar: IAvatar;
|
|
||||||
permissions: { [key in TSupportedPermissions]?: boolean };
|
permissions: { [key in TSupportedPermissions]?: boolean };
|
||||||
name: string;
|
name: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
|
@ -102,7 +97,6 @@ class RoomInfoEditView extends React.Component<IRoomInfoEditViewProps, IRoomInfo
|
||||||
this.room = {} as TSubscriptionModel;
|
this.room = {} as TSubscriptionModel;
|
||||||
this.state = {
|
this.state = {
|
||||||
room: {} as ISubscription,
|
room: {} as ISubscription,
|
||||||
avatar: {} as IAvatar,
|
|
||||||
permissions: {},
|
permissions: {},
|
||||||
name: '',
|
name: '',
|
||||||
description: '',
|
description: '',
|
||||||
|
@ -192,7 +186,6 @@ class RoomInfoEditView extends React.Component<IRoomInfoEditViewProps, IRoomInfo
|
||||||
topic,
|
topic,
|
||||||
announcement,
|
announcement,
|
||||||
t: t === 'p',
|
t: t === 'p',
|
||||||
avatar: {} as IAvatar,
|
|
||||||
ro,
|
ro,
|
||||||
reactWhenReadOnly,
|
reactWhenReadOnly,
|
||||||
joinCode: joinCodeRequired ? this.randomValue : '',
|
joinCode: joinCodeRequired ? this.randomValue : '',
|
||||||
|
@ -228,8 +221,7 @@ class RoomInfoEditView extends React.Component<IRoomInfoEditViewProps, IRoomInfo
|
||||||
joinCode,
|
joinCode,
|
||||||
systemMessages,
|
systemMessages,
|
||||||
enableSysMes,
|
enableSysMes,
|
||||||
encrypted,
|
encrypted
|
||||||
avatar
|
|
||||||
} = this.state;
|
} = this.state;
|
||||||
const { joinCodeRequired } = room;
|
const { joinCodeRequired } = room;
|
||||||
const sysMes = room.sysMes as string[];
|
const sysMes = room.sysMes as string[];
|
||||||
|
@ -244,28 +236,15 @@ class RoomInfoEditView extends React.Component<IRoomInfoEditViewProps, IRoomInfo
|
||||||
room.reactWhenReadOnly === reactWhenReadOnly &&
|
room.reactWhenReadOnly === reactWhenReadOnly &&
|
||||||
dequal(sysMes, systemMessages) &&
|
dequal(sysMes, systemMessages) &&
|
||||||
enableSysMes === (sysMes && sysMes.length > 0) &&
|
enableSysMes === (sysMes && sysMes.length > 0) &&
|
||||||
room.encrypted === encrypted &&
|
room.encrypted === encrypted
|
||||||
isEmpty(avatar)
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
submit = async () => {
|
submit = async () => {
|
||||||
logEvent(events.RI_EDIT_SAVE);
|
logEvent(events.RI_EDIT_SAVE);
|
||||||
Keyboard.dismiss();
|
Keyboard.dismiss();
|
||||||
const {
|
const { room, name, description, topic, announcement, t, ro, reactWhenReadOnly, joinCode, systemMessages, encrypted } =
|
||||||
room,
|
this.state;
|
||||||
name,
|
|
||||||
description,
|
|
||||||
topic,
|
|
||||||
announcement,
|
|
||||||
t,
|
|
||||||
ro,
|
|
||||||
reactWhenReadOnly,
|
|
||||||
joinCode,
|
|
||||||
systemMessages,
|
|
||||||
encrypted,
|
|
||||||
avatar
|
|
||||||
} = this.state;
|
|
||||||
|
|
||||||
sendLoadingEvent({ visible: true });
|
sendLoadingEvent({ visible: true });
|
||||||
let error = false;
|
let error = false;
|
||||||
|
@ -284,10 +263,6 @@ class RoomInfoEditView extends React.Component<IRoomInfoEditViewProps, IRoomInfo
|
||||||
if (room.name !== name) {
|
if (room.name !== name) {
|
||||||
params.roomName = name;
|
params.roomName = name;
|
||||||
}
|
}
|
||||||
// Avatar
|
|
||||||
if (!isEmpty(avatar)) {
|
|
||||||
params.roomAvatar = avatar.data as string;
|
|
||||||
}
|
|
||||||
// Description
|
// Description
|
||||||
if (room.description !== description) {
|
if (room.description !== description) {
|
||||||
params.roomDescription = description;
|
params.roomDescription = description;
|
||||||
|
@ -487,26 +462,10 @@ class RoomInfoEditView extends React.Component<IRoomInfoEditViewProps, IRoomInfo
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
changeAvatar = async () => {
|
handleEditAvatar = () => {
|
||||||
const options = {
|
const { navigation } = this.props;
|
||||||
cropping: true,
|
const { room } = this.state;
|
||||||
compressImageQuality: 0.8,
|
navigation.navigate('ChangeAvatarView', { titleHeader: I18n.t('Room_Info'), room, t: room.t });
|
||||||
cropperAvoidEmptySpaceAroundImage: false,
|
|
||||||
cropperChooseText: I18n.t('Choose'),
|
|
||||||
cropperCancelText: I18n.t('Cancel'),
|
|
||||||
includeBase64: true
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response: Image = await ImagePicker.openPicker(options);
|
|
||||||
this.setState({ avatar: { url: response.path, data: `data:image/jpeg;base64,${response.data}`, service: 'upload' } });
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
resetAvatar = () => {
|
|
||||||
this.setState({ avatar: { data: null } });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
toggleRoomType = (value: boolean) => {
|
toggleRoomType = (value: boolean) => {
|
||||||
|
@ -549,8 +508,7 @@ class RoomInfoEditView extends React.Component<IRoomInfoEditViewProps, IRoomInfo
|
||||||
permissions,
|
permissions,
|
||||||
archived,
|
archived,
|
||||||
enableSysMes,
|
enableSysMes,
|
||||||
encrypted,
|
encrypted
|
||||||
avatar
|
|
||||||
} = this.state;
|
} = this.state;
|
||||||
const { serverVersion, encryptionEnabled, theme } = this.props;
|
const { serverVersion, encryptionEnabled, theme } = this.props;
|
||||||
const { dangerColor } = themes[theme];
|
const { dangerColor } = themes[theme];
|
||||||
|
@ -568,29 +526,9 @@ class RoomInfoEditView extends React.Component<IRoomInfoEditViewProps, IRoomInfo
|
||||||
testID='room-info-edit-view-list'
|
testID='room-info-edit-view-list'
|
||||||
{...scrollPersistTaps}
|
{...scrollPersistTaps}
|
||||||
>
|
>
|
||||||
<TouchableOpacity
|
<View style={styles.avatarContainer}>
|
||||||
style={styles.avatarContainer}
|
<Avatar type={room.t} text={room.name} rid={room.rid} size={100} handleEdit={this.handleEditAvatar} />
|
||||||
onPress={this.changeAvatar}
|
</View>
|
||||||
disabled={compareServerVersion(serverVersion || '', 'lowerThan', '3.6.0')}
|
|
||||||
>
|
|
||||||
<Avatar
|
|
||||||
type={room.t}
|
|
||||||
text={room.name}
|
|
||||||
avatar={avatar?.url}
|
|
||||||
isStatic={avatar?.url}
|
|
||||||
rid={isEmpty(avatar) ? room.rid : undefined}
|
|
||||||
size={100}
|
|
||||||
>
|
|
||||||
{serverVersion && compareServerVersion(serverVersion, 'lowerThan', '3.6.0') ? undefined : (
|
|
||||||
<TouchableOpacity
|
|
||||||
style={[styles.resetButton, { backgroundColor: themes[theme].dangerColor }]}
|
|
||||||
onPress={this.resetAvatar}
|
|
||||||
>
|
|
||||||
<CustomIcon name='delete' color={themes[theme].backgroundColor} size={24} />
|
|
||||||
</TouchableOpacity>
|
|
||||||
)}
|
|
||||||
</Avatar>
|
|
||||||
</TouchableOpacity>
|
|
||||||
<FormTextInput
|
<FormTextInput
|
||||||
inputRef={e => {
|
inputRef={e => {
|
||||||
this.name = e;
|
this.name = e;
|
||||||
|
|
|
@ -401,7 +401,7 @@ class RoomInfoView extends React.Component<IRoomInfoViewProps, IRoomInfoViewStat
|
||||||
};
|
};
|
||||||
|
|
||||||
handleEditAvatar = () => {
|
handleEditAvatar = () => {
|
||||||
const {navigation} = this.props
|
const { navigation } = this.props;
|
||||||
const { room } = this.state;
|
const { room } = this.state;
|
||||||
navigation.navigate('ChangeAvatarView', { titleHeader: I18n.t('Room_Info'), room, t: this.t });
|
navigation.navigate('ChangeAvatarView', { titleHeader: I18n.t('Room_Info'), room, t: this.t });
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue