From fdcb02bfdc4b7dc2ca5a503c5a564f1314e7a3ba Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Mon, 14 Dec 2020 22:20:09 +1100 Subject: [PATCH] remove Section header rendering from static method, just render JSX --- js/models/conversations.js | 7 -- ts/components/LeftPane.tsx | 22 ----- .../session/LeftPaneContactSection.tsx | 15 ++-- .../session/LeftPaneMessageSection.tsx | 17 ++-- .../session/LeftPaneSectionHeader.tsx | 80 +++++-------------- .../session/LeftPaneSettingSection.tsx | 15 ++-- 6 files changed, 40 insertions(+), 116 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index 6231dde99..a617d3401 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -1782,13 +1782,6 @@ _.map(oldUnread, async providedM => { const m = getMessageController().register(providedM.id, providedM); - if (!this.messageCollection.get(m.id)) { - window.log.warn( - 'Marked a message as read in the database, but ' + - 'it was not in messageCollection.' - ); - } - await m.markRead(options.readAt); const errors = m.get('errors'); return { diff --git a/ts/components/LeftPane.tsx b/ts/components/LeftPane.tsx index 117dcdad2..640bf0d7e 100644 --- a/ts/components/LeftPane.tsx +++ b/ts/components/LeftPane.tsx @@ -58,28 +58,6 @@ export class LeftPane extends React.Component { this.handleSectionSelected = this.handleSectionSelected.bind(this); } - // this static function is set here to be used by all subsections (message, contacts,...) to render their headers - public static RENDER_HEADER( - labels: Array, - theme: DefaultTheme, - onTabSelected?: any, - buttonLabel?: string, - buttonIcon?: SessionIconType, - buttonClicked?: any - ): JSX.Element { - return ( - - ); - } - public handleSectionSelected(section: SectionType) { this.props.clearSearch(); this.props.focusSection(section); diff --git a/ts/components/session/LeftPaneContactSection.tsx b/ts/components/session/LeftPaneContactSection.tsx index 1c36a09bd..aa4f60632 100644 --- a/ts/components/session/LeftPaneContactSection.tsx +++ b/ts/components/session/LeftPaneContactSection.tsx @@ -16,6 +16,7 @@ import { } from './SessionClosableOverlay'; import { ToastUtils } from '../../session/utils'; import { DefaultTheme } from 'styled-components'; +import { LeftPaneSectionHeader } from './LeftPaneSectionHeader'; export interface Props { directContacts: Array; @@ -56,15 +57,11 @@ export class LeftPaneContactSection extends React.Component { } public renderHeader(): JSX.Element | undefined { - const labels = [window.i18n('contactsHeader')]; - - return LeftPane.RENDER_HEADER( - labels, - this.props.theme, - null, - undefined, - undefined, - undefined + return ( + ); } diff --git a/ts/components/session/LeftPaneMessageSection.tsx b/ts/components/session/LeftPaneMessageSection.tsx index be20c96f7..af2782ddb 100644 --- a/ts/components/session/LeftPaneMessageSection.tsx +++ b/ts/components/session/LeftPaneMessageSection.tsx @@ -29,6 +29,7 @@ import { import { OpenGroup } from '../../session/types'; import { ToastUtils } from '../../session/utils'; import { DefaultTheme } from 'styled-components'; +import { LeftPaneSectionHeader } from './LeftPaneSectionHeader'; export interface Props { searchTerm: string; @@ -187,15 +188,13 @@ export class LeftPaneMessageSection extends React.Component { } public renderHeader(): JSX.Element { - const labels = [window.i18n('messagesHeader')]; - - return LeftPane.RENDER_HEADER( - labels, - this.props.theme, - null, - undefined, - SessionIconType.Plus, - this.handleNewSessionButtonClick + return ( + ); } diff --git a/ts/components/session/LeftPaneSectionHeader.tsx b/ts/components/session/LeftPaneSectionHeader.tsx index f100f44cf..d14f990f0 100644 --- a/ts/components/session/LeftPaneSectionHeader.tsx +++ b/ts/components/session/LeftPaneSectionHeader.tsx @@ -37,77 +37,37 @@ const Tab = ({ }; interface Props { - onTabSelected: any; - selectedTab: number; - labels: Array; - buttonLabel?: string; + label?: string; buttonIcon?: SessionIconType; buttonClicked?: any; theme: DefaultTheme; } -interface State { - selectedTab: number; -} +export const LeftPaneSectionHeader = (props: Props) => { + const { label, buttonIcon, buttonClicked } = props; -export class LeftPaneSectionHeader extends React.Component { - constructor(props: any) { - super(props); - this.state = { selectedTab: 0 }; + const children = []; + if (label) { + children.push(); } - public render() { - const { selectedTab } = this.state; - const { labels, buttonLabel, buttonIcon, buttonClicked } = this.props; - - const hasButton = buttonLabel || buttonIcon; - - const children = []; - //loop to create children - for (let i = 0; i < labels.length; i++) { - children.push( - - ); - } - - if (hasButton) { - const buttonContent = buttonIcon ? ( + if (buttonIcon) { + const button = ( + - ) : ( - buttonLabel - ); - const button = ( - - {buttonContent} - - ); + + ); - children.push(button); - } - // Create the parent and add the children - return
{children}
; + children.push(button); } - - private readonly handleTabSelect = (tabType: number): void => { - this.setState({ - selectedTab: tabType, - }); - if (this.props.onTabSelected) { - this.props.onTabSelected(tabType); - } - }; -} + // Create the parent and add the children + return
{children}
; +}; diff --git a/ts/components/session/LeftPaneSettingSection.tsx b/ts/components/session/LeftPaneSettingSection.tsx index 5c509b6a5..83b041569 100644 --- a/ts/components/session/LeftPaneSettingSection.tsx +++ b/ts/components/session/LeftPaneSettingSection.tsx @@ -13,6 +13,7 @@ import { SessionIcon, SessionIconSize, SessionIconType } from './icon'; import { SessionSearchInput } from './SessionSearchInput'; import { SessionSettingCategory } from './settings/SessionSettings'; import { DefaultTheme } from 'styled-components'; +import { LeftPaneSectionHeader } from './LeftPaneSectionHeader'; interface Props { isSecondaryDevice: boolean; @@ -47,15 +48,11 @@ export class LeftPaneSettingSection extends React.Component { } public renderHeader(): JSX.Element | undefined { - const labels = [window.i18n('settingsHeader')]; - - return LeftPane.RENDER_HEADER( - labels, - this.props.theme, - null, - undefined, - undefined, - undefined + return ( + ); }