Ensure left pane properly handles just pinned/archived

This commit is contained in:
Evan Hahn 2020-10-16 17:05:40 -05:00 committed by GitHub
parent fb7c1e9030
commit de5595514b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 168 additions and 6 deletions

View file

@ -150,11 +150,13 @@ export class LeftPane extends React.Component<PropsType> {
}
conversationIndex -= pinnedConversations.length + 2;
} else {
} else if (index < pinnedConversations.length) {
return {
index,
type: RowType.PinnedConversation,
};
} else {
conversationIndex = 0;
}
}
@ -610,13 +612,34 @@ export class LeftPane extends React.Component<PropsType> {
}
componentDidUpdate(oldProps: PropsType): void {
const { pinnedConversations: oldPinned } = oldProps;
const { pinnedConversations: pinned } = this.props;
const {
conversations: oldConversations = [],
pinnedConversations: oldPinnedConversations = [],
archivedConversations: oldArchivedConversations = [],
showArchived: oldShowArchived,
} = oldProps;
const {
conversations: newConversations = [],
pinnedConversations: newPinnedConversations = [],
archivedConversations: newArchivedConversations = [],
showArchived: newShowArchived,
} = this.props;
const oldLength = (oldPinned && oldPinned.length) || 0;
const newLength = (pinned && pinned.length) || 0;
const oldHasArchivedConversations = Boolean(
oldArchivedConversations.length
);
const newHasArchivedConversations = Boolean(
newArchivedConversations.length
);
if (oldLength !== newLength) {
// This could probably be optimized further, but we want to be extra-careful that our
// heights are correct.
if (
oldConversations.length !== newConversations.length ||
oldPinnedConversations.length !== newPinnedConversations.length ||
oldHasArchivedConversations !== newHasArchivedConversations ||
oldShowArchived !== newShowArchived
) {
this.recomputeRowHeights();
}
}