import _ from 'lodash'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import IndexersSelectInputConnector from 'Components/Form/IndexersSelectInputConnector'; import NewznabCategorySelectInputConnector from 'Components/Form/NewznabCategorySelectInputConnector'; import TextInput from 'Components/Form/TextInput'; import keyboardShortcuts from 'Components/keyboardShortcuts'; import SpinnerButton from 'Components/Link/SpinnerButton'; import PageContentFooter from 'Components/Page/PageContentFooter'; import translate from 'Utilities/String/translate'; import SearchFooterLabel from './SearchFooterLabel'; import styles from './SearchFooter.css'; class SearchFooter extends Component { // // Lifecycle constructor(props, context) { super(props, context); const { defaultIndexerIds, defaultCategories, defaultSearchQuery } = props; this.state = { searchingReleases: false, searchQuery: defaultSearchQuery || '', searchIndexerIds: defaultIndexerIds, searchCategories: defaultCategories }; } componentDidMount() { const { searchIndexerIds, searchCategories, searchQuery } = this.state; if (searchQuery !== '' || searchCategories.length > 0 || searchIndexerIds.length > 0) { this.onSearchPress(); } this.props.bindShortcut('enter', this.onSearchPress, { isGlobal: true }); } componentDidUpdate(prevProps) { const { isFetching, defaultIndexerIds, defaultCategories, defaultSearchQuery, searchError } = this.props; const { searchIndexerIds, searchCategories } = this.state; const newState = {}; if (defaultSearchQuery && defaultSearchQuery !== prevProps.defaultSearchQuery) { newState.searchQuery = defaultSearchQuery; } if (searchIndexerIds !== defaultIndexerIds) { newState.searchIndexerIds = defaultIndexerIds; } if (searchCategories !== defaultCategories) { newState.searchCategories = defaultCategories; } if (prevProps.isFetching && !isFetching && !searchError) { newState.searchingReleases = false; } if (!_.isEmpty(newState)) { this.setState(newState); } } // // Listeners onSearchPress = () => { this.props.onSearchPress(this.state.searchQuery, this.state.searchIndexerIds, this.state.searchCategories); } onSearchInputChange = ({ value }) => { this.setState({ searchQuery: value }); } // // Render render() { const { isFetching, hasIndexers, onInputChange } = this.props; const { searchQuery, searchIndexerIds, searchCategories } = this.state; return (
{translate('Search')}
); } } SearchFooter.propTypes = { defaultIndexerIds: PropTypes.arrayOf(PropTypes.number).isRequired, defaultCategories: PropTypes.arrayOf(PropTypes.number).isRequired, defaultSearchQuery: PropTypes.string.isRequired, isFetching: PropTypes.bool.isRequired, onSearchPress: PropTypes.func.isRequired, hasIndexers: PropTypes.bool.isRequired, onInputChange: PropTypes.func.isRequired, searchError: PropTypes.object, bindShortcut: PropTypes.func.isRequired }; export default keyboardShortcuts(SearchFooter);