Chore: Evaluate `TeamChannelsView` (#4088)
* update: `TeamChannelsView`'s interfaces * update: `TeamChannelsView`'s route params and types * update: `teamChannels` type Co-authored-by: GleidsonDaniel <gleidson10daniel@hotmail.com>
This commit is contained in:
parent
abbb97cd84
commit
6623044344
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -128,7 +128,7 @@ class RightButtonsContainer extends Component<IRightButtonsProps, IRigthButtonsS
|
|||
|
||||
goTeamChannels = () => {
|
||||
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<IRightButtonsProps, IRigthButtonsS
|
|||
// @ts-ignore TODO: find a way to make this work
|
||||
navigation.navigate('ModalStackNavigator', {
|
||||
screen: 'TeamChannelsView',
|
||||
params: { teamId }
|
||||
params: { teamId, joined }
|
||||
});
|
||||
} else {
|
||||
navigation.navigate('TeamChannelsView', { teamId });
|
||||
navigation.navigate('TeamChannelsView', { teamId, joined });
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
import { Q } from '@nozbe/watermelondb';
|
||||
import { HeaderBackButton, StackNavigationOptions, StackNavigationProp } from '@react-navigation/stack';
|
||||
import React from 'react';
|
||||
import { Q } from '@nozbe/watermelondb';
|
||||
import { HeaderBackButton, StackNavigationOptions } from '@react-navigation/stack';
|
||||
import { Alert, FlatList, Keyboard } from 'react-native';
|
||||
import { EdgeInsets, withSafeAreaInsets } from 'react-native-safe-area-context';
|
||||
import { connect } from 'react-redux';
|
||||
import { Dispatch } from 'redux';
|
||||
|
||||
import { deleteRoom } from '../actions/room';
|
||||
import { themes } from '../lib/constants';
|
||||
import { withActionSheet } from '../containers/ActionSheet';
|
||||
import { DisplayMode, themes } from '../lib/constants';
|
||||
import { TActionSheetOptions, TActionSheetOptionsItem, withActionSheet } from '../containers/ActionSheet';
|
||||
import ActivityIndicator from '../containers/ActivityIndicator';
|
||||
import BackgroundContainer from '../containers/BackgroundContainer';
|
||||
import { getHeaderTitlePosition } from '../containers/Header';
|
||||
|
@ -17,7 +16,7 @@ import RoomHeader from '../containers/RoomHeader';
|
|||
import SafeAreaView from '../containers/SafeAreaView';
|
||||
import SearchHeader from '../containers/SearchHeader';
|
||||
import StatusBar from '../containers/StatusBar';
|
||||
import { IApplicationState, IBaseScreen } from '../definitions';
|
||||
import { IApplicationState, IBaseScreen, TSubscriptionModel } from '../definitions';
|
||||
import { ERoomType } from '../definitions/ERoomType';
|
||||
import { withDimensions } from '../dimensions';
|
||||
import I18n from '../i18n';
|
||||
|
@ -26,7 +25,7 @@ import { CustomIcon } from '../containers/CustomIcon';
|
|||
import RoomItem, { ROW_HEIGHT } from '../containers/RoomItem';
|
||||
import { getUserSelector } from '../selectors/login';
|
||||
import { ChatsStackParamList } from '../stacks/types';
|
||||
import { TSupportedThemes, withTheme } from '../theme';
|
||||
import { withTheme } from '../theme';
|
||||
import debounce from '../utils/debounce';
|
||||
import { isIOS } from '../utils/deviceInfo';
|
||||
import { goRoom } from '../utils/goRoom';
|
||||
|
@ -36,11 +35,6 @@ import { getRoomAvatar, getRoomTitle, hasPermission } from '../lib/methods';
|
|||
import { Services } from '../lib/services';
|
||||
|
||||
const API_FETCH_COUNT = 25;
|
||||
const PERMISSION_DELETE_C = 'delete-c';
|
||||
const PERMISSION_DELETE_P = 'delete-p';
|
||||
const PERMISSION_EDIT_TEAM_CHANNEL = 'edit-team-channel';
|
||||
const PERMISSION_REMOVE_TEAM_CHANNEL = 'remove-team-channel';
|
||||
const PERMISSION_ADD_TEAM_CHANNEL = 'add-team-channel';
|
||||
|
||||
const getItemLayout = (data: IItem[] | null | undefined, index: number) => ({
|
||||
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<IBaseScreen<ChatsStackParamList, 'TeamChannelsView'>, 'navigation'> & {
|
||||
navigation: StackNavigationProp<any, 'TeamChannelsView'>;
|
||||
};
|
||||
|
||||
interface ITeamChannelsViewProps extends IProps {
|
||||
isMasterDetail: boolean;
|
||||
interface ITeamChannelsViewProps extends IBaseScreen<ChatsStackParamList, 'TeamChannelsView'> {
|
||||
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<ITeamChannelsViewProps, ITeamChannelsViewState> {
|
||||
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<ITeamChannelsViewProps, ITeamChan
|
|||
const db = database.active;
|
||||
try {
|
||||
const subCollection = db.get('subscriptions');
|
||||
this.teamChannels = await subCollection.query(Q.where('team_id', Q.eq(this.teamId)));
|
||||
this.team = this.teamChannels?.find((channel: any) => 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<ITeamChannelsViewProps, ITeamChan
|
|||
} as ITeamChannelsViewState;
|
||||
|
||||
if (isSearching) {
|
||||
// @ts-ignore
|
||||
newState.search = [...search, ...result.rooms];
|
||||
newState.search = [...search, ...result.rooms] as IItem[];
|
||||
} else {
|
||||
// @ts-ignore
|
||||
newState.data = [...data, ...result.rooms];
|
||||
newState.data = [...data, ...result.rooms] as IItem[];
|
||||
}
|
||||
|
||||
this.setState(newState);
|
||||
|
@ -315,23 +299,27 @@ class TeamChannelsView extends React.Component<ITeamChannelsViewProps, ITeamChan
|
|||
|
||||
goRoomActionsView = (screen: string) => {
|
||||
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<ITeamChannelsViewProps, ITeamChan
|
|||
logEvent(events.TC_DELETE_ROOM);
|
||||
try {
|
||||
const { data } = this.state;
|
||||
const result = await Services.removeTeamRoom({ roomId: item._id, teamId: this.team.teamId });
|
||||
const result = await Services.removeTeamRoom({ roomId: item._id, teamId: this.team.teamId as string });
|
||||
if (result.success) {
|
||||
const newData = data.filter(room => result.room._id !== room._id);
|
||||
this.setState({ data: newData });
|
||||
|
@ -459,7 +447,7 @@ class TeamChannelsView extends React.Component<ITeamChannelsViewProps, ITeamChan
|
|||
const autoJoinIcon = isAutoJoinChecked ? 'checkbox-checked' : 'checkbox-unchecked';
|
||||
const autoJoinIconColor = isAutoJoinChecked ? themes[theme].tintActive : themes[theme].auxiliaryTintColor;
|
||||
|
||||
const options = [];
|
||||
const options: TActionSheetOptionsItem[] = [];
|
||||
|
||||
const permissionsTeam = await hasPermission([editTeamChannelPermission], this.team.rid);
|
||||
if (permissionsTeam[0]) {
|
||||
|
@ -582,11 +570,11 @@ const mapStateToProps = (state: IApplicationState) => ({
|
|||
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
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue