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.
319 lines
8.5 KiB
319 lines
8.5 KiB
7 years ago
|
import _ from 'lodash';
|
||
|
import PropTypes from 'prop-types';
|
||
|
import React, { Component } from 'react';
|
||
|
import isAfter from 'Utilities/Date/isAfter';
|
||
|
import isBefore from 'Utilities/Date/isBefore';
|
||
|
import getToggledRange from 'Utilities/Table/getToggledRange';
|
||
|
import { align, icons, kinds, sizes } from 'Helpers/Props';
|
||
|
import Icon from 'Components/Icon';
|
||
|
import IconButton from 'Components/Link/IconButton';
|
||
|
import Link from 'Components/Link/Link';
|
||
|
import SpinnerIcon from 'Components/SpinnerIcon';
|
||
|
import SpinnerIconButton from 'Components/Link/SpinnerIconButton';
|
||
|
import Menu from 'Components/Menu/Menu';
|
||
|
import MenuButton from 'Components/Menu/MenuButton';
|
||
|
import MenuContent from 'Components/Menu/MenuContent';
|
||
|
import MenuItem from 'Components/Menu/MenuItem';
|
||
|
import Table from 'Components/Table/Table';
|
||
|
import TableBody from 'Components/Table/TableBody';
|
||
|
import EpisodeFileEditorModal from 'EpisodeFile/Editor/EpisodeFileEditorModal';
|
||
|
import OrganizePreviewModalConnector from 'Organize/OrganizePreviewModalConnector';
|
||
7 years ago
|
import AlbumRowConnector from './AlbumRowConnector';
|
||
|
import styles from './ArtistDetailsSeason.css';
|
||
7 years ago
|
|
||
7 years ago
|
class ArtistDetailsSeason extends Component {
|
||
7 years ago
|
|
||
|
//
|
||
|
// Lifecycle
|
||
|
|
||
|
constructor(props, context) {
|
||
|
super(props, context);
|
||
|
|
||
|
this.state = {
|
||
|
isOrganizeModalOpen: false,
|
||
|
isManageEpisodesOpen: false,
|
||
|
lastToggledEpisode: null
|
||
|
};
|
||
|
}
|
||
|
|
||
|
componentDidMount() {
|
||
|
this._expandByDefault();
|
||
|
}
|
||
|
|
||
|
componentDidUpdate(prevProps) {
|
||
|
if (prevProps.artistId !== this.props.artistId) {
|
||
|
this._expandByDefault();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//
|
||
|
// Control
|
||
|
|
||
|
_expandByDefault() {
|
||
|
const {
|
||
7 years ago
|
name,
|
||
7 years ago
|
onExpandPress,
|
||
|
items
|
||
|
} = this.props;
|
||
|
|
||
|
const expand = _.some(items, (item) => {
|
||
|
return isAfter(item.airDateUtc) ||
|
||
|
isAfter(item.airDateUtc, { days: -30 });
|
||
|
});
|
||
|
|
||
7 years ago
|
onExpandPress(name, expand && name > 0);
|
||
7 years ago
|
}
|
||
|
|
||
|
//
|
||
|
// Listeners
|
||
|
|
||
|
onOrganizePress = () => {
|
||
|
this.setState({ isOrganizeModalOpen: true });
|
||
|
}
|
||
|
|
||
|
onOrganizeModalClose = () => {
|
||
|
this.setState({ isOrganizeModalOpen: false });
|
||
|
}
|
||
|
|
||
|
onManageEpisodesPress = () => {
|
||
|
this.setState({ isManageEpisodesOpen: true });
|
||
|
}
|
||
|
|
||
|
onManageEpisodesModalClose = () => {
|
||
|
this.setState({ isManageEpisodesOpen: false });
|
||
|
}
|
||
|
|
||
|
onExpandPress = () => {
|
||
|
const {
|
||
7 years ago
|
name,
|
||
7 years ago
|
isExpanded
|
||
|
} = this.props;
|
||
|
|
||
7 years ago
|
this.props.onExpandPress(name, !isExpanded);
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
onMonitorAlbumPress = (albumId, monitored, { shiftKey }) => {
|
||
7 years ago
|
const lastToggled = this.state.lastToggledEpisode;
|
||
7 years ago
|
const albumIds = [albumId];
|
||
7 years ago
|
|
||
|
if (shiftKey && lastToggled) {
|
||
7 years ago
|
const { lower, upper } = getToggledRange(this.props.items, albumId, lastToggled);
|
||
7 years ago
|
const items = this.props.items;
|
||
|
|
||
|
for (let i = lower; i < upper; i++) {
|
||
7 years ago
|
albumIds.push(items[i].id);
|
||
7 years ago
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
this.setState({ lastToggledEpisode: albumId });
|
||
7 years ago
|
|
||
7 years ago
|
this.props.onMonitorAlbumPress(_.uniq(albumIds), monitored);
|
||
7 years ago
|
}
|
||
|
|
||
|
//
|
||
|
// Render
|
||
|
|
||
|
render() {
|
||
|
const {
|
||
|
artistId,
|
||
7 years ago
|
label,
|
||
7 years ago
|
items,
|
||
|
columns,
|
||
|
isSaving,
|
||
|
isExpanded,
|
||
|
isSearching,
|
||
7 years ago
|
artistMonitored,
|
||
7 years ago
|
isSmallScreen,
|
||
|
onTableOptionChange,
|
||
|
onMonitorSeasonPress,
|
||
|
onSearchPress
|
||
|
} = this.props;
|
||
|
|
||
|
const {
|
||
|
isOrganizeModalOpen,
|
||
|
isManageEpisodesOpen
|
||
|
} = this.state;
|
||
|
|
||
|
return (
|
||
|
<div
|
||
7 years ago
|
className={styles.albumType}
|
||
7 years ago
|
>
|
||
|
<div className={styles.header}>
|
||
|
<div className={styles.left}>
|
||
|
{
|
||
7 years ago
|
<div>
|
||
|
<span className={styles.albumTypeLabel}>
|
||
|
{label}
|
||
|
</span>
|
||
|
|
||
|
<span className={styles.albumCount}>
|
||
|
({items.length} Releases)
|
||
7 years ago
|
</span>
|
||
7 years ago
|
</div>
|
||
7 years ago
|
}
|
||
|
|
||
|
</div>
|
||
|
|
||
|
<Link
|
||
|
className={styles.expandButton}
|
||
|
onPress={this.onExpandPress}
|
||
|
>
|
||
7 years ago
|
|
||
7 years ago
|
<Icon
|
||
|
className={styles.expandButtonIcon}
|
||
|
name={isExpanded ? icons.COLLAPSE : icons.EXPAND}
|
||
|
title={isExpanded ? 'Hide albums' : 'Show albums'}
|
||
|
size={24}
|
||
|
/>
|
||
|
|
||
7 years ago
|
{
|
||
|
!isSmallScreen &&
|
||
|
<span> </span>
|
||
|
}
|
||
|
</Link>
|
||
|
|
||
|
{
|
||
|
isSmallScreen ?
|
||
|
<Menu
|
||
|
className={styles.actionsMenu}
|
||
|
alignMenu={align.RIGHT}
|
||
|
enforceMaxHeight={false}
|
||
|
>
|
||
|
<MenuButton>
|
||
|
<Icon
|
||
|
name={icons.ACTIONS}
|
||
|
size={22}
|
||
|
/>
|
||
|
</MenuButton>
|
||
|
|
||
|
<MenuContent className={styles.actionsMenuContent}>
|
||
|
<MenuItem
|
||
|
isDisabled={isSearching}
|
||
|
onPress={onSearchPress}
|
||
|
>
|
||
|
<SpinnerIcon
|
||
|
className={styles.actionMenuIcon}
|
||
|
name={icons.SEARCH}
|
||
|
isSpinning={isSearching}
|
||
|
/>
|
||
|
|
||
|
Search
|
||
|
</MenuItem>
|
||
|
|
||
|
<MenuItem
|
||
|
onPress={this.onOrganizePress}
|
||
|
>
|
||
|
<Icon
|
||
|
className={styles.actionMenuIcon}
|
||
|
name={icons.ORGANIZE}
|
||
|
/>
|
||
|
|
||
|
Preview Rename
|
||
|
</MenuItem>
|
||
|
|
||
|
<MenuItem
|
||
|
onPress={this.onManageEpisodesPress}
|
||
|
>
|
||
|
<Icon
|
||
|
className={styles.actionMenuIcon}
|
||
|
name={icons.EPISODE_FILE}
|
||
|
/>
|
||
|
|
||
7 years ago
|
Manage Tracks
|
||
7 years ago
|
</MenuItem>
|
||
|
</MenuContent>
|
||
|
</Menu> :
|
||
|
|
||
|
<div className={styles.actions}>
|
||
|
<SpinnerIconButton
|
||
|
className={styles.actionButton}
|
||
|
name={icons.SEARCH}
|
||
7 years ago
|
title="Search for album"
|
||
7 years ago
|
size={24}
|
||
|
isSpinning={isSearching}
|
||
|
onPress={onSearchPress}
|
||
|
/>
|
||
|
|
||
|
</div>
|
||
|
}
|
||
|
|
||
|
</div>
|
||
|
|
||
7 years ago
|
<div>
|
||
|
{
|
||
|
isExpanded &&
|
||
|
<div className={styles.episodes}>
|
||
|
{
|
||
|
items.length ?
|
||
|
<Table
|
||
|
columns={columns}
|
||
|
onTableOptionChange={onTableOptionChange}
|
||
|
>
|
||
|
<TableBody>
|
||
|
{
|
||
|
items.map((item) => {
|
||
|
return (
|
||
|
<AlbumRowConnector
|
||
|
key={item.id}
|
||
|
columns={columns}
|
||
|
{...item}
|
||
|
onMonitorAlbumPress={this.onMonitorAlbumPress}
|
||
|
/>
|
||
|
);
|
||
|
})
|
||
|
}
|
||
|
</TableBody>
|
||
|
</Table> :
|
||
|
|
||
|
<div className={styles.noEpisodes}>
|
||
|
No albums in this group
|
||
|
</div>
|
||
|
}
|
||
|
<div className={styles.collapseButtonContainer}>
|
||
|
<IconButton
|
||
|
name={icons.COLLAPSE}
|
||
|
size={20}
|
||
|
title="Hide episodes"
|
||
|
onPress={this.onExpandPress}
|
||
|
/>
|
||
|
</div>
|
||
|
</div>
|
||
|
}
|
||
|
</div>
|
||
|
|
||
7 years ago
|
<OrganizePreviewModalConnector
|
||
|
isOpen={isOrganizeModalOpen}
|
||
|
artistId={artistId}
|
||
|
onModalClose={this.onOrganizeModalClose}
|
||
|
/>
|
||
|
|
||
|
<EpisodeFileEditorModal
|
||
|
isOpen={isManageEpisodesOpen}
|
||
|
artistId={artistId}
|
||
|
onModalClose={this.onManageEpisodesModalClose}
|
||
|
/>
|
||
|
</div>
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
ArtistDetailsSeason.propTypes = {
|
||
7 years ago
|
artistId: PropTypes.number.isRequired,
|
||
7 years ago
|
name: PropTypes.string.isRequired,
|
||
|
label: PropTypes.string.isRequired,
|
||
7 years ago
|
items: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||
|
columns: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||
|
isSaving: PropTypes.bool,
|
||
|
isExpanded: PropTypes.bool,
|
||
|
isSearching: PropTypes.bool.isRequired,
|
||
7 years ago
|
artistMonitored: PropTypes.bool.isRequired,
|
||
7 years ago
|
isSmallScreen: PropTypes.bool.isRequired,
|
||
|
onTableOptionChange: PropTypes.func.isRequired,
|
||
|
onMonitorSeasonPress: PropTypes.func.isRequired,
|
||
|
onExpandPress: PropTypes.func.isRequired,
|
||
7 years ago
|
onMonitorAlbumPress: PropTypes.func.isRequired,
|
||
7 years ago
|
onSearchPress: PropTypes.func.isRequired
|
||
|
};
|
||
|
|
||
7 years ago
|
export default ArtistDetailsSeason;
|