import PropTypes from 'prop-types'; import React, { Component } from 'react'; import NoArtist from 'Artist/NoArtist'; import LoadingIndicator from 'Components/Loading/LoadingIndicator'; import Measure from 'Components/Measure'; import FilterMenu from 'Components/Menu/FilterMenu'; import PageContent from 'Components/Page/PageContent'; import PageContentBody from 'Components/Page/PageContentBody'; import PageToolbar from 'Components/Page/Toolbar/PageToolbar'; import PageToolbarButton from 'Components/Page/Toolbar/PageToolbarButton'; import PageToolbarSection from 'Components/Page/Toolbar/PageToolbarSection'; import PageToolbarSeparator from 'Components/Page/Toolbar/PageToolbarSeparator'; import { align, icons } from 'Helpers/Props'; import getErrorMessage from 'Utilities/Object/getErrorMessage'; import translate from 'Utilities/String/translate'; import CalendarConnector from './CalendarConnector'; import CalendarLinkModal from './iCal/CalendarLinkModal'; import LegendConnector from './Legend/LegendConnector'; import CalendarOptionsModal from './Options/CalendarOptionsModal'; import styles from './CalendarPage.css'; const MINIMUM_DAY_WIDTH = 120; class CalendarPage extends Component { // // Lifecycle constructor(props, context) { super(props, context); this.state = { isCalendarLinkModalOpen: false, isOptionsModalOpen: false, width: 0 }; } // // Listeners onMeasure = ({ width }) => { this.setState({ width }); const days = Math.max(3, Math.min(7, Math.floor(width / MINIMUM_DAY_WIDTH))); this.props.onDaysCountChange(days); }; onGetCalendarLinkPress = () => { this.setState({ isCalendarLinkModalOpen: true }); }; onGetCalendarLinkModalClose = () => { this.setState({ isCalendarLinkModalOpen: false }); }; onOptionsPress = () => { this.setState({ isOptionsModalOpen: true }); }; onOptionsModalClose = () => { this.setState({ isOptionsModalOpen: false }); }; onSearchMissingPress = () => { const { missingAlbumIds, onSearchMissingPress } = this.props; onSearchMissingPress(missingAlbumIds); }; // // Render render() { const { selectedFilterKey, filters, hasArtist, artistError, artistIsFetching, artistIsPopulated, missingAlbumIds, isRssSyncExecuting, isSearchingForMissing, useCurrentPage, onRssSyncPress, onFilterSelect } = this.props; const { isCalendarLinkModalOpen, isOptionsModalOpen } = this.state; const isMeasured = this.state.width > 0; return ( { artistIsFetching && !artistIsPopulated && } { artistError &&
{getErrorMessage(artistError, 'Failed to load artist from API')}
} { !artistError && artistIsPopulated && hasArtist && { isMeasured ? :
} } { !artistError && artistIsPopulated && !hasArtist && } { hasArtist && !!artistError && } ); } } CalendarPage.propTypes = { selectedFilterKey: PropTypes.string.isRequired, filters: PropTypes.arrayOf(PropTypes.object).isRequired, hasArtist: PropTypes.bool.isRequired, artistError: PropTypes.object, artistIsFetching: PropTypes.bool.isRequired, artistIsPopulated: PropTypes.bool.isRequired, missingAlbumIds: PropTypes.arrayOf(PropTypes.number).isRequired, isRssSyncExecuting: PropTypes.bool.isRequired, isSearchingForMissing: PropTypes.bool.isRequired, useCurrentPage: PropTypes.bool.isRequired, onSearchMissingPress: PropTypes.func.isRequired, onDaysCountChange: PropTypes.func.isRequired, onRssSyncPress: PropTypes.func.isRequired, onFilterSelect: PropTypes.func.isRequired }; export default CalendarPage;