import { orderBy } from 'lodash'; import React, { useCallback, useMemo } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import Artist from 'Artist/Artist'; import { RETAG_ARTIST } from 'Commands/commandNames'; import Alert from 'Components/Alert'; 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 { icons, kinds } from 'Helpers/Props'; import { executeCommand } from 'Store/Actions/commandActions'; import createAllArtistSelector from 'Store/Selectors/createAllArtistSelector'; import translate from 'Utilities/String/translate'; import styles from './RetagArtistModalContent.css'; interface RetagArtistModalContentProps { artistIds: number[]; onModalClose: () => void; } function RetagArtistModalContent(props: RetagArtistModalContentProps) { const { artistIds, onModalClose } = props; const allArtists: Artist[] = useSelector(createAllArtistSelector()); const dispatch = useDispatch(); const artistNames = useMemo(() => { const artists = artistIds.reduce((acc: Artist[], id) => { const a = allArtists.find((a) => a.id === id); if (a) { acc.push(a); } return acc; }, []); const sorted = orderBy(artists, ['sortName']); return sorted.map((a) => a.artistName); }, [artistIds, allArtists]); const onRetagPress = useCallback(() => { dispatch( executeCommand({ name: RETAG_ARTIST, artistIds, }) ); onModalClose(); }, [artistIds, onModalClose, dispatch]); return ( {translate('RetagSelectedArtists')} Tip: To preview the tags that will be written, select "Cancel", then select any artist name and use the
Are you sure you want to retag all files in the {artistNames.length}{' '} selected artist?
); } export default RetagArtistModalContent;