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.
95 lines
2.4 KiB
95 lines
2.4 KiB
7 years ago
|
import PropTypes from 'prop-types';
|
||
|
import React, { Component } from 'react';
|
||
6 years ago
|
import { connect } from 'react-redux';
|
||
7 years ago
|
import { createSelector } from 'reselect';
|
||
7 years ago
|
import * as releaseActions from 'Store/Actions/releaseActions';
|
||
7 years ago
|
import createClientSideCollectionSelector from 'Store/Selectors/createClientSideCollectionSelector';
|
||
6 years ago
|
import createUISettingsSelector from 'Store/Selectors/createUISettingsSelector';
|
||
|
import InteractiveSearch from './InteractiveSearch';
|
||
7 years ago
|
|
||
6 years ago
|
function createMapStateToProps(appState, { type }) {
|
||
7 years ago
|
return createSelector(
|
||
7 years ago
|
(state) => state.releases.items.length,
|
||
6 years ago
|
createClientSideCollectionSelector('releases', `releases.${type}`),
|
||
7 years ago
|
createUISettingsSelector(),
|
||
7 years ago
|
(totalReleasesCount, releases, uiSettings) => {
|
||
7 years ago
|
return {
|
||
7 years ago
|
totalReleasesCount,
|
||
7 years ago
|
longDateFormat: uiSettings.longDateFormat,
|
||
|
timeFormat: uiSettings.timeFormat,
|
||
|
...releases
|
||
|
};
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
|
||
|
function createMapDispatchToProps(dispatch, props) {
|
||
|
return {
|
||
6 years ago
|
dispatchFetchReleases(payload) {
|
||
|
dispatch(releaseActions.fetchReleases(payload));
|
||
7 years ago
|
},
|
||
|
|
||
|
onSortPress(sortKey, sortDirection) {
|
||
|
dispatch(releaseActions.setReleasesSort({ sortKey, sortDirection }));
|
||
7 years ago
|
},
|
||
|
|
||
7 years ago
|
onFilterSelect(selectedFilterKey) {
|
||
6 years ago
|
const action = props.type === 'album' ?
|
||
|
releaseActions.setAlbumReleasesFilter :
|
||
|
releaseActions.setArtistReleasesFilter;
|
||
|
|
||
|
dispatch(action({ selectedFilterKey }));
|
||
7 years ago
|
},
|
||
|
|
||
6 years ago
|
onGrabPress(payload) {
|
||
|
dispatch(releaseActions.grabRelease(payload));
|
||
7 years ago
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
6 years ago
|
class InteractiveSearchConnector extends Component {
|
||
7 years ago
|
|
||
|
//
|
||
|
// Lifecycle
|
||
|
|
||
|
componentDidMount() {
|
||
|
const {
|
||
6 years ago
|
searchPayload,
|
||
|
isPopulated,
|
||
|
dispatchFetchReleases
|
||
7 years ago
|
} = this.props;
|
||
|
|
||
6 years ago
|
// If search results are not yet isPopulated fetch them,
|
||
|
// otherwise re-show the existing props.
|
||
7 years ago
|
|
||
6 years ago
|
if (!isPopulated) {
|
||
|
dispatchFetchReleases(searchPayload);
|
||
|
}
|
||
7 years ago
|
}
|
||
|
|
||
|
//
|
||
|
// Render
|
||
|
|
||
|
render() {
|
||
7 years ago
|
const {
|
||
|
dispatchFetchReleases,
|
||
|
...otherProps
|
||
|
} = this.props;
|
||
|
|
||
7 years ago
|
return (
|
||
6 years ago
|
|
||
|
<InteractiveSearch
|
||
7 years ago
|
{...otherProps}
|
||
7 years ago
|
/>
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
6 years ago
|
InteractiveSearchConnector.propTypes = {
|
||
|
searchPayload: PropTypes.object.isRequired,
|
||
|
isPopulated: PropTypes.bool.isRequired,
|
||
|
dispatchFetchReleases: PropTypes.func.isRequired
|
||
7 years ago
|
};
|
||
|
|
||
6 years ago
|
export default connect(createMapStateToProps, createMapDispatchToProps)(InteractiveSearchConnector);
|