158 lines
3.6 KiB
JavaScript
Raw Normal View History

/*
*
* HomePage
*
*/
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { createStructuredSelector } from 'reselect';
import { injectIntl } from 'react-intl';
import { bindActionCreators, compose } from 'redux';
// You can find these components in either
// ./node_modules/strapi-helper-plugin/lib/src
// or strapi/packages/strapi-helper-plugin/lib/src
import ContainerFluid from 'components/ContainerFluid';
import InputSearch from 'components/InputSearch';
// import InputSelect from 'components/InputSelect';
import PluginHeader from 'components/PluginHeader';
// Plugin's component
import EntriesNumber from 'components/EntriesNumber';
2018-02-16 16:53:01 +01:00
import List from 'components/List';
import PluginInputFile from 'components/PluginInputFile';
// Utils
import injectReducer from 'utils/injectReducer';
import injectSaga from 'utils/injectSaga';
// Actions
import {
2018-02-19 15:14:32 +01:00
deleteData,
getData,
2018-02-19 15:14:32 +01:00
onDrop,
onSearch,
} from './actions';
// Selectors
import selectHomePage from './selectors';
// Styles
import styles from './styles.scss';
import reducer from './reducer';
import saga from './saga';
export class HomePage extends React.Component {
2018-02-19 15:14:32 +01:00
getChildContext = () => (
{
deleteData: this.props.deleteData,
}
);
componentDidMount() {
this.props.getData();
}
2018-02-19 15:14:32 +01:00
componentWillReceiveProps(nextProps) {
if (nextProps.deleteSuccess !== this.props.deleteSuccess) {
this.props.getData();
}
}
renderInputSearch = () =>
<InputSearch
autoFocus
name="search"
onChange={this.props.onSearch}
placeholder="upload.HomePage.InputSearch.placeholder"
style={{ marginTop: '-10px' }}
value={this.props.search}
/>
render() {
return (
<ContainerFluid>
<div className={styles.homePageUpload}>
<PluginHeader
title={{
id: 'upload.HomePage.title',
}}
description={{
id: 'upload.HomePage.description',
}}
overrideRendering={this.renderInputSearch}
/>
</div>
<PluginInputFile
name="files"
2018-02-16 14:17:24 +01:00
onDrop={this.props.onDrop}
/>
<div className={styles.entriesWrapper}>
<div>
{/* NOTE: Prepare for bulk actions}
<InputSelect
name="bulkAction"
onChange={() => console.log('change')}
selectOptions={[{ value: 'select all'}]}
2018-02-16 16:53:01 +01:00
style={{ minWidth: '200px', height: '32px', marginTop: '-8px' }}
/>
*/}
</div>
<EntriesNumber number={this.props.entriesNumber} />
</div>
2018-02-19 13:10:35 +01:00
<List
data={this.props.uploadedFiles}
/>
</ContainerFluid>
);
}
}
2018-02-19 15:14:32 +01:00
HomePage.childContextTypes = {
deleteData: PropTypes.func.isRequired,
};
2018-02-19 13:10:35 +01:00
HomePage.defaultProps = {
uploadedFiles: [{}],
};
HomePage.contextTypes = {
router: PropTypes.object,
2018-02-19 13:10:35 +01:00
uploadedFiles: PropTypes.arrayOf(PropTypes.object),
};
HomePage.propTypes = {
getData: PropTypes.func.isRequired,
2018-02-16 14:17:24 +01:00
onDrop: PropTypes.func.isRequired,
onSearch: PropTypes.func.isRequired,
search: PropTypes.string.isRequired,
};
function mapDispatchToProps(dispatch) {
return bindActionCreators(
{
2018-02-19 15:14:32 +01:00
deleteData,
getData,
2018-02-19 15:14:32 +01:00
onDrop,
onSearch,
},
dispatch,
);
}
const mapStateToProps = selectHomePage();
const withConnect = connect(mapStateToProps, mapDispatchToProps);
const withReducer = injectReducer({ key: 'homePage', reducer });
const withSaga = injectSaga({ key: 'homePage', saga });
export default compose(
withReducer,
withSaga,
withConnect,
)(injectIntl(HomePage));