mirror of
https://github.com/Readarr/Readarr
synced 2025-12-23 16:55:12 +01:00
131 lines
3.2 KiB
JavaScript
131 lines
3.2 KiB
JavaScript
import PropTypes from 'prop-types';
|
|
import React, { Component } from 'react';
|
|
import AuthorIndexItemConnector from 'Author/Index/AuthorIndexItemConnector';
|
|
import VirtualTable from 'Components/Table/VirtualTable';
|
|
import VirtualTableRow from 'Components/Table/VirtualTableRow';
|
|
import { sortDirections } from 'Helpers/Props';
|
|
import getIndexOfFirstCharacter from 'Utilities/Array/getIndexOfFirstCharacter';
|
|
import AuthorIndexHeaderConnector from './AuthorIndexHeaderConnector';
|
|
import AuthorIndexRow from './AuthorIndexRow';
|
|
import styles from './AuthorIndexTable.css';
|
|
|
|
class AuthorIndexTable extends Component {
|
|
|
|
//
|
|
// Lifecycle
|
|
|
|
constructor(props, context) {
|
|
super(props, context);
|
|
|
|
this.state = {
|
|
scrollIndex: null
|
|
};
|
|
}
|
|
|
|
componentDidUpdate(prevProps) {
|
|
const {
|
|
items,
|
|
jumpToCharacter
|
|
} = this.props;
|
|
|
|
if (jumpToCharacter != null && jumpToCharacter !== prevProps.jumpToCharacter) {
|
|
|
|
const scrollIndex = getIndexOfFirstCharacter(items, jumpToCharacter);
|
|
|
|
if (scrollIndex != null) {
|
|
this.setState({ scrollIndex });
|
|
}
|
|
} else if (jumpToCharacter == null && prevProps.jumpToCharacter != null) {
|
|
this.setState({ scrollIndex: null });
|
|
}
|
|
}
|
|
|
|
//
|
|
// Control
|
|
|
|
rowRenderer = ({ key, rowIndex, style }) => {
|
|
const {
|
|
items,
|
|
columns,
|
|
showBanners
|
|
} = this.props;
|
|
|
|
const author = items[rowIndex];
|
|
|
|
return (
|
|
<VirtualTableRow
|
|
key={key}
|
|
style={style}
|
|
>
|
|
<AuthorIndexItemConnector
|
|
key={author.id}
|
|
component={AuthorIndexRow}
|
|
style={style}
|
|
columns={columns}
|
|
authorId={author.id}
|
|
qualityProfileId={author.qualityProfileId}
|
|
metadataProfileId={author.metadataProfileId}
|
|
showBanners={showBanners}
|
|
/>
|
|
</VirtualTableRow>
|
|
);
|
|
}
|
|
|
|
//
|
|
// Render
|
|
|
|
render() {
|
|
const {
|
|
items,
|
|
columns,
|
|
sortKey,
|
|
sortDirection,
|
|
showBanners,
|
|
isSmallScreen,
|
|
onSortPress,
|
|
scroller,
|
|
scrollTop
|
|
} = this.props;
|
|
|
|
return (
|
|
<VirtualTable
|
|
className={styles.tableContainer}
|
|
items={items}
|
|
scrollIndex={this.state.scrollIndex}
|
|
scrollTop={scrollTop}
|
|
isSmallScreen={isSmallScreen}
|
|
scroller={scroller}
|
|
rowHeight={showBanners ? 70 : 38}
|
|
overscanRowCount={2}
|
|
rowRenderer={this.rowRenderer}
|
|
header={
|
|
<AuthorIndexHeaderConnector
|
|
showBanners={showBanners}
|
|
columns={columns}
|
|
sortKey={sortKey}
|
|
sortDirection={sortDirection}
|
|
onSortPress={onSortPress}
|
|
/>
|
|
}
|
|
columns={columns}
|
|
sortKey={sortKey}
|
|
sortDirection={sortDirection}
|
|
/>
|
|
);
|
|
}
|
|
}
|
|
|
|
AuthorIndexTable.propTypes = {
|
|
items: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
columns: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
sortKey: PropTypes.string,
|
|
sortDirection: PropTypes.oneOf(sortDirections.all),
|
|
showBanners: PropTypes.bool.isRequired,
|
|
jumpToCharacter: PropTypes.string,
|
|
scrollTop: PropTypes.number,
|
|
scroller: PropTypes.instanceOf(Element).isRequired,
|
|
isSmallScreen: PropTypes.bool.isRequired,
|
|
onSortPress: PropTypes.func.isRequired
|
|
};
|
|
|
|
export default AuthorIndexTable;
|