Don't constantly re-mount the sublists with a new addRoomFn

Any time we though that the room list had to re-render we were dynamically creating a new addRoomFn, which would signal to the sublist that it needed to re-render. 

The only reason we wrap the function from the aesthetics is to provide theoretical tiling/multiaccount support through use of different dispatchers, however considering that's not a reality yet we can just use a default dispatcher when none is supplied.
This commit is contained in:
Travis Ralston 2020-07-23 22:12:10 -06:00
parent 7b97c3032b
commit ad92e6ba00

View File

@ -81,7 +81,7 @@ interface ITagAesthetics {
sectionLabel: string; sectionLabel: string;
sectionLabelRaw?: string; sectionLabelRaw?: string;
addRoomLabel?: string; addRoomLabel?: string;
onAddRoom?: (dispatcher: Dispatcher<ActionPayload>) => void; onAddRoom?: (dispatcher?: Dispatcher<ActionPayload>) => void;
isInvite: boolean; isInvite: boolean;
defaultHidden: boolean; defaultHidden: boolean;
} }
@ -105,14 +105,18 @@ const TAG_AESTHETICS: {
isInvite: false, isInvite: false,
defaultHidden: false, defaultHidden: false,
addRoomLabel: _td("Start chat"), addRoomLabel: _td("Start chat"),
onAddRoom: (dispatcher: Dispatcher<ActionPayload>) => dispatcher.dispatch({action: 'view_create_chat'}), onAddRoom: (dispatcher?: Dispatcher<ActionPayload>) => {
(dispatcher || defaultDispatcher).dispatch({action: 'view_create_chat'});
},
}, },
[DefaultTagID.Untagged]: { [DefaultTagID.Untagged]: {
sectionLabel: _td("Rooms"), sectionLabel: _td("Rooms"),
isInvite: false, isInvite: false,
defaultHidden: false, defaultHidden: false,
addRoomLabel: _td("Create room"), addRoomLabel: _td("Create room"),
onAddRoom: (dispatcher: Dispatcher<ActionPayload>) => dispatcher.dispatch({action: 'view_create_room'}), onAddRoom: (dispatcher?: Dispatcher<ActionPayload>) => {
(dispatcher || defaultDispatcher).dispatch({action: 'view_create_room'})
},
}, },
[DefaultTagID.LowPriority]: { [DefaultTagID.LowPriority]: {
sectionLabel: _td("Low priority"), sectionLabel: _td("Low priority"),
@ -304,7 +308,6 @@ export default class RoomList extends React.Component<IProps, IState> {
: TAG_AESTHETICS[orderedTagId]; : TAG_AESTHETICS[orderedTagId];
if (!aesthetics) throw new Error(`Tag ${orderedTagId} does not have aesthetics`); if (!aesthetics) throw new Error(`Tag ${orderedTagId} does not have aesthetics`);
const onAddRoomFn = aesthetics.onAddRoom ? () => aesthetics.onAddRoom(dis) : null;
components.push( components.push(
<RoomSublist <RoomSublist
key={`sublist-${orderedTagId}`} key={`sublist-${orderedTagId}`}
@ -312,7 +315,7 @@ export default class RoomList extends React.Component<IProps, IState> {
forRooms={true} forRooms={true}
startAsHidden={aesthetics.defaultHidden} startAsHidden={aesthetics.defaultHidden}
label={aesthetics.sectionLabelRaw ? aesthetics.sectionLabelRaw : _t(aesthetics.sectionLabel)} label={aesthetics.sectionLabelRaw ? aesthetics.sectionLabelRaw : _t(aesthetics.sectionLabel)}
onAddRoom={onAddRoomFn} onAddRoom={aesthetics.onAddRoom}
addRoomLabel={aesthetics.addRoomLabel ? _t(aesthetics.addRoomLabel) : aesthetics.addRoomLabel} addRoomLabel={aesthetics.addRoomLabel ? _t(aesthetics.addRoomLabel) : aesthetics.addRoomLabel}
isMinimized={this.props.isMinimized} isMinimized={this.props.isMinimized}
onResize={this.props.onResize} onResize={this.props.onResize}