You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
279 lines
7.3 KiB
279 lines
7.3 KiB
import PropTypes from 'prop-types';
|
|
import React, { Component } from 'react';
|
|
import BookSearchCellConnector from 'Book/BookSearchCellConnector';
|
|
import BookTitleLink from 'Book/BookTitleLink';
|
|
import IndexerFlags from 'Book/IndexerFlags';
|
|
import Icon from 'Components/Icon';
|
|
import MonitorToggleButton from 'Components/MonitorToggleButton';
|
|
import StarRating from 'Components/StarRating';
|
|
import RelativeDateCellConnector from 'Components/Table/Cells/RelativeDateCellConnector';
|
|
import TableRowCell from 'Components/Table/Cells/TableRowCell';
|
|
import TableSelectCell from 'Components/Table/Cells/TableSelectCell';
|
|
import TableRow from 'Components/Table/TableRow';
|
|
import Popover from 'Components/Tooltip/Popover';
|
|
import { icons, kinds, tooltipPositions } from 'Helpers/Props';
|
|
import translate from 'Utilities/String/translate';
|
|
import BookStatus from './BookStatus';
|
|
import styles from './BookRow.css';
|
|
|
|
class BookRow extends Component {
|
|
|
|
//
|
|
// Lifecycle
|
|
|
|
constructor(props, context) {
|
|
super(props, context);
|
|
|
|
this.state = {
|
|
isDetailsModalOpen: false,
|
|
isEditBookModalOpen: false
|
|
};
|
|
}
|
|
|
|
//
|
|
// Listeners
|
|
|
|
onManualSearchPress = () => {
|
|
this.setState({ isDetailsModalOpen: true });
|
|
};
|
|
|
|
onDetailsModalClose = () => {
|
|
this.setState({ isDetailsModalOpen: false });
|
|
};
|
|
|
|
onEditBookPress = () => {
|
|
this.setState({ isEditBookModalOpen: true });
|
|
};
|
|
|
|
onEditBookModalClose = () => {
|
|
this.setState({ isEditBookModalOpen: false });
|
|
};
|
|
|
|
onMonitorBookPress = (monitored, options) => {
|
|
this.props.onMonitorBookPress(this.props.id, monitored, options);
|
|
};
|
|
|
|
//
|
|
// Render
|
|
|
|
render() {
|
|
const {
|
|
id,
|
|
authorId,
|
|
monitored,
|
|
releaseDate,
|
|
title,
|
|
seriesTitle,
|
|
authorName,
|
|
position,
|
|
pageCount,
|
|
ratings,
|
|
isSaving,
|
|
authorMonitored,
|
|
titleSlug,
|
|
bookFiles,
|
|
indexerFlags,
|
|
isEditorActive,
|
|
isSelected,
|
|
onSelectedChange,
|
|
columns
|
|
} = this.props;
|
|
|
|
const bookFile = bookFiles[0];
|
|
const isAvailable = Date.parse(releaseDate) < new Date();
|
|
|
|
return (
|
|
<TableRow>
|
|
{
|
|
columns.map((column) => {
|
|
const {
|
|
name,
|
|
isVisible
|
|
} = column;
|
|
|
|
if (!isVisible) {
|
|
return null;
|
|
}
|
|
|
|
if (isEditorActive && name === 'select') {
|
|
return (
|
|
<TableSelectCell
|
|
key={name}
|
|
id={id}
|
|
isSelected={isSelected}
|
|
isDisabled={false}
|
|
onSelectedChange={onSelectedChange}
|
|
/>
|
|
);
|
|
}
|
|
|
|
if (name === 'monitored') {
|
|
return (
|
|
<TableRowCell
|
|
key={name}
|
|
className={styles.monitored}
|
|
>
|
|
<MonitorToggleButton
|
|
monitored={monitored}
|
|
isDisabled={!authorMonitored}
|
|
isSaving={isSaving}
|
|
onPress={this.onMonitorBookPress}
|
|
/>
|
|
</TableRowCell>
|
|
);
|
|
}
|
|
|
|
if (name === 'title') {
|
|
return (
|
|
<TableRowCell
|
|
key={name}
|
|
className={styles.title}
|
|
>
|
|
<BookTitleLink
|
|
titleSlug={titleSlug}
|
|
title={title}
|
|
/>
|
|
</TableRowCell>
|
|
);
|
|
}
|
|
|
|
if (name === 'series') {
|
|
return (
|
|
<TableRowCell
|
|
key={name}
|
|
className={styles.title}
|
|
>
|
|
{seriesTitle || ''}
|
|
</TableRowCell>
|
|
);
|
|
}
|
|
|
|
if (name === 'position') {
|
|
return (
|
|
<TableRowCell
|
|
key={name}
|
|
className={styles.position}
|
|
>
|
|
{position || ''}
|
|
</TableRowCell>
|
|
);
|
|
}
|
|
|
|
if (name === 'rating') {
|
|
return (
|
|
<TableRowCell
|
|
key={name}
|
|
className={styles.rating}
|
|
>
|
|
{
|
|
<StarRating
|
|
rating={ratings.value}
|
|
votes={ratings.votes}
|
|
/>
|
|
}
|
|
</TableRowCell>
|
|
);
|
|
}
|
|
|
|
if (name === 'releaseDate') {
|
|
return (
|
|
<RelativeDateCellConnector
|
|
className={styles.releaseDate}
|
|
key={name}
|
|
date={releaseDate}
|
|
/>
|
|
);
|
|
}
|
|
|
|
if (name === 'pageCount') {
|
|
return (
|
|
<TableRowCell
|
|
key={name}
|
|
className={styles.pageCount}
|
|
>
|
|
{pageCount || ''}
|
|
</TableRowCell>
|
|
);
|
|
}
|
|
|
|
if (name === 'indexerFlags') {
|
|
return (
|
|
<TableRowCell
|
|
key={name}
|
|
className={styles.indexerFlags}
|
|
>
|
|
{indexerFlags ? (
|
|
<Popover
|
|
anchor={<Icon name={icons.FLAG} kind={kinds.PRIMARY} />}
|
|
title={translate('IndexerFlags')}
|
|
body={<IndexerFlags indexerFlags={indexerFlags} />}
|
|
position={tooltipPositions.LEFT}
|
|
/>
|
|
) : null}
|
|
</TableRowCell>
|
|
);
|
|
}
|
|
|
|
if (name === 'status') {
|
|
return (
|
|
<TableRowCell
|
|
key={name}
|
|
className={styles.status}
|
|
>
|
|
<BookStatus
|
|
isAvailable={isAvailable}
|
|
monitored={monitored}
|
|
bookFile={bookFile}
|
|
/>
|
|
</TableRowCell>
|
|
);
|
|
}
|
|
|
|
if (name === 'actions') {
|
|
return (
|
|
<BookSearchCellConnector
|
|
key={name}
|
|
bookId={id}
|
|
authorId={authorId}
|
|
bookTitle={title}
|
|
authorName={authorName}
|
|
/>
|
|
);
|
|
}
|
|
return null;
|
|
})
|
|
}
|
|
</TableRow>
|
|
);
|
|
}
|
|
}
|
|
|
|
BookRow.propTypes = {
|
|
id: PropTypes.number.isRequired,
|
|
authorId: PropTypes.number.isRequired,
|
|
monitored: PropTypes.bool.isRequired,
|
|
releaseDate: PropTypes.string,
|
|
title: PropTypes.string.isRequired,
|
|
seriesTitle: PropTypes.string.isRequired,
|
|
authorName: PropTypes.string.isRequired,
|
|
position: PropTypes.string,
|
|
pageCount: PropTypes.number,
|
|
ratings: PropTypes.object.isRequired,
|
|
indexerFlags: PropTypes.number.isRequired,
|
|
titleSlug: PropTypes.string.isRequired,
|
|
isSaving: PropTypes.bool,
|
|
authorMonitored: PropTypes.bool.isRequired,
|
|
bookFiles: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
isEditorActive: PropTypes.bool.isRequired,
|
|
isSelected: PropTypes.bool,
|
|
onSelectedChange: PropTypes.func.isRequired,
|
|
columns: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
onMonitorBookPress: PropTypes.func.isRequired
|
|
};
|
|
|
|
BookRow.defaultProps = {
|
|
indexerFlags: 0
|
|
};
|
|
|
|
export default BookRow;
|