From 9749603acdf1112a086d256d0138b013c2bbe100 Mon Sep 17 00:00:00 2001 From: Joachim Robert Date: Wed, 6 Feb 2019 19:27:36 +0100 Subject: [PATCH] Fixed `flow` errors --- components/ChecklistItem/Apps.js | 13 ++++++++----- components/ChecklistItem/index.js | 14 +++++++------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/components/ChecklistItem/Apps.js b/components/ChecklistItem/Apps.js index 834a337..17302a7 100644 --- a/components/ChecklistItem/Apps.js +++ b/components/ChecklistItem/Apps.js @@ -18,17 +18,20 @@ type State = { export class Apps extends React.Component { state = { overflowExpanded: false, contentHeight: 2000, }; + expandContentContainer: { current: null | HTMLDivElement } - constructor(props) { + constructor(props: Props) { super(props) if (!this.props.resource.apps) return null; this.expandContentContainer = React.createRef(); - } handleExpand = () => { - let expandContentHeight = this.expandContentContainer.current.scrollHeight; + let expandContentHeight = + this.expandContentContainer.current + ? this.expandContentContainer.current.scrollHeight + : this.state.contentHeight; this.setState({ contentHeight: expandContentHeight, @@ -41,7 +44,7 @@ export class Apps extends React.Component { render() { let appList = this.props.resource.apps; let overflowAppList; - if (appList.length > 3) { + if (appList && appList.length > 3) { overflowAppList = appList.slice(3, appList.length); appList = appList.slice(0, 3); } @@ -52,7 +55,7 @@ export class Apps extends React.Component { return ( Apps - {appList.map(app => ( + {appList && appList.map(app => ( ))} diff --git a/components/ChecklistItem/index.js b/components/ChecklistItem/index.js index 6aeaea4..2b9439b 100644 --- a/components/ChecklistItem/index.js +++ b/components/ChecklistItem/index.js @@ -30,8 +30,9 @@ type State = { class ChecklistItem extends React.Component { state = { isChecked: false, isLoading: true, isCollapsed: true, contentHeight: 2000, }; + contentContainer: { current: null | HTMLDivElement } - constructor(props) { + constructor(props: Props) { super(props); this.contentContainer = React.createRef(); @@ -47,9 +48,8 @@ class ChecklistItem extends React.Component { }); } - componentDidUpdate(prevProps, prevState) { - - if (prevState.isLoading && !this.state.isLoading) { + componentDidUpdate(prevProps: Props, prevState: State) { + if (prevState.isLoading && !this.state.isLoading && this.contentContainer.current) { return this.setState({ contentHeight: this.contentContainer.current.scrollHeight, }) @@ -65,11 +65,11 @@ class ChecklistItem extends React.Component { uncollapse = () => { this.setState(state => ({ isCollapsed: !state.isCollapsed })); - this.contentContainer.current.focus(); + this.contentContainer.current && this.contentContainer.current.focus(); }; - handleAppsExpand = appsContainerHeight => { - return this.setState({ + handleAppsExpand = (appsContainerHeight: number) => { + return this.contentContainer.current && this.setState({ contentHeight: this.contentContainer.current.scrollHeight + appsContainerHeight, }) }