(cherry picked from commit bdcfef80d627e777d7932c54cda04cbe7c656ffc) Load albums for album details on mouse hoverpull/4254/head
parent
de6c9589d0
commit
72267d3cb4
@ -0,0 +1,8 @@
|
||||
import Album from 'Album/Album';
|
||||
import AppSectionState, {
|
||||
AppSectionDeleteState,
|
||||
} from 'App/State/AppSectionState';
|
||||
|
||||
interface AlbumAppState extends AppSectionState<Album>, AppSectionDeleteState {}
|
||||
|
||||
export default AlbumAppState;
|
@ -0,0 +1,10 @@
|
||||
.albums {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.truncated {
|
||||
align-self: center;
|
||||
flex: 0 0 100%;
|
||||
padding: 4px 6px;
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
// This file is automatically generated.
|
||||
// Please do not change this file!
|
||||
interface CssExports {
|
||||
'albums': string;
|
||||
'truncated': string;
|
||||
}
|
||||
export const cssExports: CssExports;
|
||||
export default cssExports;
|
@ -0,0 +1,88 @@
|
||||
import _ from 'lodash';
|
||||
import React, { useEffect, useMemo } from 'react';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
import Alert from 'Components/Alert';
|
||||
import LoadingIndicator from 'Components/Loading/LoadingIndicator';
|
||||
import { kinds } from 'Helpers/Props';
|
||||
import { clearAlbums, fetchAlbums } from 'Store/Actions/albumActions';
|
||||
import createArtistAlbumsSelector from 'Store/Selectors/createArtistAlbumsSelector';
|
||||
import translate from 'Utilities/String/translate';
|
||||
import AlbumStudioAlbum from './AlbumStudioAlbum';
|
||||
import styles from './AlbumDetails.css';
|
||||
|
||||
interface AlbumDetailsProps {
|
||||
artistId: number;
|
||||
}
|
||||
|
||||
function AlbumDetails(props: AlbumDetailsProps) {
|
||||
const { artistId } = props;
|
||||
|
||||
const {
|
||||
isFetching,
|
||||
isPopulated,
|
||||
error,
|
||||
items: albums,
|
||||
} = useSelector(createArtistAlbumsSelector(artistId));
|
||||
|
||||
const dispatch = useDispatch();
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(fetchAlbums({ artistId }));
|
||||
|
||||
return () => {
|
||||
dispatch(clearAlbums());
|
||||
};
|
||||
}, [dispatch, artistId]);
|
||||
|
||||
const latestAlbums = useMemo(() => {
|
||||
const sortedAlbums = _.orderBy(albums, 'releaseDate', 'desc');
|
||||
|
||||
return sortedAlbums.slice(0, 20);
|
||||
}, [albums]);
|
||||
|
||||
return (
|
||||
<div className={styles.albums}>
|
||||
{isFetching ? <LoadingIndicator /> : null}
|
||||
|
||||
{!isFetching && error ? (
|
||||
<Alert kind={kinds.DANGER}>{translate('AlbumsLoadError')}</Alert>
|
||||
) : null}
|
||||
|
||||
{isPopulated && !error
|
||||
? latestAlbums.map((album) => {
|
||||
const {
|
||||
id: albumId,
|
||||
title,
|
||||
disambiguation,
|
||||
albumType,
|
||||
monitored,
|
||||
statistics,
|
||||
isSaving,
|
||||
} = album;
|
||||
|
||||
return (
|
||||
<AlbumStudioAlbum
|
||||
key={albumId}
|
||||
artistId={artistId}
|
||||
albumId={albumId}
|
||||
title={title}
|
||||
disambiguation={disambiguation}
|
||||
albumType={albumType}
|
||||
monitored={monitored}
|
||||
statistics={statistics}
|
||||
isSaving={isSaving}
|
||||
/>
|
||||
);
|
||||
})
|
||||
: null}
|
||||
|
||||
{latestAlbums.length < albums.length ? (
|
||||
<div className={styles.truncated}>
|
||||
{translate('AlbumStudioTruncated')}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default AlbumDetails;
|
@ -0,0 +1,39 @@
|
||||
.album {
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
overflow: hidden;
|
||||
margin: 2px 4px;
|
||||
border: 1px solid var(--borderColor);
|
||||
border-radius: 4px;
|
||||
background-color: var(--albumBackgroundColor);
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.info {
|
||||
padding: 0 4px;
|
||||
}
|
||||
|
||||
.albumType {
|
||||
padding: 0 4px;
|
||||
border-width: 0 1px;
|
||||
border-style: solid;
|
||||
border-color: var(--borderColor);
|
||||
background-color: var(--albumBackgroundColor);
|
||||
color: var(--defaultColor);
|
||||
}
|
||||
|
||||
.tracks {
|
||||
padding: 0 4px;
|
||||
background-color: var(--trackBackgroundColor);
|
||||
color: var(--defaultColor);
|
||||
}
|
||||
|
||||
.allTracks {
|
||||
background-color: color(#27c24c saturation(-25%));
|
||||
color: var(--white);
|
||||
}
|
||||
|
||||
.missingWanted {
|
||||
background-color: color(#f05050 saturation(-20%));
|
||||
color: var(--white);
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
// This file is automatically generated.
|
||||
// Please do not change this file!
|
||||
interface CssExports {
|
||||
'album': string;
|
||||
'albumType': string;
|
||||
'allTracks': string;
|
||||
'info': string;
|
||||
'missingWanted': string;
|
||||
'tracks': string;
|
||||
}
|
||||
export const cssExports: CssExports;
|
||||
export default cssExports;
|
@ -0,0 +1,83 @@
|
||||
import classNames from 'classnames';
|
||||
import React, { useCallback } from 'react';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { Statistics } from 'Album/Album';
|
||||
import MonitorToggleButton from 'Components/MonitorToggleButton';
|
||||
import { toggleAlbumsMonitored } from 'Store/Actions/albumActions';
|
||||
import translate from 'Utilities/String/translate';
|
||||
import styles from './AlbumStudioAlbum.css';
|
||||
|
||||
interface AlbumStudioAlbumProps {
|
||||
artistId: number;
|
||||
albumId: number;
|
||||
title: string;
|
||||
disambiguation: string;
|
||||
albumType: string;
|
||||
monitored: boolean;
|
||||
statistics: Statistics;
|
||||
isSaving: boolean;
|
||||
}
|
||||
|
||||
function AlbumStudioAlbum(props: AlbumStudioAlbumProps) {
|
||||
const {
|
||||
albumId,
|
||||
title,
|
||||
disambiguation,
|
||||
albumType,
|
||||
monitored,
|
||||
statistics = {
|
||||
trackFileCount: 0,
|
||||
totalTrackCount: 0,
|
||||
percentOfTracks: 0,
|
||||
},
|
||||
isSaving = false,
|
||||
} = props;
|
||||
|
||||
const { trackFileCount, totalTrackCount, percentOfTracks } = statistics;
|
||||
|
||||
const dispatch = useDispatch();
|
||||
const onAlbumMonitoredPress = useCallback(() => {
|
||||
dispatch(
|
||||
toggleAlbumsMonitored({
|
||||
albumIds: [albumId],
|
||||
monitored: !monitored,
|
||||
})
|
||||
);
|
||||
}, [albumId, monitored, dispatch]);
|
||||
|
||||
return (
|
||||
<div className={styles.album}>
|
||||
<div className={styles.info}>
|
||||
<MonitorToggleButton
|
||||
monitored={monitored}
|
||||
isSaving={isSaving}
|
||||
onPress={onAlbumMonitoredPress}
|
||||
/>
|
||||
|
||||
<span>
|
||||
{disambiguation ? `${title} (${disambiguation})` : `${title}`}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className={styles.albumType}>
|
||||
<span>{albumType}</span>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className={classNames(
|
||||
styles.tracks,
|
||||
percentOfTracks < 100 && monitored && styles.missingWanted,
|
||||
percentOfTracks === 100 && styles.allTracks
|
||||
)}
|
||||
title={translate('AlbumStudioTracksDownloaded', {
|
||||
trackFileCount,
|
||||
totalTrackCount,
|
||||
})}
|
||||
>
|
||||
{totalTrackCount === 0 ? '0/0' : `${trackFileCount}/${totalTrackCount}`}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default AlbumStudioAlbum;
|
@ -0,0 +1,26 @@
|
||||
import React from 'react';
|
||||
import Modal from 'Components/Modal/Modal';
|
||||
import ChangeMonitoringModalContent from './ChangeMonitoringModalContent';
|
||||
|
||||
interface ChangeMonitoringModalProps {
|
||||
isOpen: boolean;
|
||||
artistIds: number[];
|
||||
onSavePress(monitor: string): void;
|
||||
onModalClose(): void;
|
||||
}
|
||||
|
||||
function ChangeMonitoringModal(props: ChangeMonitoringModalProps) {
|
||||
const { isOpen, artistIds, onSavePress, onModalClose } = props;
|
||||
|
||||
return (
|
||||
<Modal isOpen={isOpen} onModalClose={onModalClose}>
|
||||
<ChangeMonitoringModalContent
|
||||
artistIds={artistIds}
|
||||
onSavePress={onSavePress}
|
||||
onModalClose={onModalClose}
|
||||
/>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
export default ChangeMonitoringModal;
|
@ -0,0 +1,26 @@
|
||||
.labelIcon {
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
.message {
|
||||
composes: alert from '~Components/Alert.css';
|
||||
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.modalFooter {
|
||||
composes: modalFooter from '~Components/Modal/ModalFooter.css';
|
||||
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.selected {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
@media only screen and (max-width: $breakpointExtraSmall) {
|
||||
.modalFooter {
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
// This file is automatically generated.
|
||||
// Please do not change this file!
|
||||
interface CssExports {
|
||||
'labelIcon': string;
|
||||
'message': string;
|
||||
'modalFooter': string;
|
||||
'selected': string;
|
||||
}
|
||||
export const cssExports: CssExports;
|
||||
export default cssExports;
|
@ -0,0 +1,96 @@
|
||||
import React, { useCallback, useState } from 'react';
|
||||
import ArtistMonitoringOptionsPopoverContent from 'AddArtist/ArtistMonitoringOptionsPopoverContent';
|
||||
import Alert from 'Components/Alert';
|
||||
import Form from 'Components/Form/Form';
|
||||
import FormGroup from 'Components/Form/FormGroup';
|
||||
import FormInputGroup from 'Components/Form/FormInputGroup';
|
||||
import FormLabel from 'Components/Form/FormLabel';
|
||||
import Icon from 'Components/Icon';
|
||||
import Button from 'Components/Link/Button';
|
||||
import ModalBody from 'Components/Modal/ModalBody';
|
||||
import ModalContent from 'Components/Modal/ModalContent';
|
||||
import ModalFooter from 'Components/Modal/ModalFooter';
|
||||
import ModalHeader from 'Components/Modal/ModalHeader';
|
||||
import Popover from 'Components/Tooltip/Popover';
|
||||
import { icons, inputTypes, kinds, tooltipPositions } from 'Helpers/Props';
|
||||
import translate from 'Utilities/String/translate';
|
||||
import styles from './ChangeMonitoringModalContent.css';
|
||||
|
||||
const NO_CHANGE = 'noChange';
|
||||
|
||||
interface ChangeMonitoringModalContentProps {
|
||||
artistIds: number[];
|
||||
saveError?: object;
|
||||
onSavePress(monitor: string): void;
|
||||
onModalClose(): void;
|
||||
}
|
||||
|
||||
function ChangeMonitoringModalContent(
|
||||
props: ChangeMonitoringModalContentProps
|
||||
) {
|
||||
const { artistIds, onSavePress, onModalClose, ...otherProps } = props;
|
||||
|
||||
const [monitor, setMonitor] = useState(NO_CHANGE);
|
||||
|
||||
const onInputChange = useCallback(
|
||||
({ value }) => {
|
||||
setMonitor(value);
|
||||
},
|
||||
[setMonitor]
|
||||
);
|
||||
|
||||
const onSavePressWrapper = useCallback(() => {
|
||||
onSavePress(monitor);
|
||||
}, [monitor, onSavePress]);
|
||||
|
||||
const selectedCount = artistIds.length;
|
||||
|
||||
return (
|
||||
<ModalContent onModalClose={onModalClose}>
|
||||
<ModalHeader>{translate('MonitorArtists')}</ModalHeader>
|
||||
|
||||
<ModalBody>
|
||||
<Alert kind={kinds.INFO} className={styles.message}>
|
||||
{translate('MonitorAlbumExistingOnlyWarning')}
|
||||
</Alert>
|
||||
|
||||
<Form {...otherProps}>
|
||||
<FormGroup>
|
||||
<FormLabel>
|
||||
{translate('MonitorExistingAlbums')}
|
||||
|
||||
<Popover
|
||||
anchor={<Icon className={styles.labelIcon} name={icons.INFO} />}
|
||||
title={translate('MonitoringOptions')}
|
||||
body={<ArtistMonitoringOptionsPopoverContent />}
|
||||
position={tooltipPositions.RIGHT}
|
||||
/>
|
||||
</FormLabel>
|
||||
|
||||
<FormInputGroup
|
||||
type={inputTypes.MONITOR_ALBUMS_SELECT}
|
||||
name="monitor"
|
||||
value={monitor}
|
||||
includeNoChange={true}
|
||||
onChange={onInputChange}
|
||||
/>
|
||||
</FormGroup>
|
||||
</Form>
|
||||
</ModalBody>
|
||||
|
||||
<ModalFooter className={styles.modalFooter}>
|
||||
<div className={styles.selected}>
|
||||
{translate('CountArtistsSelected', { count: selectedCount })}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Button onPress={onModalClose}>{translate('Cancel')}</Button>
|
||||
|
||||
<Button onPress={onSavePressWrapper}>{translate('Save')}</Button>
|
||||
</div>
|
||||
</ModalFooter>
|
||||
</ModalContent>
|
||||
);
|
||||
}
|
||||
|
||||
export default ChangeMonitoringModalContent;
|
@ -0,0 +1,4 @@
|
||||
.albumCount {
|
||||
width: 100%;
|
||||
cursor: default;
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
// This file is automatically generated.
|
||||
// Please do not change this file!
|
||||
interface CssExports {
|
||||
'albumCount': string;
|
||||
}
|
||||
export const cssExports: CssExports;
|
||||
export default cssExports;
|
@ -0,0 +1,38 @@
|
||||
import React from 'react';
|
||||
import AlbumDetails from 'Artist/Index/Select/AlbumStudio/AlbumDetails';
|
||||
import VirtualTableRowCell from 'Components/Table/Cells/VirtualTableRowCell';
|
||||
import Popover from 'Components/Tooltip/Popover';
|
||||
import TooltipPosition from 'Helpers/Props/TooltipPosition';
|
||||
import translate from 'Utilities/String/translate';
|
||||
import styles from './AlbumsCell.css';
|
||||
|
||||
interface SeriesStatusCellProps {
|
||||
className: string;
|
||||
artistId: number;
|
||||
albumCount: number;
|
||||
isSelectMode: boolean;
|
||||
}
|
||||
|
||||
function AlbumsCell(props: SeriesStatusCellProps) {
|
||||
const { className, artistId, albumCount, isSelectMode, ...otherProps } =
|
||||
props;
|
||||
|
||||
return (
|
||||
<VirtualTableRowCell className={className} {...otherProps}>
|
||||
{isSelectMode && albumCount > 0 ? (
|
||||
<Popover
|
||||
className={styles.albumCount}
|
||||
anchor={albumCount}
|
||||
title={translate('AlbumDetails')}
|
||||
body={<AlbumDetails artistId={artistId} />}
|
||||
position={TooltipPosition.Left}
|
||||
canFlip={true}
|
||||
/>
|
||||
) : (
|
||||
albumCount
|
||||
)}
|
||||
</VirtualTableRowCell>
|
||||
);
|
||||
}
|
||||
|
||||
export default AlbumsCell;
|
@ -0,0 +1,27 @@
|
||||
import { createSelector } from 'reselect';
|
||||
import AppState from 'App/State/AppState';
|
||||
import Artist from 'Artist/Artist';
|
||||
import { createArtistSelectorForHook } from './createArtistSelector';
|
||||
|
||||
function createArtistAlbumsSelector(artistId: number) {
|
||||
return createSelector(
|
||||
(state: AppState) => state.albums,
|
||||
createArtistSelectorForHook(artistId),
|
||||
(albums, artist = {} as Artist) => {
|
||||
const { isFetching, isPopulated, error, items } = albums;
|
||||
|
||||
const filteredAlbums = items.filter(
|
||||
(album) => album.artist.artistMetadataId === artist.artistMetadataId
|
||||
);
|
||||
|
||||
return {
|
||||
isFetching,
|
||||
isPopulated,
|
||||
error,
|
||||
items: filteredAlbums,
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export default createArtistAlbumsSelector;
|
Loading…
Reference in new issue