From f9394b66e33ad0401668f818e016b9f2dd9867fb Mon Sep 17 00:00:00 2001 From: Gerzon Z Date: Mon, 16 May 2022 14:14:04 -0400 Subject: [PATCH] Chore: evaluate `RoomsListView` (#4147) --- app/views/RoomsListView/index.tsx | 81 +++++++++++++++---------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/app/views/RoomsListView/index.tsx b/app/views/RoomsListView/index.tsx index fefd863d..a9199bad 100644 --- a/app/views/RoomsListView/index.tsx +++ b/app/views/RoomsListView/index.tsx @@ -61,7 +61,7 @@ import { E2E_BANNER_TYPE, DisplayMode, SortBy, MAX_SIDEBAR_WIDTH, themes } from import { Services } from '../../lib/services'; interface IRoomsListViewProps extends IBaseScreen { - [key: string]: any; + [key: string]: IUser | string | boolean | ISubscription[] | number | object | TEncryptionBanner; user: IUser; server: string; searchText: string; @@ -76,7 +76,7 @@ interface IRoomsListViewProps extends IBaseScreen { - internalSetState = (...args: any) => { + internalSetState = ( + state: + | (( + prevState: Readonly, + props: Readonly + ) => Pick | IRoomsListViewState | null) + | (Pick | IRoomsListViewState | null), + callback?: () => void + ) => { if (this.animated) { animateNextTransition(); } - // @ts-ignore - this.setState(...args); + this.setState(state, callback); }; addRoomsGroup = (data: TSubscriptionModel[], header: string, allData: TSubscriptionModel[]) => { @@ -570,23 +575,12 @@ class RoomsListView extends React.Component { const { chats } = this.state; const { isMasterDetail } = this.props; - const filteredChats = chats.filter(c => !c.separator); + const filteredChats = chats ? chats.filter(c => !c.separator) : []; const room = filteredChats[index - 1]; if (room) { this.goRoom({ item: room, isMasterDetail }); @@ -800,7 +794,7 @@ class RoomsListView extends React.Component { const { chats } = this.state; const otherIndex = index + sign; - const otherRoom = chats[otherIndex]; + const otherRoom = chats?.length ? chats[otherIndex] : ({} as IRoomItem); if (!otherRoom) { return; } @@ -820,12 +814,17 @@ class RoomsListView extends React.Component 0) { + if (search && search?.length > 0) { return; } const { chats } = this.state; const { isMasterDetail } = this.props; + + if (!chats?.length) { + return; + } + const index = chats.findIndex(c => c.rid === item.rid); const otherRoom = this.findOtherRoom(index, sign); if (otherRoom) { @@ -908,7 +907,7 @@ class RoomsListView extends React.Component; }; - renderItem = ({ item }: { item: ISubscription }) => { + renderItem = ({ item }: { item: IRoomItem }) => { if (item.separator) { return this.renderSectionHeader(item.rid); }