[FIX] Add loading prop on RoomActionsView to avoid double click (#4462)

This commit is contained in:
Gleidson Daniel Silva 2022-09-05 09:33:56 -03:00 committed by Diego Mello
parent d161fc6221
commit 64598cc5dd
1 changed files with 11 additions and 3 deletions

View File

@ -95,6 +95,7 @@ interface IRoomActionsViewState {
canCreateTeam: boolean;
canAddChannelToTeam: boolean;
canConvertTeam: boolean;
loading: boolean;
}
class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomActionsViewState> {
@ -144,7 +145,8 @@ class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomAction
canToggleEncryption: false,
canCreateTeam: false,
canAddChannelToTeam: false,
canConvertTeam: false
canConvertTeam: false,
loading: false
};
if (room && room.observe && room.rid) {
this.roomObservable = room.observe();
@ -512,6 +514,7 @@ class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomAction
if (!room.teamId) {
return;
}
this.setState({ loading: true });
const result = await Services.teamListRoomsOfUser({ teamId: room.teamId, userId });
if (result.success) {
@ -531,6 +534,7 @@ class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomAction
this.convertTeamToChannelConfirmation();
}
}
this.setState({ loading: false });
} catch (e) {
this.convertTeamToChannelConfirmation();
}
@ -573,6 +577,7 @@ class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomAction
if (!room.teamId) {
return;
}
this.setState({ loading: true });
const result = await Services.teamListRoomsOfUser({ teamId: room.teamId, userId });
if (result.success) {
@ -598,6 +603,7 @@ class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomAction
});
}
}
this.setState({ loading: false });
} catch (e) {
showConfirmationAlert({
message: I18n.t('You_are_leaving_the_team', { team: getRoomTitle(room) }),
@ -889,7 +895,7 @@ class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomAction
};
renderLastSection = () => {
const { room, joined } = this.state;
const { room, joined, loading } = this.state;
const { theme } = this.props;
const { t, blocker } = room;
@ -923,6 +929,7 @@ class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomAction
<List.Section>
<List.Separator />
<List.Item
disabled={loading}
title='Leave'
onPress={() =>
this.onPressTouchable({
@ -987,7 +994,7 @@ class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomAction
};
teamToChannelActions = (t: string, room: ISubscription) => {
const { canEdit, canConvertTeam } = this.state;
const { canEdit, canConvertTeam, loading } = this.state;
const canConvertTeamToChannel = canEdit && canConvertTeam && !!room?.teamMain;
return (
@ -996,6 +1003,7 @@ class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomAction
<>
<List.Item
title='Convert_to_Channel'
disabled={loading}
onPress={() =>
this.onPressTouchable({
event: this.convertTeamToChannel