From 84fa99a126ddd53594b504d913bd63a8c9932b09 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 26 Feb 2019 19:46:18 -0800 Subject: [PATCH] Icon, SeriesIndexFooter -> PureComponent --- frontend/src/Components/Icon.js | 78 ++--- frontend/src/Components/Page/PageJumpBar.js | 7 + .../src/Series/Index/SeriesIndexFooter.js | 271 +++++++++--------- 3 files changed, 188 insertions(+), 168 deletions(-) diff --git a/frontend/src/Components/Icon.js b/frontend/src/Components/Icon.js index ae3f01c10..d7748d2e7 100644 --- a/frontend/src/Components/Icon.js +++ b/frontend/src/Components/Icon.js @@ -1,49 +1,55 @@ import PropTypes from 'prop-types'; -import React from 'react'; +import React, { PureComponent } from 'react'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { kinds } from 'Helpers/Props'; import classNames from 'classnames'; import styles from './Icon.css'; -function Icon(props) { - const { - containerClassName, - className, - name, - kind, - size, - title, - isSpinning, - ...otherProps - } = props; +class Icon extends PureComponent { - const icon = ( - - ); + // + // Render - if (title) { - return ( - - {icon} - + render() { + const { + containerClassName, + className, + name, + kind, + size, + title, + isSpinning, + ...otherProps + } = this.props; + + const icon = ( + ); - } - return icon; + if (title) { + return ( + + {icon} + + ); + } + + return icon; + } } Icon.propTypes = { diff --git a/frontend/src/Components/Page/PageJumpBar.js b/frontend/src/Components/Page/PageJumpBar.js index f7d44ae9a..f555d5426 100644 --- a/frontend/src/Components/Page/PageJumpBar.js +++ b/frontend/src/Components/Page/PageJumpBar.js @@ -26,6 +26,13 @@ class PageJumpBar extends Component { this.computeVisibleItems(); } + shouldComponentUpdate(nextProps, nextState) { + return ( + nextProps.items !== this.props.items || + nextState.height !== this.state.height + ); + } + componentDidUpdate(prevProps, prevState) { if ( prevProps.items !== this.props.items || diff --git a/frontend/src/Series/Index/SeriesIndexFooter.js b/frontend/src/Series/Index/SeriesIndexFooter.js index 92480c721..712937dc6 100644 --- a/frontend/src/Series/Index/SeriesIndexFooter.js +++ b/frontend/src/Series/Index/SeriesIndexFooter.js @@ -1,5 +1,5 @@ import PropTypes from 'prop-types'; -import React from 'react'; +import React, { PureComponent } from 'react'; import classNames from 'classnames'; import formatBytes from 'Utilities/Number/formatBytes'; import { ColorImpairedConsumer } from 'App/ColorImpairedContext'; @@ -7,141 +7,148 @@ import DescriptionList from 'Components/DescriptionList/DescriptionList'; import DescriptionListItem from 'Components/DescriptionList/DescriptionListItem'; import styles from './SeriesIndexFooter.css'; -function SeriesIndexFooter({ series }) { - const count = series.length; - let episodes = 0; - let episodeFiles = 0; - let ended = 0; - let continuing = 0; - let monitored = 0; - let totalFileSize = 0; - - series.forEach((s) => { - const { statistics = {} } = s; - - const { - episodeCount = 0, - episodeFileCount = 0, - sizeOnDisk = 0 - } = statistics; - - episodes += episodeCount; - episodeFiles += episodeFileCount; - - if (s.status === 'ended') { - ended++; - } else { - continuing++; - } - - if (s.monitored) { - monitored++; - } - - totalFileSize += sizeOnDisk; - }); - - return ( - - {(enableColorImpairedMode) => { - return ( -
-
-
-
-
Continuing (All episodes downloaded)
+class SeriesIndexFooter extends PureComponent { + + // + // Render + + render() { + const { series } = this.props; + const count = series.length; + let episodes = 0; + let episodeFiles = 0; + let ended = 0; + let continuing = 0; + let monitored = 0; + let totalFileSize = 0; + + series.forEach((s) => { + const { statistics = {} } = s; + + const { + episodeCount = 0, + episodeFileCount = 0, + sizeOnDisk = 0 + } = statistics; + + episodes += episodeCount; + episodeFiles += episodeFileCount; + + if (s.status === 'ended') { + ended++; + } else { + continuing++; + } + + if (s.monitored) { + monitored++; + } + + totalFileSize += sizeOnDisk; + }); + + return ( + + {(enableColorImpairedMode) => { + return ( +
+
+
+
+
Continuing (All episodes downloaded)
+
+ +
+
+
Ended (All episodes downloaded)
+
+ +
+
+
Missing Episodes (Series monitored)
+
+ +
+
+
Missing Episodes (Series not monitored)
+
-
-
-
Ended (All episodes downloaded)
+
+ + + + + + + + + + + + + + + + + + + + + + +
- -
-
-
Missing Episodes (Series monitored)
-
- -
-
-
Missing Episodes (Series not monitored)
-
-
- -
- - - - - - - - - - - - - - - - - - - - - - -
-
- ); - }} - - ); + ); + }} + + ); + } } SeriesIndexFooter.propTypes = {