From 66230443447bed4a83e684ab97b70371c847e9f9 Mon Sep 17 00:00:00 2001 From: Gerzon Z Date: Mon, 9 May 2022 09:21:09 -0400 Subject: [PATCH] Chore: Evaluate `TeamChannelsView` (#4088) * update: `TeamChannelsView`'s interfaces * update: `TeamChannelsView`'s route params and types * update: `teamChannels` type Co-authored-by: GleidsonDaniel --- app/stacks/MasterDetailStack/types.ts | 3 +- app/stacks/types.ts | 8 ++- app/views/RoomView/RightButtons.tsx | 6 +- app/views/TeamChannelsView.tsx | 84 ++++++++++++--------------- 4 files changed, 46 insertions(+), 55 deletions(-) diff --git a/app/stacks/MasterDetailStack/types.ts b/app/stacks/MasterDetailStack/types.ts index 1edfff73..a21c63eb 100644 --- a/app/stacks/MasterDetailStack/types.ts +++ b/app/stacks/MasterDetailStack/types.ts @@ -28,7 +28,7 @@ export type MasterDetailDrawerParamList = { export type ModalStackParamList = { RoomActionsView: { room: ISubscription; - member: any; + member?: any; rid: string; t: SubscriptionType; joined: boolean; @@ -135,6 +135,7 @@ export type ModalStackParamList = { }; TeamChannelsView: { teamId: string; + joined: boolean; }; MarkdownTableView: { renderRows: Function; diff --git a/app/stacks/types.ts b/app/stacks/types.ts index 8d186ffb..04bd3912 100644 --- a/app/stacks/types.ts +++ b/app/stacks/types.ts @@ -1,6 +1,7 @@ import { NavigatorScreenParams } from '@react-navigation/core'; import { TextInputProps } from 'react-native'; +import { IItem } from '../views/TeamChannelsView'; import { IOptionsField } from '../views/NotificationPreferencesView/options'; import { IServer } from '../definitions/IServer'; import { IAttachment } from '../definitions/IAttachment'; @@ -36,7 +37,7 @@ export type ChatsStackParamList = { | undefined; // Navigates back to RoomView already on stack RoomActionsView: { room: TSubscriptionModel; - member: any; + member?: any; rid: string; t: SubscriptionType; joined: boolean; @@ -125,6 +126,7 @@ export type ChatsStackParamList = { }; TeamChannelsView: { teamId: string; + joined: boolean; }; CreateChannelView: { isTeam?: boolean; // TODO: To check @@ -132,11 +134,11 @@ export type ChatsStackParamList = { }; AddChannelTeamView: { teamId?: string; - teamChannels: []; // TODO: Change + teamChannels: IItem[]; }; AddExistingChannelView: { teamId?: string; - teamChannels: []; // TODO: Change + teamChannels: IItem[]; }; MarkdownTableView: { renderRows: (drawExtraBorders?: boolean) => JSX.Element; diff --git a/app/views/RoomView/RightButtons.tsx b/app/views/RoomView/RightButtons.tsx index 079e4668..4e5bd51d 100644 --- a/app/views/RoomView/RightButtons.tsx +++ b/app/views/RoomView/RightButtons.tsx @@ -128,7 +128,7 @@ class RightButtonsContainer extends Component { logEvent(events.ROOM_GO_TEAM_CHANNELS); - const { navigation, isMasterDetail, teamId } = this.props; + const { navigation, isMasterDetail, teamId, joined } = this.props; if (!teamId) { return; } @@ -136,10 +136,10 @@ class RightButtonsContainer extends Component ({ length: data?.length || 0, @@ -49,8 +43,7 @@ const getItemLayout = (data: IItem[] | null | undefined, index: number) => ({ }); const keyExtractor = (item: IItem) => item._id; -// This interface comes from request getTeamListRoom -interface IItem { +export interface IItem { _id: ERoomType; fname: string; customFields: object; @@ -81,14 +74,8 @@ interface ITeamChannelsViewState { showCreate: boolean; } -type IProps = Omit, 'navigation'> & { - navigation: StackNavigationProp; -}; - -interface ITeamChannelsViewProps extends IProps { - isMasterDetail: boolean; +interface ITeamChannelsViewProps extends IBaseScreen { insets: EdgeInsets; - theme: TSupportedThemes; useRealName: boolean; width: number; StoreLastMessage: boolean; @@ -97,22 +84,21 @@ interface ITeamChannelsViewProps extends IProps { removeTeamChannelPermission: string[]; deleteCPermission: string[]; deletePPermission: string[]; - showActionSheet: (options: any) => void; + showActionSheet: (options: TActionSheetOptions) => void; showAvatar: boolean; - displayMode: string; - dispatch: Dispatch; + displayMode: DisplayMode; } class TeamChannelsView extends React.Component { private teamId: string; - - // TODO: Refactor when migrate room - private teamChannels: any; - - // TODO: Refactor when migrate room - private team: any; + private joined: boolean; + private teamChannels: TSubscriptionModel[]; + private team: TSubscriptionModel; constructor(props: ITeamChannelsViewProps) { super(props); + this.teamChannels = []; + this.team = {} as TSubscriptionModel; + this.joined = props.route.params?.joined; this.teamId = props.route.params?.teamId; this.state = { loading: true, @@ -139,8 +125,8 @@ class TeamChannelsView extends React.Component channel.teamMain); + this.teamChannels = await subCollection.query(Q.where('team_id', Q.eq(this.teamId))).fetch(); + this.team = this.teamChannels?.find((channel: TSubscriptionModel) => channel.teamMain) as TSubscriptionModel; this.setHeader(); if (!this.team) { @@ -188,11 +174,9 @@ class TeamChannelsView extends React.Component { logEvent(events.TC_GO_ACTIONS); - const { team } = this; + const { team, joined } = this; const { navigation, isMasterDetail } = this.props; - if (isMasterDetail) { + if (!team) { + return; + } + if (isMasterDetail && screen) { navigation.navigate('ModalStackNavigator', { - screen: screen ?? 'RoomActionsView', + screen: 'RoomActionsView', params: { rid: team.rid, t: team.t, room: team, - showCloseModal: false + joined } }); } else { navigation.navigate('RoomActionsView', { rid: team.rid, t: team.t, - room: team + room: team, + joined }); } }; @@ -411,7 +399,7 @@ class TeamChannelsView extends React.Component result.room._id !== room._id); this.setState({ data: newData }); @@ -459,7 +447,7 @@ class TeamChannelsView extends React.Component ({ useRealName: state.settings.UI_Use_Real_Name, isMasterDetail: state.app.isMasterDetail, StoreLastMessage: state.settings.Store_Last_Message, - addTeamChannelPermission: state.permissions[PERMISSION_ADD_TEAM_CHANNEL], - editTeamChannelPermission: state.permissions[PERMISSION_EDIT_TEAM_CHANNEL], - removeTeamChannelPermission: state.permissions[PERMISSION_REMOVE_TEAM_CHANNEL], - deleteCPermission: state.permissions[PERMISSION_DELETE_C], - deletePPermission: state.permissions[PERMISSION_DELETE_P], + addTeamChannelPermission: state.permissions['add-team-channel'], + editTeamChannelPermission: state.permissions['edit-team-channel'], + removeTeamChannelPermission: state.permissions['remove-team-channel'], + deleteCPermission: state.permissions['delete-c'], + deletePPermission: state.permissions['delete-p'], showAvatar: state.sortPreferences.showAvatar, displayMode: state.sortPreferences.displayMode });