parent
f884a2689a
commit
5192c76717
@ -0,0 +1,330 @@
|
|||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import React, { Component } from 'react';
|
||||||
|
import TextTruncate from 'react-text-truncate';
|
||||||
|
import AuthorPoster from 'Author/AuthorPoster';
|
||||||
|
import HeartRating from 'Components/HeartRating';
|
||||||
|
import Icon from 'Components/Icon';
|
||||||
|
import Label from 'Components/Label';
|
||||||
|
import Marquee from 'Components/Marquee';
|
||||||
|
import Measure from 'Components/Measure';
|
||||||
|
import MonitorToggleButton from 'Components/MonitorToggleButton';
|
||||||
|
import Popover from 'Components/Tooltip/Popover';
|
||||||
|
import Tooltip from 'Components/Tooltip/Tooltip';
|
||||||
|
import { icons, kinds, sizes, tooltipPositions } from 'Helpers/Props';
|
||||||
|
import QualityProfileNameConnector from 'Settings/Profiles/Quality/QualityProfileNameConnector';
|
||||||
|
import fonts from 'Styles/Variables/fonts';
|
||||||
|
import formatBytes from 'Utilities/Number/formatBytes';
|
||||||
|
import stripHtml from 'Utilities/String/stripHtml';
|
||||||
|
import AuthorAlternateTitles from './AuthorAlternateTitles';
|
||||||
|
import AuthorDetailsLinks from './AuthorDetailsLinks';
|
||||||
|
import AuthorTagsConnector from './AuthorTagsConnector';
|
||||||
|
import styles from './AuthorDetails.css';
|
||||||
|
|
||||||
|
const defaultFontSize = parseInt(fonts.defaultFontSize);
|
||||||
|
const lineHeight = parseFloat(fonts.lineHeight);
|
||||||
|
|
||||||
|
function getFanartUrl(images) {
|
||||||
|
const fanartImage = images.find((x) => x.coverType === 'fanart');
|
||||||
|
|
||||||
|
if (fanartImage) {
|
||||||
|
// Remove protocol
|
||||||
|
return fanartImage.url.replace(/^https?:/, '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AuthorDetailsHeader extends Component {
|
||||||
|
|
||||||
|
//
|
||||||
|
// Lifecyle
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
overviewHeight: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Listeners
|
||||||
|
|
||||||
|
onOverviewMeasure = ({ height }) => {
|
||||||
|
console.log(`overview measure ${height}`);
|
||||||
|
this.setState({ overviewHeight: height });
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// Render
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const {
|
||||||
|
id,
|
||||||
|
width,
|
||||||
|
authorName,
|
||||||
|
ratings,
|
||||||
|
path,
|
||||||
|
statistics,
|
||||||
|
qualityProfileId,
|
||||||
|
monitored,
|
||||||
|
status,
|
||||||
|
overview,
|
||||||
|
links,
|
||||||
|
images,
|
||||||
|
alternateTitles,
|
||||||
|
tags,
|
||||||
|
isSaving,
|
||||||
|
isSmallScreen,
|
||||||
|
onMonitorTogglePress
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
|
const {
|
||||||
|
bookFileCount,
|
||||||
|
sizeOnDisk
|
||||||
|
} = statistics;
|
||||||
|
|
||||||
|
const {
|
||||||
|
overviewHeight
|
||||||
|
} = this.state;
|
||||||
|
|
||||||
|
const marqueeWidth = width - (isSmallScreen ? 115 : 225);
|
||||||
|
|
||||||
|
const continuing = status === 'continuing';
|
||||||
|
|
||||||
|
let bookFilesCountMessage = 'No book files';
|
||||||
|
|
||||||
|
if (bookFileCount === 1) {
|
||||||
|
bookFilesCountMessage = '1 book file';
|
||||||
|
} else if (bookFileCount > 1) {
|
||||||
|
bookFilesCountMessage = `${bookFileCount} book files`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.header}>
|
||||||
|
<div
|
||||||
|
className={styles.backdrop}
|
||||||
|
style={{
|
||||||
|
backgroundImage: `url(${getFanartUrl(images)})`
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div className={styles.backdropOverlay} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.headerContent}>
|
||||||
|
<AuthorPoster
|
||||||
|
className={styles.poster}
|
||||||
|
images={images}
|
||||||
|
size={250}
|
||||||
|
lazy={false}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className={styles.info}>
|
||||||
|
<div className={styles.titleRow}>
|
||||||
|
<div className={styles.titleContainer}>
|
||||||
|
<div className={styles.toggleMonitoredContainer}>
|
||||||
|
<MonitorToggleButton
|
||||||
|
className={styles.monitorToggleButton}
|
||||||
|
monitored={monitored}
|
||||||
|
isSaving={isSaving}
|
||||||
|
size={isSmallScreen ? 30: 40}
|
||||||
|
onPress={onMonitorTogglePress}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.title} style={{ width: marqueeWidth }}>
|
||||||
|
<Marquee text={authorName} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{
|
||||||
|
!!alternateTitles.length &&
|
||||||
|
<div className={styles.alternateTitlesIconContainer}>
|
||||||
|
<Popover
|
||||||
|
anchor={
|
||||||
|
<Icon
|
||||||
|
name={icons.ALTERNATE_TITLES}
|
||||||
|
size={20}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
title="Alternate Titles"
|
||||||
|
body={<AuthorAlternateTitles alternateTitles={alternateTitles} />}
|
||||||
|
position={tooltipPositions.BOTTOM}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.details}>
|
||||||
|
<div>
|
||||||
|
<HeartRating
|
||||||
|
rating={ratings.value}
|
||||||
|
iconSize={20}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.detailsLabels}>
|
||||||
|
<Label
|
||||||
|
className={styles.detailsLabel}
|
||||||
|
size={sizes.LARGE}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
name={icons.FOLDER}
|
||||||
|
size={17}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<span className={styles.path}>
|
||||||
|
{path}
|
||||||
|
</span>
|
||||||
|
</Label>
|
||||||
|
|
||||||
|
<Label
|
||||||
|
className={styles.detailsLabel}
|
||||||
|
title={bookFilesCountMessage}
|
||||||
|
size={sizes.LARGE}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
name={icons.DRIVE}
|
||||||
|
size={17}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<span className={styles.sizeOnDisk}>
|
||||||
|
{
|
||||||
|
formatBytes(sizeOnDisk || 0)
|
||||||
|
}
|
||||||
|
</span>
|
||||||
|
</Label>
|
||||||
|
|
||||||
|
<Label
|
||||||
|
className={styles.detailsLabel}
|
||||||
|
title="Quality Profile"
|
||||||
|
size={sizes.LARGE}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
name={icons.PROFILE}
|
||||||
|
size={17}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<span className={styles.qualityProfileName}>
|
||||||
|
{
|
||||||
|
<QualityProfileNameConnector
|
||||||
|
qualityProfileId={qualityProfileId}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
</span>
|
||||||
|
</Label>
|
||||||
|
|
||||||
|
<Label
|
||||||
|
className={styles.detailsLabel}
|
||||||
|
size={sizes.LARGE}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
name={monitored ? icons.MONITORED : icons.UNMONITORED}
|
||||||
|
size={17}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<span className={styles.qualityProfileName}>
|
||||||
|
{monitored ? 'Monitored' : 'Unmonitored'}
|
||||||
|
</span>
|
||||||
|
</Label>
|
||||||
|
|
||||||
|
<Label
|
||||||
|
className={styles.detailsLabel}
|
||||||
|
title={continuing ? 'More books are expected' : 'No additional books are expected'}
|
||||||
|
size={sizes.LARGE}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
name={continuing ? icons.AUTHOR_CONTINUING : icons.AUTHOR_ENDED}
|
||||||
|
size={17}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<span className={styles.qualityProfileName}>
|
||||||
|
{continuing ? 'Continuing' : 'Deceased'}
|
||||||
|
</span>
|
||||||
|
</Label>
|
||||||
|
|
||||||
|
<Tooltip
|
||||||
|
anchor={
|
||||||
|
<Label
|
||||||
|
className={styles.detailsLabel}
|
||||||
|
size={sizes.LARGE}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
name={icons.EXTERNAL_LINK}
|
||||||
|
size={17}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<span className={styles.links}>
|
||||||
|
Links
|
||||||
|
</span>
|
||||||
|
</Label>
|
||||||
|
}
|
||||||
|
tooltip={
|
||||||
|
<AuthorDetailsLinks
|
||||||
|
links={links}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
kind={kinds.INVERSE}
|
||||||
|
position={tooltipPositions.BOTTOM}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{
|
||||||
|
!!tags.length &&
|
||||||
|
<Tooltip
|
||||||
|
anchor={
|
||||||
|
<Label
|
||||||
|
className={styles.detailsLabel}
|
||||||
|
size={sizes.LARGE}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
name={icons.TAGS}
|
||||||
|
size={17}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<span className={styles.tags}>
|
||||||
|
Tags
|
||||||
|
</span>
|
||||||
|
</Label>
|
||||||
|
}
|
||||||
|
tooltip={<AuthorTagsConnector authorId={id} />}
|
||||||
|
kind={kinds.INVERSE}
|
||||||
|
position={tooltipPositions.BOTTOM}
|
||||||
|
/>
|
||||||
|
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<Measure
|
||||||
|
onMeasure={this.onOverviewMeasure}
|
||||||
|
className={styles.overview}
|
||||||
|
>
|
||||||
|
<TextTruncate
|
||||||
|
line={Math.floor(overviewHeight / (defaultFontSize * lineHeight))}
|
||||||
|
text={stripHtml(overview)}
|
||||||
|
/>
|
||||||
|
</Measure>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AuthorDetailsHeader.propTypes = {
|
||||||
|
id: PropTypes.number.isRequired,
|
||||||
|
width: PropTypes.number.isRequired,
|
||||||
|
authorName: PropTypes.string.isRequired,
|
||||||
|
ratings: PropTypes.object.isRequired,
|
||||||
|
path: PropTypes.string.isRequired,
|
||||||
|
statistics: PropTypes.object.isRequired,
|
||||||
|
qualityProfileId: PropTypes.number.isRequired,
|
||||||
|
monitored: PropTypes.bool.isRequired,
|
||||||
|
status: PropTypes.string.isRequired,
|
||||||
|
overview: PropTypes.string,
|
||||||
|
links: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||||
|
images: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||||
|
alternateTitles: PropTypes.arrayOf(PropTypes.string).isRequired,
|
||||||
|
tags: PropTypes.arrayOf(PropTypes.number).isRequired,
|
||||||
|
isSaving: PropTypes.bool.isRequired,
|
||||||
|
isSmallScreen: PropTypes.bool.isRequired,
|
||||||
|
onMonitorTogglePress: PropTypes.func.isRequired
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AuthorDetailsHeader;
|
@ -0,0 +1,71 @@
|
|||||||
|
/* eslint max-params: 0 */
|
||||||
|
import _ from 'lodash';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import React, { Component } from 'react';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import { createSelector } from 'reselect';
|
||||||
|
import { toggleAuthorMonitored } from 'Store/Actions/authorActions';
|
||||||
|
import createAuthorSelector from 'Store/Selectors/createAuthorSelector';
|
||||||
|
import createDimensionsSelector from 'Store/Selectors/createDimensionsSelector';
|
||||||
|
import AuthorDetailsHeader from './AuthorDetailsHeader';
|
||||||
|
|
||||||
|
function createMapStateToProps() {
|
||||||
|
return createSelector(
|
||||||
|
(state) => state.authors,
|
||||||
|
createAuthorSelector(),
|
||||||
|
createDimensionsSelector(),
|
||||||
|
(authors, author, dimensions) => {
|
||||||
|
const alternateTitles = _.reduce(author.alternateTitles, (acc, alternateTitle) => {
|
||||||
|
if ((alternateTitle.seasonNumber === -1 || alternateTitle.seasonNumber === undefined) &&
|
||||||
|
(alternateTitle.sceneSeasonNumber === -1 || alternateTitle.sceneSeasonNumber === undefined)) {
|
||||||
|
acc.push(alternateTitle.title);
|
||||||
|
}
|
||||||
|
|
||||||
|
return acc;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...author,
|
||||||
|
isSaving: authors.isSaving,
|
||||||
|
alternateTitles,
|
||||||
|
isSmallScreen: dimensions.isSmallScreen
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapDispatchToProps = {
|
||||||
|
toggleAuthorMonitored
|
||||||
|
};
|
||||||
|
|
||||||
|
class AuthorDetailsHeaderConnector extends Component {
|
||||||
|
|
||||||
|
//
|
||||||
|
// Listeners
|
||||||
|
|
||||||
|
onMonitorTogglePress = (monitored) => {
|
||||||
|
this.props.toggleAuthorMonitored({
|
||||||
|
authorId: this.props.authorId,
|
||||||
|
monitored
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Render
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<AuthorDetailsHeader
|
||||||
|
{...this.props}
|
||||||
|
onMonitorTogglePress={this.onMonitorTogglePress}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AuthorDetailsHeaderConnector.propTypes = {
|
||||||
|
authorId: PropTypes.number.isRequired,
|
||||||
|
toggleAuthorMonitored: PropTypes.func.isRequired
|
||||||
|
};
|
||||||
|
|
||||||
|
export default connect(createMapStateToProps, mapDispatchToProps)(AuthorDetailsHeaderConnector);
|
@ -0,0 +1,256 @@
|
|||||||
|
import moment from 'moment';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import React, { Component } from 'react';
|
||||||
|
import TextTruncate from 'react-text-truncate';
|
||||||
|
import BookCover from 'Book/BookCover';
|
||||||
|
import HeartRating from 'Components/HeartRating';
|
||||||
|
import Icon from 'Components/Icon';
|
||||||
|
import Label from 'Components/Label';
|
||||||
|
import Marquee from 'Components/Marquee';
|
||||||
|
import Measure from 'Components/Measure';
|
||||||
|
import MonitorToggleButton from 'Components/MonitorToggleButton';
|
||||||
|
import Tooltip from 'Components/Tooltip/Tooltip';
|
||||||
|
import { icons, kinds, sizes, tooltipPositions } from 'Helpers/Props';
|
||||||
|
import fonts from 'Styles/Variables/fonts';
|
||||||
|
import formatBytes from 'Utilities/Number/formatBytes';
|
||||||
|
import stripHtml from 'Utilities/String/stripHtml';
|
||||||
|
import BookDetailsLinks from './BookDetailsLinks';
|
||||||
|
import styles from './BookDetails.css';
|
||||||
|
|
||||||
|
const defaultFontSize = parseInt(fonts.defaultFontSize);
|
||||||
|
const lineHeight = parseFloat(fonts.lineHeight);
|
||||||
|
|
||||||
|
function getFanartUrl(images) {
|
||||||
|
const fanartImage = images.find((x) => x.coverType === 'fanart');
|
||||||
|
|
||||||
|
if (fanartImage) {
|
||||||
|
// Remove protocol
|
||||||
|
return fanartImage.url.replace(/^https?:/, '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class BookDetailsHeader extends Component {
|
||||||
|
|
||||||
|
//
|
||||||
|
// Lifecycle
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
overviewHeight: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Listeners
|
||||||
|
|
||||||
|
onOverviewMeasure = ({ height }) => {
|
||||||
|
this.setState({ overviewHeight: height });
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Render
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const {
|
||||||
|
width,
|
||||||
|
titleSlug,
|
||||||
|
title,
|
||||||
|
seriesTitle,
|
||||||
|
pageCount,
|
||||||
|
overview,
|
||||||
|
statistics = {},
|
||||||
|
monitored,
|
||||||
|
releaseDate,
|
||||||
|
ratings,
|
||||||
|
images,
|
||||||
|
links,
|
||||||
|
isSaving,
|
||||||
|
shortDateFormat,
|
||||||
|
author,
|
||||||
|
isSmallScreen,
|
||||||
|
onMonitorTogglePress
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
|
const {
|
||||||
|
overviewHeight
|
||||||
|
} = this.state;
|
||||||
|
|
||||||
|
const marqueeWidth = width - (isSmallScreen ? 115 : 225);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.header}>
|
||||||
|
<div
|
||||||
|
className={styles.backdrop}
|
||||||
|
style={{
|
||||||
|
backgroundImage: `url(${getFanartUrl(author.images)})`
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div className={styles.backdropOverlay} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.headerContent}>
|
||||||
|
<BookCover
|
||||||
|
className={styles.cover}
|
||||||
|
images={images}
|
||||||
|
size={250}
|
||||||
|
lazy={false}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className={styles.info}>
|
||||||
|
<div className={styles.titleRow}>
|
||||||
|
<div className={styles.titleContainer}>
|
||||||
|
<div className={styles.toggleMonitoredContainer}>
|
||||||
|
<MonitorToggleButton
|
||||||
|
className={styles.monitorToggleButton}
|
||||||
|
monitored={monitored}
|
||||||
|
isSaving={isSaving}
|
||||||
|
size={isSmallScreen ? 30: 40}
|
||||||
|
onPress={onMonitorTogglePress}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.title} style={{ width: marqueeWidth }}>
|
||||||
|
<Marquee text={title} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.details}>
|
||||||
|
<div>
|
||||||
|
{seriesTitle}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{
|
||||||
|
!!pageCount &&
|
||||||
|
<span className={styles.duration}>
|
||||||
|
{`${pageCount} pages`}
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
|
||||||
|
<HeartRating
|
||||||
|
rating={ratings.value}
|
||||||
|
iconSize={20}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.detailsLabels}>
|
||||||
|
<Label
|
||||||
|
className={styles.detailsLabel}
|
||||||
|
size={sizes.LARGE}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
name={icons.CALENDAR}
|
||||||
|
size={17}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<span className={styles.sizeOnDisk}>
|
||||||
|
{
|
||||||
|
moment(releaseDate).format(shortDateFormat)
|
||||||
|
}
|
||||||
|
</span>
|
||||||
|
</Label>
|
||||||
|
|
||||||
|
<Label
|
||||||
|
className={styles.detailsLabel}
|
||||||
|
size={sizes.LARGE}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
name={icons.DRIVE}
|
||||||
|
size={17}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<span className={styles.sizeOnDisk}>
|
||||||
|
{
|
||||||
|
formatBytes(statistics.sizeOnDisk)
|
||||||
|
}
|
||||||
|
</span>
|
||||||
|
</Label>
|
||||||
|
|
||||||
|
<Label
|
||||||
|
className={styles.detailsLabel}
|
||||||
|
size={sizes.LARGE}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
name={monitored ? icons.MONITORED : icons.UNMONITORED}
|
||||||
|
size={17}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<span className={styles.qualityProfileName}>
|
||||||
|
{monitored ? 'Monitored' : 'Unmonitored'}
|
||||||
|
</span>
|
||||||
|
</Label>
|
||||||
|
|
||||||
|
<Tooltip
|
||||||
|
anchor={
|
||||||
|
<Label
|
||||||
|
className={styles.detailsLabel}
|
||||||
|
size={sizes.LARGE}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
name={icons.EXTERNAL_LINK}
|
||||||
|
size={17}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<span className={styles.links}>
|
||||||
|
Links
|
||||||
|
</span>
|
||||||
|
</Label>
|
||||||
|
}
|
||||||
|
tooltip={
|
||||||
|
<BookDetailsLinks
|
||||||
|
titleSlug={titleSlug}
|
||||||
|
links={links}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
kind={kinds.INVERSE}
|
||||||
|
position={tooltipPositions.BOTTOM}
|
||||||
|
/>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<Measure
|
||||||
|
onMeasure={this.onOverviewMeasure}
|
||||||
|
className={styles.overview}
|
||||||
|
>
|
||||||
|
<TextTruncate
|
||||||
|
line={Math.floor(overviewHeight / (defaultFontSize * lineHeight))}
|
||||||
|
text={stripHtml(overview)}
|
||||||
|
/>
|
||||||
|
</Measure>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BookDetailsHeader.propTypes = {
|
||||||
|
id: PropTypes.number.isRequired,
|
||||||
|
width: PropTypes.number.isRequired,
|
||||||
|
titleSlug: PropTypes.string.isRequired,
|
||||||
|
title: PropTypes.string.isRequired,
|
||||||
|
seriesTitle: PropTypes.string.isRequired,
|
||||||
|
pageCount: PropTypes.number,
|
||||||
|
overview: PropTypes.string,
|
||||||
|
statistics: PropTypes.object.isRequired,
|
||||||
|
releaseDate: PropTypes.string.isRequired,
|
||||||
|
ratings: PropTypes.object.isRequired,
|
||||||
|
images: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||||
|
links: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||||
|
monitored: PropTypes.bool.isRequired,
|
||||||
|
shortDateFormat: PropTypes.string.isRequired,
|
||||||
|
isSaving: PropTypes.bool.isRequired,
|
||||||
|
author: PropTypes.object,
|
||||||
|
isSmallScreen: PropTypes.bool.isRequired,
|
||||||
|
onMonitorTogglePress: PropTypes.func.isRequired
|
||||||
|
};
|
||||||
|
|
||||||
|
BookDetailsHeader.defaultProps = {
|
||||||
|
isSaving: false
|
||||||
|
};
|
||||||
|
|
||||||
|
export default BookDetailsHeader;
|
@ -0,0 +1,62 @@
|
|||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import React, { Component } from 'react';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import { createSelector } from 'reselect';
|
||||||
|
import { toggleBooksMonitored } from 'Store/Actions/bookActions';
|
||||||
|
import createBookSelector from 'Store/Selectors/createBookSelector';
|
||||||
|
import createDimensionsSelector from 'Store/Selectors/createDimensionsSelector';
|
||||||
|
import createUISettingsSelector from 'Store/Selectors/createUISettingsSelector';
|
||||||
|
import BookDetailsHeader from './BookDetailsHeader';
|
||||||
|
|
||||||
|
function createMapStateToProps() {
|
||||||
|
return createSelector(
|
||||||
|
createBookSelector(),
|
||||||
|
createUISettingsSelector(),
|
||||||
|
createDimensionsSelector(),
|
||||||
|
(book, uiSettings, dimensions) => {
|
||||||
|
|
||||||
|
return {
|
||||||
|
...book,
|
||||||
|
shortDateFormat: uiSettings.shortDateFormat,
|
||||||
|
isSmallScreen: dimensions.isSmallScreen
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapDispatchToProps = {
|
||||||
|
toggleBooksMonitored
|
||||||
|
};
|
||||||
|
|
||||||
|
class BookDetailsHeaderConnector extends Component {
|
||||||
|
|
||||||
|
//
|
||||||
|
// Listeners
|
||||||
|
|
||||||
|
onMonitorTogglePress = (monitored) => {
|
||||||
|
this.props.toggleBooksMonitored({
|
||||||
|
bookIds: [this.props.bookId],
|
||||||
|
monitored
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Render
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<BookDetailsHeader
|
||||||
|
{...this.props}
|
||||||
|
onMonitorTogglePress={this.onMonitorTogglePress}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BookDetailsHeaderConnector.propTypes = {
|
||||||
|
bookId: PropTypes.number,
|
||||||
|
toggleBooksMonitored: PropTypes.func.isRequired,
|
||||||
|
author: PropTypes.object
|
||||||
|
};
|
||||||
|
|
||||||
|
export default connect(createMapStateToProps, mapDispatchToProps)(BookDetailsHeaderConnector);
|
@ -0,0 +1,14 @@
|
|||||||
|
.container {
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
width: 300%;
|
||||||
|
height: 100%;
|
||||||
|
transition: var(--transition);
|
||||||
|
transform: translateX(var(--translate));
|
||||||
|
}
|
@ -0,0 +1,242 @@
|
|||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import React, { Component } from 'react';
|
||||||
|
import Measure from 'Components/Measure';
|
||||||
|
import styles from './SwipeHeader.css';
|
||||||
|
|
||||||
|
function cursorPosition(event) {
|
||||||
|
return event.touches ? event.touches[0].clientX : event.clientX;
|
||||||
|
}
|
||||||
|
|
||||||
|
class SwipeHeader extends Component {
|
||||||
|
|
||||||
|
//
|
||||||
|
// Lifecycle
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
containerWidth: 0,
|
||||||
|
touching: null,
|
||||||
|
translate: 0,
|
||||||
|
stage: 'init',
|
||||||
|
url: null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
this.removeEventListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Listeners
|
||||||
|
|
||||||
|
onMouseDown = (e) => {
|
||||||
|
if (!this.props.isSmallScreen || this.state.touching) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.startTouchPosition = cursorPosition(e);
|
||||||
|
this.initTranslate = this.state.translate;
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
stage: null,
|
||||||
|
touching: true }, () => {
|
||||||
|
this.addEventListeners();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
addEventListeners = () => {
|
||||||
|
window.addEventListener('mousemove', this.onMouseMove);
|
||||||
|
window.addEventListener('touchmove', this.onMouseMove);
|
||||||
|
window.addEventListener('mouseup', this.onMouseUp);
|
||||||
|
window.addEventListener('touchend', this.onMouseUp);
|
||||||
|
}
|
||||||
|
|
||||||
|
removeEventListeners = () => {
|
||||||
|
window.removeEventListener('mousemove', this.onMouseMove);
|
||||||
|
window.removeEventListener('touchmove', this.onMouseMove);
|
||||||
|
window.removeEventListener('mouseup', this.onMouseUp);
|
||||||
|
window.removeEventListener('touchend', this.onMouseUp);
|
||||||
|
}
|
||||||
|
|
||||||
|
onMouseMove = (e) => {
|
||||||
|
const {
|
||||||
|
touching,
|
||||||
|
containerWidth
|
||||||
|
} = this.state;
|
||||||
|
|
||||||
|
if (!touching) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const translate = Math.max(Math.min(cursorPosition(e) - this.startTouchPosition + this.initTranslate, containerWidth), -1 * containerWidth);
|
||||||
|
|
||||||
|
this.setState({ translate });
|
||||||
|
};
|
||||||
|
|
||||||
|
onMouseUp = () => {
|
||||||
|
this.startTouchPosition = null;
|
||||||
|
|
||||||
|
const {
|
||||||
|
nextLink,
|
||||||
|
prevLink,
|
||||||
|
navWidth
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
|
const {
|
||||||
|
containerWidth,
|
||||||
|
translate
|
||||||
|
} = this.state;
|
||||||
|
|
||||||
|
const newState = {
|
||||||
|
touching: false
|
||||||
|
};
|
||||||
|
|
||||||
|
const acceptableMove = navWidth * 0.7;
|
||||||
|
const showNav = Math.abs(translate) >= acceptableMove;
|
||||||
|
const navWithoutConfirm = Math.abs(translate) >= containerWidth * 0.5;
|
||||||
|
|
||||||
|
if (navWithoutConfirm) {
|
||||||
|
newState.translate = Math.sign(translate) * containerWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!showNav) {
|
||||||
|
newState.translate = 0;
|
||||||
|
newState.stage = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showNav && !navWithoutConfirm) {
|
||||||
|
newState.translate = Math.sign(translate) * navWidth;
|
||||||
|
newState.stage = 'showNav';
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setState(newState, () => {
|
||||||
|
if (navWithoutConfirm) {
|
||||||
|
this.onNavClick(translate < 0 ? nextLink : prevLink, Math.abs(translate) === containerWidth);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.removeEventListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
onNavClick = (url, callTransition) => {
|
||||||
|
const {
|
||||||
|
containerWidth,
|
||||||
|
translate
|
||||||
|
} = this.state;
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
stage: 'navigating',
|
||||||
|
translate: Math.sign(translate) * containerWidth,
|
||||||
|
url
|
||||||
|
}, () => {
|
||||||
|
if (callTransition) {
|
||||||
|
this.onTransitionEnd();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onTransitionEnd = (e) => {
|
||||||
|
const {
|
||||||
|
stage,
|
||||||
|
url
|
||||||
|
} = this.state;
|
||||||
|
|
||||||
|
if (stage === 'navigating') {
|
||||||
|
this.setState({
|
||||||
|
stage: 'navigated',
|
||||||
|
translate: 0,
|
||||||
|
url: null
|
||||||
|
}, () => {
|
||||||
|
this.props.onGoTo(url);
|
||||||
|
this.setState({ stage: null });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onNext = () => {
|
||||||
|
this.onNavClick(this.props.nextLink);
|
||||||
|
}
|
||||||
|
|
||||||
|
onPrev = () => {
|
||||||
|
this.onNavClick(this.props.prevLink);
|
||||||
|
}
|
||||||
|
|
||||||
|
onContainerMeasure = ({ width }) => {
|
||||||
|
this.setState({ containerWidth: width });
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Render
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const {
|
||||||
|
transitionDuration,
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
prevComponent,
|
||||||
|
currentComponent,
|
||||||
|
nextComponent
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
|
const {
|
||||||
|
containerWidth,
|
||||||
|
translate,
|
||||||
|
touching,
|
||||||
|
stage
|
||||||
|
} = this.state;
|
||||||
|
|
||||||
|
const useTransition = !touching && stage !== 'navigated' && stage !== 'init';
|
||||||
|
|
||||||
|
const style = {
|
||||||
|
'--translate': `${translate - containerWidth}px`,
|
||||||
|
'--transition': useTransition ? `transform ${transitionDuration}ms ease-out` : undefined
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log(`stage: ${stage} translate: ${translate} width: ${containerWidth}`);
|
||||||
|
console.log(style);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Measure
|
||||||
|
className={className}
|
||||||
|
onMeasure={this.onContainerMeasure}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
|
||||||
|
<div
|
||||||
|
className={styles.content}
|
||||||
|
style={style}
|
||||||
|
onMouseDown={this.onMouseDown}
|
||||||
|
onTouchStart={this.onMouseDown}
|
||||||
|
onTransitionEnd={this.onTransitionEnd}
|
||||||
|
>
|
||||||
|
{prevComponent(containerWidth)}
|
||||||
|
{currentComponent(containerWidth)}
|
||||||
|
{nextComponent(containerWidth)}
|
||||||
|
</div>
|
||||||
|
</Measure>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SwipeHeader.propTypes = {
|
||||||
|
transitionDuration: PropTypes.number.isRequired,
|
||||||
|
navWidth: PropTypes.number.isRequired,
|
||||||
|
nextLink: PropTypes.string,
|
||||||
|
prevLink: PropTypes.string,
|
||||||
|
nextComponent: PropTypes.func.isRequired,
|
||||||
|
currentComponent: PropTypes.func.isRequired,
|
||||||
|
prevComponent: PropTypes.func.isRequired,
|
||||||
|
isSmallScreen: PropTypes.bool.isRequired,
|
||||||
|
className: PropTypes.string,
|
||||||
|
onGoTo: PropTypes.func.isRequired,
|
||||||
|
children: PropTypes.node.isRequired
|
||||||
|
};
|
||||||
|
|
||||||
|
SwipeHeader.defaultProps = {
|
||||||
|
transitionDuration: 250,
|
||||||
|
navWidth: 75
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SwipeHeader;
|
@ -0,0 +1,46 @@
|
|||||||
|
import { push } from 'connected-react-router';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import React, { Component } from 'react';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import { createSelector } from 'reselect';
|
||||||
|
import createDimensionsSelector from 'Store/Selectors/createDimensionsSelector';
|
||||||
|
import SwipeHeader from './SwipeHeader';
|
||||||
|
|
||||||
|
function createMapStateToProps() {
|
||||||
|
return createSelector(
|
||||||
|
createDimensionsSelector(),
|
||||||
|
(dimensions) => {
|
||||||
|
return {
|
||||||
|
isSmallScreen: dimensions.isSmallScreen
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function createMapDispatchToProps(dispatch, props) {
|
||||||
|
return {
|
||||||
|
onGoTo(url) {
|
||||||
|
dispatch(push(`${window.Readarr.urlBase}${url}`));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
class SwipeHeaderConnector extends Component {
|
||||||
|
|
||||||
|
//
|
||||||
|
// Render
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<SwipeHeader
|
||||||
|
{...this.props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SwipeHeaderConnector.propTypes = {
|
||||||
|
onGoTo: PropTypes.func.isRequired
|
||||||
|
};
|
||||||
|
|
||||||
|
export default connect(createMapStateToProps, createMapDispatchToProps)(SwipeHeaderConnector);
|
Loading…
Reference in new issue