Icon, SeriesIndexFooter -> PureComponent

This commit is contained in:
Mark McDowall 2019-02-26 19:46:18 -08:00
parent 78b3c9552b
commit 84fa99a126
3 changed files with 179 additions and 159 deletions

View File

@ -1,49 +1,55 @@
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import React from 'react'; import React, { PureComponent } from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { kinds } from 'Helpers/Props'; import { kinds } from 'Helpers/Props';
import classNames from 'classnames'; import classNames from 'classnames';
import styles from './Icon.css'; import styles from './Icon.css';
function Icon(props) { class Icon extends PureComponent {
const {
containerClassName,
className,
name,
kind,
size,
title,
isSpinning,
...otherProps
} = props;
const icon = ( //
<FontAwesomeIcon // Render
className={classNames(
className,
styles[kind]
)}
icon={name}
spin={isSpinning}
style={{
fontSize: `${size}px`
}}
{...otherProps}
/>
);
if (title) { render() {
return ( const {
<span containerClassName,
className={containerClassName} className,
title={title} name,
> kind,
{icon} size,
</span> title,
isSpinning,
...otherProps
} = this.props;
const icon = (
<FontAwesomeIcon
className={classNames(
className,
styles[kind]
)}
icon={name}
spin={isSpinning}
style={{
fontSize: `${size}px`
}}
{...otherProps}
/>
); );
}
return icon; if (title) {
return (
<span
className={containerClassName}
title={title}
>
{icon}
</span>
);
}
return icon;
}
} }
Icon.propTypes = { Icon.propTypes = {

View File

@ -26,6 +26,13 @@ class PageJumpBar extends Component {
this.computeVisibleItems(); this.computeVisibleItems();
} }
shouldComponentUpdate(nextProps, nextState) {
return (
nextProps.items !== this.props.items ||
nextState.height !== this.state.height
);
}
componentDidUpdate(prevProps, prevState) { componentDidUpdate(prevProps, prevState) {
if ( if (
prevProps.items !== this.props.items || prevProps.items !== this.props.items ||

View File

@ -1,5 +1,5 @@
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import React from 'react'; import React, { PureComponent } from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import formatBytes from 'Utilities/Number/formatBytes'; import formatBytes from 'Utilities/Number/formatBytes';
import { ColorImpairedConsumer } from 'App/ColorImpairedContext'; import { ColorImpairedConsumer } from 'App/ColorImpairedContext';
@ -7,141 +7,148 @@ import DescriptionList from 'Components/DescriptionList/DescriptionList';
import DescriptionListItem from 'Components/DescriptionList/DescriptionListItem'; import DescriptionListItem from 'Components/DescriptionList/DescriptionListItem';
import styles from './SeriesIndexFooter.css'; import styles from './SeriesIndexFooter.css';
function SeriesIndexFooter({ series }) { class SeriesIndexFooter extends PureComponent {
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; // Render
const { render() {
episodeCount = 0, const { series } = this.props;
episodeFileCount = 0, const count = series.length;
sizeOnDisk = 0 let episodes = 0;
} = statistics; let episodeFiles = 0;
let ended = 0;
let continuing = 0;
let monitored = 0;
let totalFileSize = 0;
episodes += episodeCount; series.forEach((s) => {
episodeFiles += episodeFileCount; const { statistics = {} } = s;
if (s.status === 'ended') { const {
ended++; episodeCount = 0,
} else { episodeFileCount = 0,
continuing++; sizeOnDisk = 0
} } = statistics;
if (s.monitored) { episodes += episodeCount;
monitored++; episodeFiles += episodeFileCount;
}
totalFileSize += sizeOnDisk; if (s.status === 'ended') {
}); ended++;
} else {
continuing++;
}
return ( if (s.monitored) {
<ColorImpairedConsumer> monitored++;
{(enableColorImpairedMode) => { }
return (
<div className={styles.footer}> totalFileSize += sizeOnDisk;
<div> });
<div className={styles.legendItem}>
<div return (
className={classNames( <ColorImpairedConsumer>
styles.continuing, {(enableColorImpairedMode) => {
enableColorImpairedMode && 'colorImpaired' return (
)} <div className={styles.footer}>
/> <div>
<div>Continuing (All episodes downloaded)</div> <div className={styles.legendItem}>
<div
className={classNames(
styles.continuing,
enableColorImpairedMode && 'colorImpaired'
)}
/>
<div>Continuing (All episodes downloaded)</div>
</div>
<div className={styles.legendItem}>
<div
className={classNames(
styles.ended,
enableColorImpairedMode && 'colorImpaired'
)}
/>
<div>Ended (All episodes downloaded)</div>
</div>
<div className={styles.legendItem}>
<div
className={classNames(
styles.missingMonitored,
enableColorImpairedMode && 'colorImpaired'
)}
/>
<div>Missing Episodes (Series monitored)</div>
</div>
<div className={styles.legendItem}>
<div
className={classNames(
styles.missingUnmonitored,
enableColorImpairedMode && 'colorImpaired'
)}
/>
<div>Missing Episodes (Series not monitored)</div>
</div>
</div> </div>
<div className={styles.legendItem}> <div className={styles.statistics}>
<div <DescriptionList>
className={classNames( <DescriptionListItem
styles.ended, title="Series"
enableColorImpairedMode && 'colorImpaired' data={count}
)} />
/>
<div>Ended (All episodes downloaded)</div>
</div>
<div className={styles.legendItem}> <DescriptionListItem
<div title="Ended"
className={classNames( data={ended}
styles.missingMonitored, />
enableColorImpairedMode && 'colorImpaired'
)}
/>
<div>Missing Episodes (Series monitored)</div>
</div>
<div className={styles.legendItem}> <DescriptionListItem
<div title="Continuing"
className={classNames( data={continuing}
styles.missingUnmonitored, />
enableColorImpairedMode && 'colorImpaired' </DescriptionList>
)}
/> <DescriptionList>
<div>Missing Episodes (Series not monitored)</div> <DescriptionListItem
title="Monitored"
data={monitored}
/>
<DescriptionListItem
title="Unmonitored"
data={count - monitored}
/>
</DescriptionList>
<DescriptionList>
<DescriptionListItem
title="Episodes"
data={episodes}
/>
<DescriptionListItem
title="Files"
data={episodeFiles}
/>
</DescriptionList>
<DescriptionList>
<DescriptionListItem
title="Total File Size"
data={formatBytes(totalFileSize)}
/>
</DescriptionList>
</div> </div>
</div> </div>
);
<div className={styles.statistics}> }}
<DescriptionList> </ColorImpairedConsumer>
<DescriptionListItem );
title="Series" }
data={count}
/>
<DescriptionListItem
title="Ended"
data={ended}
/>
<DescriptionListItem
title="Continuing"
data={continuing}
/>
</DescriptionList>
<DescriptionList>
<DescriptionListItem
title="Monitored"
data={monitored}
/>
<DescriptionListItem
title="Unmonitored"
data={count - monitored}
/>
</DescriptionList>
<DescriptionList>
<DescriptionListItem
title="Episodes"
data={episodes}
/>
<DescriptionListItem
title="Files"
data={episodeFiles}
/>
</DescriptionList>
<DescriptionList>
<DescriptionListItem
title="Total File Size"
data={formatBytes(totalFileSize)}
/>
</DescriptionList>
</div>
</div>
);
}}
</ColorImpairedConsumer>
);
} }
SeriesIndexFooter.propTypes = { SeriesIndexFooter.propTypes = {