|
|
@@ -6,7 +6,6 @@ import { withTranslation } from 'react-i18next';
|
|
|
|
|
|
import { withUnstatedContainers } from './UnstatedUtils';
|
|
|
import AppContainer from '~/client/services/AppContainer';
|
|
|
-
|
|
|
import { toastError } from '~/client/util/apiNotification';
|
|
|
import SearchPageLayout from './SearchPage/SearchPageLayout';
|
|
|
import SearchResultContent from './SearchPage/SearchResultContent';
|
|
|
@@ -30,23 +29,24 @@ class SearchPage extends React.Component {
|
|
|
searchedKeyword: '',
|
|
|
searchResults: [],
|
|
|
searchResultMeta: {},
|
|
|
- focusedSearchResultData: {},
|
|
|
+ focusedSearchResultData: null,
|
|
|
selectedPages: new Set(),
|
|
|
searchResultCount: 0,
|
|
|
activePage: 1,
|
|
|
- pagingLimit: 10, // change to an appropriate limit number
|
|
|
+ pagingLimit: this.props.appContainer.config.pageLimitationL,
|
|
|
excludeUsersHome: true,
|
|
|
excludeTrash: true,
|
|
|
};
|
|
|
|
|
|
this.changeURL = this.changeURL.bind(this);
|
|
|
this.search = this.search.bind(this);
|
|
|
- this.searchHandler = this.searchHandler.bind(this);
|
|
|
+ this.onSearchInvoked = this.onSearchInvoked.bind(this);
|
|
|
this.selectPage = this.selectPage.bind(this);
|
|
|
this.toggleCheckBox = this.toggleCheckBox.bind(this);
|
|
|
this.onExcludeUsersHome = this.onExcludeUsersHome.bind(this);
|
|
|
this.onExcludeTrash = this.onExcludeTrash.bind(this);
|
|
|
this.onPagingNumberChanged = this.onPagingNumberChanged.bind(this);
|
|
|
+ this.onPagingLimitChanged = this.onPagingLimitChanged.bind(this);
|
|
|
}
|
|
|
|
|
|
componentDidMount() {
|
|
|
@@ -105,20 +105,23 @@ class SearchPage extends React.Component {
|
|
|
* this method is called when user changes paging number
|
|
|
*/
|
|
|
async onPagingNumberChanged(activePage) {
|
|
|
- // this.setState does not change the state immediately and following calls of this.search outside of this.setState will have old activePage state.
|
|
|
- // To prevent above, pass this.search as a callback function to make sure this.search will have the latest activePage state.
|
|
|
this.setState({ activePage }, () => this.search({ keyword: this.state.searchedKeyword }));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* this method is called when user searches by pressing Enter or using searchbox
|
|
|
*/
|
|
|
- async searchHandler(data) {
|
|
|
- // this.setState does not change the state immediately and following calls of this.search outside of this.setState will have old activePage state.
|
|
|
- // To prevent above, pass this.search as a callback function to make sure this.search will have the latest activePage state.
|
|
|
+ async onSearchInvoked(data) {
|
|
|
this.setState({ activePage: 1 }, () => this.search(data));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * change number of pages to display per page and execute search method after.
|
|
|
+ */
|
|
|
+ async onPagingLimitChanged(limit) {
|
|
|
+ this.setState({ pagingLimit: limit }, () => this.search({ keyword: this.state.searchedKeyword }));
|
|
|
+ }
|
|
|
+
|
|
|
async search(data) {
|
|
|
const keyword = data.keyword;
|
|
|
if (keyword === '') {
|
|
|
@@ -223,7 +226,7 @@ class SearchPage extends React.Component {
|
|
|
<SearchControl
|
|
|
searchingKeyword={this.state.searchingKeyword}
|
|
|
appContainer={this.props.appContainer}
|
|
|
- onSearchInvoked={this.searchHandler}
|
|
|
+ onSearchInvoked={this.onSearchInvoked}
|
|
|
onExcludeUsersHome={this.onExcludeUsersHome}
|
|
|
onExcludeTrash={this.onExcludeTrash}
|
|
|
>
|
|
|
@@ -240,6 +243,8 @@ class SearchPage extends React.Component {
|
|
|
SearchResultContent={this.renderSearchResultContent}
|
|
|
searchResultMeta={this.state.searchResultMeta}
|
|
|
searchingKeyword={this.state.searchedKeyword}
|
|
|
+ onPagingLimitChanged={this.onPagingLimitChanged}
|
|
|
+ initialPagingLimit={this.props.appContainer.config.pageLimitationL || 50}
|
|
|
>
|
|
|
</SearchPageLayout>
|
|
|
</div>
|
|
|
@@ -256,7 +261,6 @@ const SearchPageWrapper = withUnstatedContainers(SearchPage, [AppContainer]);
|
|
|
SearchPage.propTypes = {
|
|
|
t: PropTypes.func.isRequired, // i18next
|
|
|
appContainer: PropTypes.instanceOf(AppContainer).isRequired,
|
|
|
-
|
|
|
query: PropTypes.object,
|
|
|
};
|
|
|
SearchPage.defaultProps = {
|