refactor: leftpanemessagesection is now a functional component

pull/3083/head
William Grant 2 years ago
parent c93cc932fc
commit 38c390355d

@ -1,6 +1,3 @@
import autoBind from 'auto-bind';
import { Component } from 'react';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { AutoSizer, List, ListRowProps } from 'react-virtualized'; import { AutoSizer, List, ListRowProps } from 'react-virtualized';
import styled from 'styled-components'; import styled from 'styled-components';
@ -66,15 +63,10 @@ const ClosableOverlay = () => {
} }
}; };
export class LeftPaneMessageSection extends Component<Props> { export const LeftPaneMessageSection = (props: Props) => {
public constructor(props: Props) { const { conversationIds, hasSearchResults, leftOverlayMode } = props;
super(props);
autoBind(this);
}
public renderRow = ({ index, key, style }: ListRowProps): JSX.Element | null => {
const { conversationIds } = this.props;
const renderRow = ({ index, key, style }: ListRowProps): JSX.Element | null => {
// assume conversations that have been marked unapproved should be filtered out by selector. // assume conversations that have been marked unapproved should be filtered out by selector.
if (!conversationIds) { if (!conversationIds) {
throw new Error('renderRow: Tried to render without conversations'); throw new Error('renderRow: Tried to render without conversations');
@ -88,9 +80,7 @@ export class LeftPaneMessageSection extends Component<Props> {
return <ConversationListItem key={key} style={style} conversationId={conversationId} />; return <ConversationListItem key={key} style={style} conversationId={conversationId} />;
}; };
public renderList(): JSX.Element { const renderList = () => {
const { conversationIds, hasSearchResults } = this.props;
if (hasSearchResults) { if (hasSearchResults) {
return <SearchResults />; return <SearchResults />;
} }
@ -110,7 +100,7 @@ export class LeftPaneMessageSection extends Component<Props> {
height={height} height={height}
rowCount={length} rowCount={length}
rowHeight={64} rowHeight={64}
rowRenderer={this.renderRow} rowRenderer={renderRow}
width={width} width={width}
autoHeight={false} autoHeight={false}
conversationIds={conversationIds} conversationIds={conversationIds}
@ -119,20 +109,9 @@ export class LeftPaneMessageSection extends Component<Props> {
</AutoSizer> </AutoSizer>
</StyledLeftPaneList> </StyledLeftPaneList>
); );
} };
public render(): JSX.Element {
const { leftOverlayMode } = this.props;
return (
<StyledLeftPaneContent>
<LeftPaneSectionHeader />
{leftOverlayMode ? <ClosableOverlay /> : this.renderConversations()}
</StyledLeftPaneContent>
);
}
public renderConversations() { const renderConversations = () => {
return ( return (
<StyledConversationListContent> <StyledConversationListContent>
<SessionSearchInput /> <SessionSearchInput />
@ -141,8 +120,15 @@ export class LeftPaneMessageSection extends Component<Props> {
window.inboxStore?.dispatch(setLeftOverlayMode('message-requests')); window.inboxStore?.dispatch(setLeftOverlayMode('message-requests'));
}} }}
/> />
{this.renderList()} {renderList()}
</StyledConversationListContent> </StyledConversationListContent>
); );
} };
}
return (
<StyledLeftPaneContent>
<LeftPaneSectionHeader />
{leftOverlayMode ? <ClosableOverlay /> : renderConversations()}
</StyledLeftPaneContent>
);
};

Loading…
Cancel
Save