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 = {
|
export type ModalStackParamList = {
|
||||||
RoomActionsView: {
|
RoomActionsView: {
|
||||||
room: ISubscription;
|
room: ISubscription;
|
||||||
member: any;
|
member?: any;
|
||||||
rid: string;
|
rid: string;
|
||||||
t: SubscriptionType;
|
t: SubscriptionType;
|
||||||
joined: boolean;
|
joined: boolean;
|
||||||
|
@ -135,6 +135,7 @@ export type ModalStackParamList = {
|
||||||
};
|
};
|
||||||
TeamChannelsView: {
|
TeamChannelsView: {
|
||||||
teamId: string;
|
teamId: string;
|
||||||
|
joined: boolean;
|
||||||
};
|
};
|
||||||
MarkdownTableView: {
|
MarkdownTableView: {
|
||||||
renderRows: Function;
|
renderRows: Function;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { NavigatorScreenParams } from '@react-navigation/core';
|
import { NavigatorScreenParams } from '@react-navigation/core';
|
||||||
import { TextInputProps } from 'react-native';
|
import { TextInputProps } from 'react-native';
|
||||||
|
|
||||||
|
import { IItem } from '../views/TeamChannelsView';
|
||||||
import { IOptionsField } from '../views/NotificationPreferencesView/options';
|
import { IOptionsField } from '../views/NotificationPreferencesView/options';
|
||||||
import { IServer } from '../definitions/IServer';
|
import { IServer } from '../definitions/IServer';
|
||||||
import { IAttachment } from '../definitions/IAttachment';
|
import { IAttachment } from '../definitions/IAttachment';
|
||||||
|
@ -36,7 +37,7 @@ export type ChatsStackParamList = {
|
||||||
| undefined; // Navigates back to RoomView already on stack
|
| undefined; // Navigates back to RoomView already on stack
|
||||||
RoomActionsView: {
|
RoomActionsView: {
|
||||||
room: TSubscriptionModel;
|
room: TSubscriptionModel;
|
||||||
member: any;
|
member?: any;
|
||||||
rid: string;
|
rid: string;
|
||||||
t: SubscriptionType;
|
t: SubscriptionType;
|
||||||
joined: boolean;
|
joined: boolean;
|
||||||
|
@ -125,6 +126,7 @@ export type ChatsStackParamList = {
|
||||||
};
|
};
|
||||||
TeamChannelsView: {
|
TeamChannelsView: {
|
||||||
teamId: string;
|
teamId: string;
|
||||||
|
joined: boolean;
|
||||||
};
|
};
|
||||||
CreateChannelView: {
|
CreateChannelView: {
|
||||||
isTeam?: boolean; // TODO: To check
|
isTeam?: boolean; // TODO: To check
|
||||||
|
@ -132,11 +134,11 @@ export type ChatsStackParamList = {
|
||||||
};
|
};
|
||||||
AddChannelTeamView: {
|
AddChannelTeamView: {
|
||||||
teamId?: string;
|
teamId?: string;
|
||||||
teamChannels: []; // TODO: Change
|
teamChannels: IItem[];
|
||||||
};
|
};
|
||||||
AddExistingChannelView: {
|
AddExistingChannelView: {
|
||||||
teamId?: string;
|
teamId?: string;
|
||||||
teamChannels: []; // TODO: Change
|
teamChannels: IItem[];
|
||||||
};
|
};
|
||||||
MarkdownTableView: {
|
MarkdownTableView: {
|
||||||
renderRows: (drawExtraBorders?: boolean) => JSX.Element;
|
renderRows: (drawExtraBorders?: boolean) => JSX.Element;
|
||||||
|
|
|
@ -128,7 +128,7 @@ class RightButtonsContainer extends Component<IRightButtonsProps, IRigthButtonsS
|
||||||
|
|
||||||
goTeamChannels = () => {
|
goTeamChannels = () => {
|
||||||
logEvent(events.ROOM_GO_TEAM_CHANNELS);
|
logEvent(events.ROOM_GO_TEAM_CHANNELS);
|
||||||
const { navigation, isMasterDetail, teamId } = this.props;
|
const { navigation, isMasterDetail, teamId, joined } = this.props;
|
||||||
if (!teamId) {
|
if (!teamId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -136,10 +136,10 @@ class RightButtonsContainer extends Component<IRightButtonsProps, IRigthButtonsS
|
||||||
// @ts-ignore TODO: find a way to make this work
|
// @ts-ignore TODO: find a way to make this work
|
||||||
navigation.navigate('ModalStackNavigator', {
|
navigation.navigate('ModalStackNavigator', {
|
||||||
screen: 'TeamChannelsView',
|
screen: 'TeamChannelsView',
|
||||||
params: { teamId }
|
params: { teamId, joined }
|
||||||
});
|
});
|
||||||
} else {
|
} 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 React from 'react';
|
||||||
|
import { Q } from '@nozbe/watermelondb';
|
||||||
|
import { HeaderBackButton, StackNavigationOptions } from '@react-navigation/stack';
|
||||||
import { Alert, FlatList, Keyboard } from 'react-native';
|
import { Alert, FlatList, Keyboard } from 'react-native';
|
||||||
import { EdgeInsets, withSafeAreaInsets } from 'react-native-safe-area-context';
|
import { EdgeInsets, withSafeAreaInsets } from 'react-native-safe-area-context';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { Dispatch } from 'redux';
|
|
||||||
|
|
||||||
import { deleteRoom } from '../actions/room';
|
import { deleteRoom } from '../actions/room';
|
||||||
import { themes } from '../lib/constants';
|
import { DisplayMode, themes } from '../lib/constants';
|
||||||
import { withActionSheet } from '../containers/ActionSheet';
|
import { TActionSheetOptions, TActionSheetOptionsItem, withActionSheet } from '../containers/ActionSheet';
|
||||||
import ActivityIndicator from '../containers/ActivityIndicator';
|
import ActivityIndicator from '../containers/ActivityIndicator';
|
||||||
import BackgroundContainer from '../containers/BackgroundContainer';
|
import BackgroundContainer from '../containers/BackgroundContainer';
|
||||||
import { getHeaderTitlePosition } from '../containers/Header';
|
import { getHeaderTitlePosition } from '../containers/Header';
|
||||||
|
@ -17,7 +16,7 @@ import RoomHeader from '../containers/RoomHeader';
|
||||||
import SafeAreaView from '../containers/SafeAreaView';
|
import SafeAreaView from '../containers/SafeAreaView';
|
||||||
import SearchHeader from '../containers/SearchHeader';
|
import SearchHeader from '../containers/SearchHeader';
|
||||||
import StatusBar from '../containers/StatusBar';
|
import StatusBar from '../containers/StatusBar';
|
||||||
import { IApplicationState, IBaseScreen } from '../definitions';
|
import { IApplicationState, IBaseScreen, TSubscriptionModel } from '../definitions';
|
||||||
import { ERoomType } from '../definitions/ERoomType';
|
import { ERoomType } from '../definitions/ERoomType';
|
||||||
import { withDimensions } from '../dimensions';
|
import { withDimensions } from '../dimensions';
|
||||||
import I18n from '../i18n';
|
import I18n from '../i18n';
|
||||||
|
@ -26,7 +25,7 @@ import { CustomIcon } from '../containers/CustomIcon';
|
||||||
import RoomItem, { ROW_HEIGHT } from '../containers/RoomItem';
|
import RoomItem, { ROW_HEIGHT } from '../containers/RoomItem';
|
||||||
import { getUserSelector } from '../selectors/login';
|
import { getUserSelector } from '../selectors/login';
|
||||||
import { ChatsStackParamList } from '../stacks/types';
|
import { ChatsStackParamList } from '../stacks/types';
|
||||||
import { TSupportedThemes, withTheme } from '../theme';
|
import { withTheme } from '../theme';
|
||||||
import debounce from '../utils/debounce';
|
import debounce from '../utils/debounce';
|
||||||
import { isIOS } from '../utils/deviceInfo';
|
import { isIOS } from '../utils/deviceInfo';
|
||||||
import { goRoom } from '../utils/goRoom';
|
import { goRoom } from '../utils/goRoom';
|
||||||
|
@ -36,11 +35,6 @@ import { getRoomAvatar, getRoomTitle, hasPermission } from '../lib/methods';
|
||||||
import { Services } from '../lib/services';
|
import { Services } from '../lib/services';
|
||||||
|
|
||||||
const API_FETCH_COUNT = 25;
|
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) => ({
|
const getItemLayout = (data: IItem[] | null | undefined, index: number) => ({
|
||||||
length: data?.length || 0,
|
length: data?.length || 0,
|
||||||
|
@ -49,8 +43,7 @@ const getItemLayout = (data: IItem[] | null | undefined, index: number) => ({
|
||||||
});
|
});
|
||||||
const keyExtractor = (item: IItem) => item._id;
|
const keyExtractor = (item: IItem) => item._id;
|
||||||
|
|
||||||
// This interface comes from request getTeamListRoom
|
export interface IItem {
|
||||||
interface IItem {
|
|
||||||
_id: ERoomType;
|
_id: ERoomType;
|
||||||
fname: string;
|
fname: string;
|
||||||
customFields: object;
|
customFields: object;
|
||||||
|
@ -81,14 +74,8 @@ interface ITeamChannelsViewState {
|
||||||
showCreate: boolean;
|
showCreate: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
type IProps = Omit<IBaseScreen<ChatsStackParamList, 'TeamChannelsView'>, 'navigation'> & {
|
interface ITeamChannelsViewProps extends IBaseScreen<ChatsStackParamList, 'TeamChannelsView'> {
|
||||||
navigation: StackNavigationProp<any, 'TeamChannelsView'>;
|
|
||||||
};
|
|
||||||
|
|
||||||
interface ITeamChannelsViewProps extends IProps {
|
|
||||||
isMasterDetail: boolean;
|
|
||||||
insets: EdgeInsets;
|
insets: EdgeInsets;
|
||||||
theme: TSupportedThemes;
|
|
||||||
useRealName: boolean;
|
useRealName: boolean;
|
||||||
width: number;
|
width: number;
|
||||||
StoreLastMessage: boolean;
|
StoreLastMessage: boolean;
|
||||||
|
@ -97,22 +84,21 @@ interface ITeamChannelsViewProps extends IProps {
|
||||||
removeTeamChannelPermission: string[];
|
removeTeamChannelPermission: string[];
|
||||||
deleteCPermission: string[];
|
deleteCPermission: string[];
|
||||||
deletePPermission: string[];
|
deletePPermission: string[];
|
||||||
showActionSheet: (options: any) => void;
|
showActionSheet: (options: TActionSheetOptions) => void;
|
||||||
showAvatar: boolean;
|
showAvatar: boolean;
|
||||||
displayMode: string;
|
displayMode: DisplayMode;
|
||||||
dispatch: Dispatch;
|
|
||||||
}
|
}
|
||||||
class TeamChannelsView extends React.Component<ITeamChannelsViewProps, ITeamChannelsViewState> {
|
class TeamChannelsView extends React.Component<ITeamChannelsViewProps, ITeamChannelsViewState> {
|
||||||
private teamId: string;
|
private teamId: string;
|
||||||
|
private joined: boolean;
|
||||||
// TODO: Refactor when migrate room
|
private teamChannels: TSubscriptionModel[];
|
||||||
private teamChannels: any;
|
private team: TSubscriptionModel;
|
||||||
|
|
||||||
// TODO: Refactor when migrate room
|
|
||||||
private team: any;
|
|
||||||
|
|
||||||
constructor(props: ITeamChannelsViewProps) {
|
constructor(props: ITeamChannelsViewProps) {
|
||||||
super(props);
|
super(props);
|
||||||
|
this.teamChannels = [];
|
||||||
|
this.team = {} as TSubscriptionModel;
|
||||||
|
this.joined = props.route.params?.joined;
|
||||||
this.teamId = props.route.params?.teamId;
|
this.teamId = props.route.params?.teamId;
|
||||||
this.state = {
|
this.state = {
|
||||||
loading: true,
|
loading: true,
|
||||||
|
@ -139,8 +125,8 @@ class TeamChannelsView extends React.Component<ITeamChannelsViewProps, ITeamChan
|
||||||
const db = database.active;
|
const db = database.active;
|
||||||
try {
|
try {
|
||||||
const subCollection = db.get('subscriptions');
|
const subCollection = db.get('subscriptions');
|
||||||
this.teamChannels = await subCollection.query(Q.where('team_id', Q.eq(this.teamId)));
|
this.teamChannels = await subCollection.query(Q.where('team_id', Q.eq(this.teamId))).fetch();
|
||||||
this.team = this.teamChannels?.find((channel: any) => channel.teamMain);
|
this.team = this.teamChannels?.find((channel: TSubscriptionModel) => channel.teamMain) as TSubscriptionModel;
|
||||||
this.setHeader();
|
this.setHeader();
|
||||||
|
|
||||||
if (!this.team) {
|
if (!this.team) {
|
||||||
|
@ -188,11 +174,9 @@ class TeamChannelsView extends React.Component<ITeamChannelsViewProps, ITeamChan
|
||||||
} as ITeamChannelsViewState;
|
} as ITeamChannelsViewState;
|
||||||
|
|
||||||
if (isSearching) {
|
if (isSearching) {
|
||||||
// @ts-ignore
|
newState.search = [...search, ...result.rooms] as IItem[];
|
||||||
newState.search = [...search, ...result.rooms];
|
|
||||||
} else {
|
} else {
|
||||||
// @ts-ignore
|
newState.data = [...data, ...result.rooms] as IItem[];
|
||||||
newState.data = [...data, ...result.rooms];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState(newState);
|
this.setState(newState);
|
||||||
|
@ -315,23 +299,27 @@ class TeamChannelsView extends React.Component<ITeamChannelsViewProps, ITeamChan
|
||||||
|
|
||||||
goRoomActionsView = (screen: string) => {
|
goRoomActionsView = (screen: string) => {
|
||||||
logEvent(events.TC_GO_ACTIONS);
|
logEvent(events.TC_GO_ACTIONS);
|
||||||
const { team } = this;
|
const { team, joined } = this;
|
||||||
const { navigation, isMasterDetail } = this.props;
|
const { navigation, isMasterDetail } = this.props;
|
||||||
if (isMasterDetail) {
|
if (!team) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isMasterDetail && screen) {
|
||||||
navigation.navigate('ModalStackNavigator', {
|
navigation.navigate('ModalStackNavigator', {
|
||||||
screen: screen ?? 'RoomActionsView',
|
screen: 'RoomActionsView',
|
||||||
params: {
|
params: {
|
||||||
rid: team.rid,
|
rid: team.rid,
|
||||||
t: team.t,
|
t: team.t,
|
||||||
room: team,
|
room: team,
|
||||||
showCloseModal: false
|
joined
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
navigation.navigate('RoomActionsView', {
|
navigation.navigate('RoomActionsView', {
|
||||||
rid: team.rid,
|
rid: team.rid,
|
||||||
t: team.t,
|
t: team.t,
|
||||||
room: team
|
room: team,
|
||||||
|
joined
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -411,7 +399,7 @@ class TeamChannelsView extends React.Component<ITeamChannelsViewProps, ITeamChan
|
||||||
logEvent(events.TC_DELETE_ROOM);
|
logEvent(events.TC_DELETE_ROOM);
|
||||||
try {
|
try {
|
||||||
const { data } = this.state;
|
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) {
|
if (result.success) {
|
||||||
const newData = data.filter(room => result.room._id !== room._id);
|
const newData = data.filter(room => result.room._id !== room._id);
|
||||||
this.setState({ data: newData });
|
this.setState({ data: newData });
|
||||||
|
@ -459,7 +447,7 @@ class TeamChannelsView extends React.Component<ITeamChannelsViewProps, ITeamChan
|
||||||
const autoJoinIcon = isAutoJoinChecked ? 'checkbox-checked' : 'checkbox-unchecked';
|
const autoJoinIcon = isAutoJoinChecked ? 'checkbox-checked' : 'checkbox-unchecked';
|
||||||
const autoJoinIconColor = isAutoJoinChecked ? themes[theme].tintActive : themes[theme].auxiliaryTintColor;
|
const autoJoinIconColor = isAutoJoinChecked ? themes[theme].tintActive : themes[theme].auxiliaryTintColor;
|
||||||
|
|
||||||
const options = [];
|
const options: TActionSheetOptionsItem[] = [];
|
||||||
|
|
||||||
const permissionsTeam = await hasPermission([editTeamChannelPermission], this.team.rid);
|
const permissionsTeam = await hasPermission([editTeamChannelPermission], this.team.rid);
|
||||||
if (permissionsTeam[0]) {
|
if (permissionsTeam[0]) {
|
||||||
|
@ -582,11 +570,11 @@ const mapStateToProps = (state: IApplicationState) => ({
|
||||||
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[PERMISSION_ADD_TEAM_CHANNEL],
|
addTeamChannelPermission: state.permissions['add-team-channel'],
|
||||||
editTeamChannelPermission: state.permissions[PERMISSION_EDIT_TEAM_CHANNEL],
|
editTeamChannelPermission: state.permissions['edit-team-channel'],
|
||||||
removeTeamChannelPermission: state.permissions[PERMISSION_REMOVE_TEAM_CHANNEL],
|
removeTeamChannelPermission: state.permissions['remove-team-channel'],
|
||||||
deleteCPermission: state.permissions[PERMISSION_DELETE_C],
|
deleteCPermission: state.permissions['delete-c'],
|
||||||
deletePPermission: state.permissions[PERMISSION_DELETE_P],
|
deletePPermission: state.permissions['delete-p'],
|
||||||
showAvatar: state.sortPreferences.showAvatar,
|
showAvatar: state.sortPreferences.showAvatar,
|
||||||
displayMode: state.sortPreferences.displayMode
|
displayMode: state.sortPreferences.displayMode
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue