Refactor touch component and update removeRoom and deleteRoom methods
This commit is contained in:
parent
bb0632b689
commit
c3ffa37323
File diff suppressed because it is too large
Load Diff
|
@ -79,11 +79,10 @@ const Content = React.memo(({
|
||||||
));
|
));
|
||||||
|
|
||||||
const Button = React.memo(({
|
const Button = React.memo(({
|
||||||
onPress, backgroundColor, underlayColor, ...props
|
onPress, underlayColor, ...props
|
||||||
}) => (
|
}) => (
|
||||||
<Touch
|
<Touch
|
||||||
onPress={() => onPress(props.title)}
|
onPress={() => onPress(props.title)}
|
||||||
style={{ backgroundColor: backgroundColor || themes[props.theme].backgroundColor }}
|
|
||||||
underlayColor={underlayColor}
|
underlayColor={underlayColor}
|
||||||
enabled={!props.disabled}
|
enabled={!props.disabled}
|
||||||
theme={props.theme}
|
theme={props.theme}
|
||||||
|
|
|
@ -722,5 +722,7 @@
|
||||||
"Add_Existing": "Add Existing",
|
"Add_Existing": "Add Existing",
|
||||||
"Add_Existing_Channel": "Add Existing Channel",
|
"Add_Existing_Channel": "Add Existing Channel",
|
||||||
"Remove_from_Team": "Remove from Team",
|
"Remove_from_Team": "Remove from Team",
|
||||||
"Auto-join": "Auto-join"
|
"Auto-join": "Auto-join",
|
||||||
|
"Delete_Team_Room_Warning": "Woud you like to remove this channel from the team? The channel will be moved back to the workspace",
|
||||||
|
"Confirmation": "Confirmation"
|
||||||
}
|
}
|
||||||
|
|
|
@ -754,13 +754,9 @@ const RocketChat = {
|
||||||
// RC 3.13.0
|
// RC 3.13.0
|
||||||
return this.post('teams.addRooms', params);
|
return this.post('teams.addRooms', params);
|
||||||
},
|
},
|
||||||
deleteTeamRoom({ rid, teamId }) {
|
removeTeamRoom({ roomId, teamId }) {
|
||||||
const params = {
|
|
||||||
roomId: rid,
|
|
||||||
teamId
|
|
||||||
};
|
|
||||||
// RC 3.13.0
|
// RC 3.13.0
|
||||||
return this.post('teams.removeRoom', params);
|
return this.post('teams.removeRoom', { roomId, teamId });
|
||||||
},
|
},
|
||||||
joinRoom(roomId, joinCode, type) {
|
joinRoom(roomId, joinCode, type) {
|
||||||
// TODO: join code
|
// TODO: join code
|
||||||
|
|
|
@ -24,7 +24,6 @@ const RoomItem = ({
|
||||||
status,
|
status,
|
||||||
useRealName,
|
useRealName,
|
||||||
theme,
|
theme,
|
||||||
isFocused,
|
|
||||||
isGroupChat,
|
isGroupChat,
|
||||||
isRead,
|
isRead,
|
||||||
date,
|
date,
|
||||||
|
@ -61,7 +60,6 @@ const RoomItem = ({
|
||||||
testID={testID}
|
testID={testID}
|
||||||
type={type}
|
type={type}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
isFocused={isFocused}
|
|
||||||
swipeEnabled={swipeEnabled}
|
swipeEnabled={swipeEnabled}
|
||||||
>
|
>
|
||||||
<Wrapper
|
<Wrapper
|
||||||
|
@ -163,7 +161,6 @@ RoomItem.propTypes = {
|
||||||
status: PropTypes.string,
|
status: PropTypes.string,
|
||||||
useRealName: PropTypes.bool,
|
useRealName: PropTypes.bool,
|
||||||
theme: PropTypes.string,
|
theme: PropTypes.string,
|
||||||
isFocused: PropTypes.bool,
|
|
||||||
isGroupChat: PropTypes.bool,
|
isGroupChat: PropTypes.bool,
|
||||||
isRead: PropTypes.bool,
|
isRead: PropTypes.bool,
|
||||||
teamMain: PropTypes.bool,
|
teamMain: PropTypes.bool,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { Animated, Pressable } from 'react-native';
|
import { Animated } from 'react-native';
|
||||||
import { PanGestureHandler, State } from 'react-native-gesture-handler';
|
import { PanGestureHandler, State } from 'react-native-gesture-handler';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -9,8 +9,8 @@ import {
|
||||||
LONG_SWIPE
|
LONG_SWIPE
|
||||||
} from './styles';
|
} from './styles';
|
||||||
import { isRTL } from '../../i18n';
|
import { isRTL } from '../../i18n';
|
||||||
import { themes } from '../../constants/colors';
|
|
||||||
import { LeftActions, RightActions } from './Actions';
|
import { LeftActions, RightActions } from './Actions';
|
||||||
|
import Touch from '../../utils/touch';
|
||||||
|
|
||||||
class Touchable extends React.Component {
|
class Touchable extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
|
@ -27,7 +27,6 @@ class Touchable extends React.Component {
|
||||||
hideChannel: PropTypes.func,
|
hideChannel: PropTypes.func,
|
||||||
children: PropTypes.element,
|
children: PropTypes.element,
|
||||||
theme: PropTypes.string,
|
theme: PropTypes.string,
|
||||||
isFocused: PropTypes.bool,
|
|
||||||
swipeEnabled: PropTypes.bool
|
swipeEnabled: PropTypes.bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,7 +216,7 @@ class Touchable extends React.Component {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
testID, isRead, width, favorite, children, theme, isFocused, swipeEnabled
|
testID, isRead, width, favorite, children, theme, swipeEnabled
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -249,17 +248,14 @@ class Touchable extends React.Component {
|
||||||
transform: [{ translateX: this.transX }]
|
transform: [{ translateX: this.transX }]
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Pressable
|
<Touch
|
||||||
onPress={this.onPress}
|
onPress={this.onPress}
|
||||||
onLongPress={this.onLongPress}
|
onLongPress={this.onLongPress}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
testID={testID}
|
testID={testID}
|
||||||
style={{
|
|
||||||
backgroundColor: isFocused ? themes[theme].chatComponentBackground : themes[theme].backgroundColor
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</Pressable>
|
</Touch>
|
||||||
</Animated.View>
|
</Animated.View>
|
||||||
</Animated.View>
|
</Animated.View>
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ const attrs = [
|
||||||
'status',
|
'status',
|
||||||
'connected',
|
'connected',
|
||||||
'theme',
|
'theme',
|
||||||
'isFocused',
|
|
||||||
'forceUpdate',
|
'forceUpdate',
|
||||||
'showLastMessage'
|
'showLastMessage'
|
||||||
];
|
];
|
||||||
|
@ -37,7 +36,6 @@ class RoomItemContainer extends React.Component {
|
||||||
getUserPresence: PropTypes.func,
|
getUserPresence: PropTypes.func,
|
||||||
connected: PropTypes.bool,
|
connected: PropTypes.bool,
|
||||||
theme: PropTypes.string,
|
theme: PropTypes.string,
|
||||||
isFocused: PropTypes.bool,
|
|
||||||
getRoomTitle: PropTypes.func,
|
getRoomTitle: PropTypes.func,
|
||||||
getRoomAvatar: PropTypes.func,
|
getRoomAvatar: PropTypes.func,
|
||||||
getIsGroupChat: PropTypes.func,
|
getIsGroupChat: PropTypes.func,
|
||||||
|
@ -129,7 +127,6 @@ class RoomItemContainer extends React.Component {
|
||||||
toggleRead,
|
toggleRead,
|
||||||
hideChannel,
|
hideChannel,
|
||||||
theme,
|
theme,
|
||||||
isFocused,
|
|
||||||
avatarSize,
|
avatarSize,
|
||||||
status,
|
status,
|
||||||
showLastMessage,
|
showLastMessage,
|
||||||
|
@ -178,7 +175,6 @@ class RoomItemContainer extends React.Component {
|
||||||
testID={testID}
|
testID={testID}
|
||||||
type={item.t}
|
type={item.t}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
isFocused={isFocused}
|
|
||||||
size={avatarSize}
|
size={avatarSize}
|
||||||
prid={item.prid}
|
prid={item.prid}
|
||||||
status={status}
|
status={status}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { RectButton } from 'react-native-gesture-handler';
|
|
||||||
|
|
||||||
|
import { Pressable } from 'react-native';
|
||||||
import { themes } from '../constants/colors';
|
import { themes } from '../constants/colors';
|
||||||
|
|
||||||
class Touch extends React.Component {
|
class Touch extends React.Component {
|
||||||
|
@ -15,21 +15,23 @@ class Touch extends React.Component {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
children, onPress, onLongPress, theme, underlayColor, ...props
|
children, onPress, onLongPress, theme, ...props
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RectButton
|
<Pressable
|
||||||
ref={this.getRef}
|
ref={this.getRef}
|
||||||
onPress={onPress}
|
onPress={onPress}
|
||||||
onLongPress={onLongPress}
|
onLongPress={onLongPress}
|
||||||
activeOpacity={1}
|
activeOpacity={1}
|
||||||
underlayColor={underlayColor || themes[theme].bannerBackground}
|
style={({ pressed }) => [{
|
||||||
rippleColor={themes[theme].bannerBackground}
|
backgroundColor: pressed ? themes[theme].chatComponentBackground : themes[theme].backgroundColor
|
||||||
|
}]}
|
||||||
|
android_ripple={{ color: themes[theme].bannerBackground }}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</RectButton>
|
</Pressable>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,6 @@ class AddChannelTeamView extends React.Component {
|
||||||
return (
|
return (
|
||||||
<Touch
|
<Touch
|
||||||
onPress={onPress}
|
onPress={onPress}
|
||||||
style={{ backgroundColor: themes[theme].backgroundColor }}
|
|
||||||
testID={testID}
|
testID={testID}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
>
|
>
|
||||||
|
|
|
@ -148,7 +148,6 @@ class NewMessageView extends React.Component {
|
||||||
return (
|
return (
|
||||||
<Touch
|
<Touch
|
||||||
onPress={onPress}
|
onPress={onPress}
|
||||||
style={{ backgroundColor: themes[theme].backgroundColor }}
|
|
||||||
testID={testID}
|
testID={testID}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
>
|
>
|
||||||
|
|
|
@ -586,10 +586,7 @@ class RoomsListView extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
onPressItem = (item = {}) => {
|
onPressItem = (item = {}) => {
|
||||||
const { navigation, isMasterDetail } = this.props;
|
const { isMasterDetail } = this.props;
|
||||||
if (!navigation.isFocused()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.cancelSearch();
|
this.cancelSearch();
|
||||||
this.goRoom({ item, isMasterDetail });
|
this.goRoom({ item, isMasterDetail });
|
||||||
|
@ -894,7 +891,6 @@ class RoomsListView extends React.Component {
|
||||||
return this.renderSectionHeader(item.rid);
|
return this.renderSectionHeader(item.rid);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { item: currentItem } = this.state;
|
|
||||||
const {
|
const {
|
||||||
user: { username },
|
user: { username },
|
||||||
StoreLastMessage,
|
StoreLastMessage,
|
||||||
|
@ -925,7 +921,6 @@ class RoomsListView extends React.Component {
|
||||||
getIsGroupChat={this.isGroupChat}
|
getIsGroupChat={this.isGroupChat}
|
||||||
getIsRead={this.isRead}
|
getIsRead={this.isRead}
|
||||||
visitor={item.visitor}
|
visitor={item.visitor}
|
||||||
isFocused={currentItem?.rid === item.rid}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -51,6 +51,7 @@ class TeamChannelsView extends React.Component {
|
||||||
width: PropTypes.number,
|
width: PropTypes.number,
|
||||||
StoreLastMessage: PropTypes.bool,
|
StoreLastMessage: PropTypes.bool,
|
||||||
addTeamChannelPermission: PropTypes.array,
|
addTeamChannelPermission: PropTypes.array,
|
||||||
|
removeTeamChannelPermission: PropTypes.array,
|
||||||
showActionSheet: PropTypes.func,
|
showActionSheet: PropTypes.func,
|
||||||
deleteRoom: PropTypes.func
|
deleteRoom: PropTypes.func
|
||||||
}
|
}
|
||||||
|
@ -79,6 +80,8 @@ class TeamChannelsView extends React.Component {
|
||||||
|
|
||||||
loadTeam = async() => {
|
loadTeam = async() => {
|
||||||
const { addTeamChannelPermission } = this.props;
|
const { addTeamChannelPermission } = this.props;
|
||||||
|
const { loading } = this.state;
|
||||||
|
|
||||||
const db = database.active;
|
const db = database.active;
|
||||||
try {
|
try {
|
||||||
const subCollection = db.get('subscriptions');
|
const subCollection = db.get('subscriptions');
|
||||||
|
@ -96,6 +99,9 @@ class TeamChannelsView extends React.Component {
|
||||||
if (permissions[0]) {
|
if (permissions[0]) {
|
||||||
this.setState({ showCreate: true }, () => this.setHeader());
|
this.setState({ showCreate: true }, () => this.setHeader());
|
||||||
}
|
}
|
||||||
|
if (loading) {
|
||||||
|
this.setState({ loading: false });
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
const { navigation } = this.props;
|
const { navigation } = this.props;
|
||||||
navigation.pop();
|
navigation.pop();
|
||||||
|
@ -103,7 +109,7 @@ class TeamChannelsView extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
load = debounce(async() => {
|
load = async() => {
|
||||||
const {
|
const {
|
||||||
loadingMore, data, search, isSearching, searchText, end
|
loadingMore, data, search, isSearching, searchText, end
|
||||||
} = this.state;
|
} = this.state;
|
||||||
|
@ -147,7 +153,7 @@ class TeamChannelsView extends React.Component {
|
||||||
log(e);
|
log(e);
|
||||||
this.setState({ loading: false, loadingMore: false });
|
this.setState({ loading: false, loadingMore: false });
|
||||||
}
|
}
|
||||||
}, 300)
|
}
|
||||||
|
|
||||||
setHeader = () => {
|
setHeader = () => {
|
||||||
const { isSearching, showCreate, data } = this.state;
|
const { isSearching, showCreate, data } = this.state;
|
||||||
|
@ -308,18 +314,54 @@ class TeamChannelsView extends React.Component {
|
||||||
title: I18n.t('Remove_from_Team'),
|
title: I18n.t('Remove_from_Team'),
|
||||||
icon: 'close',
|
icon: 'close',
|
||||||
danger: true,
|
danger: true,
|
||||||
onPress: this.removeFromTeam(item.id, this.teamId)
|
onPress: () => this.remove(item)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: I18n.t('Delete'),
|
title: I18n.t('Delete'),
|
||||||
icon: 'delete',
|
icon: 'delete',
|
||||||
danger: true,
|
danger: true,
|
||||||
onPress: this.delete
|
onPress: () => this.delete(item)
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
||||||
delete = () => {
|
remove = (item) => {
|
||||||
const { room } = this.state;
|
Alert.alert(
|
||||||
|
I18n.t('Confirmation'),
|
||||||
|
I18n.t('Delete_Team_Room_Warning'),
|
||||||
|
[
|
||||||
|
{
|
||||||
|
text: I18n.t('Cancel'),
|
||||||
|
style: 'cancel'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: I18n.t('Yes_action_it', { action: I18n.t('delete') }),
|
||||||
|
style: 'destructive',
|
||||||
|
onPress: () => this.removeRoom(item)
|
||||||
|
}
|
||||||
|
],
|
||||||
|
{ cancelable: false }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
removeRoom = async(item) => {
|
||||||
|
try {
|
||||||
|
const { data } = this.state;
|
||||||
|
const result = await RocketChat.removeTeamRoom({ roomId: item.rid, teamId: this.team.teamId });
|
||||||
|
if (result.success) {
|
||||||
|
console.log({ result });
|
||||||
|
const newData = data.filter(room => result.room._id !== room.rid);
|
||||||
|
console.log({ newData });
|
||||||
|
this.setState({ loading: true, data: newData }, () => {
|
||||||
|
this.loadTeam();
|
||||||
|
this.load();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delete = (item) => {
|
||||||
const { deleteRoom } = this.props;
|
const { deleteRoom } = this.props;
|
||||||
|
|
||||||
Alert.alert(
|
Alert.alert(
|
||||||
|
@ -333,16 +375,21 @@ class TeamChannelsView extends React.Component {
|
||||||
{
|
{
|
||||||
text: I18n.t('Yes_action_it', { action: I18n.t('delete') }),
|
text: I18n.t('Yes_action_it', { action: I18n.t('delete') }),
|
||||||
style: 'destructive',
|
style: 'destructive',
|
||||||
onPress: () => deleteRoom(room.rid, room.t)
|
onPress: () => deleteRoom(item.rid, item.t)
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
{ cancelable: false }
|
{ cancelable: false }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
showChannelActions = (item) => {
|
showChannelActions = async(item) => {
|
||||||
logEvent(events.ROOM_SHOW_BOX_ACTIONS);
|
logEvent(events.ROOM_SHOW_BOX_ACTIONS);
|
||||||
const { showActionSheet } = this.props;
|
const { showActionSheet, removeTeamChannelPermission } = this.props;
|
||||||
|
|
||||||
|
const permissions = await RocketChat.hasPermission([removeTeamChannelPermission], this.team.rid);
|
||||||
|
if (!permissions[0]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
showActionSheet({ options: this.options(item) });
|
showActionSheet({ options: this.options(item) });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,7 +473,8 @@ const mapStateToProps = state => ({
|
||||||
useRealName: state.settings.UI_Use_Real_Name,
|
useRealName: state.settings.UI_Use_Real_Name,
|
||||||
isMasterDetail: state.app.isMasterDetail,
|
isMasterDetail: state.app.isMasterDetail,
|
||||||
StoreLastMessage: state.settings.Store_Last_Message,
|
StoreLastMessage: state.settings.Store_Last_Message,
|
||||||
addTeamChannelPermission: state.permissions['add-team-channel']
|
addTeamChannelPermission: state.permissions['add-team-channel'],
|
||||||
|
removeTeamChannelPermission: state.permissions['remove-team-channel']
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch => ({
|
const mapDispatchToProps = dispatch => ({
|
||||||
|
|
Loading…
Reference in New Issue