|
|
@@ -11,9 +11,9 @@ import SearchPageLayout from './SearchPage/SearchPageLayout';
|
|
|
import SearchResultContent from './SearchPage/SearchResultContent';
|
|
|
import SearchResultList from './SearchPage/SearchResultList';
|
|
|
import SearchControl from './SearchPage/SearchControl';
|
|
|
+import { CheckboxType, SORT_AXIS, SORT_ORDER } from '~/interfaces/search';
|
|
|
import PageDeleteModal from './PageDeleteModal';
|
|
|
-
|
|
|
-import { CheckboxType } from '../interfaces/search';
|
|
|
+import { useIsGuestUser } from '~/stores/context';
|
|
|
|
|
|
export const specificPathNames = {
|
|
|
user: '/user',
|
|
|
@@ -35,9 +35,11 @@ class SearchPage extends React.Component {
|
|
|
selectedPagesIdList: new Set(),
|
|
|
searchResultCount: 0,
|
|
|
activePage: 1,
|
|
|
- pagingLimit: this.props.appContainer.config.pageLimitationL,
|
|
|
+ pagingLimit: this.props.appContainer.config.pageLimitationL || 50,
|
|
|
excludeUserPages: true,
|
|
|
excludeTrashPages: true,
|
|
|
+ sort: SORT_AXIS.RELATION_SCORE,
|
|
|
+ order: SORT_ORDER.DESC,
|
|
|
selectAllCheckboxType: CheckboxType.NONE_CHECKED,
|
|
|
isDeleteConfirmModalShown: false,
|
|
|
deleteTargetPageIds: new Set(),
|
|
|
@@ -50,6 +52,7 @@ class SearchPage extends React.Component {
|
|
|
this.toggleCheckBox = this.toggleCheckBox.bind(this);
|
|
|
this.switchExcludeUserPagesHandler = this.switchExcludeUserPagesHandler.bind(this);
|
|
|
this.switchExcludeTrashPagesHandler = this.switchExcludeTrashPagesHandler.bind(this);
|
|
|
+ this.onChangeSortInvoked = this.onChangeSortInvoked.bind(this);
|
|
|
this.onPagingNumberChanged = this.onPagingNumberChanged.bind(this);
|
|
|
this.onPagingLimitChanged = this.onPagingLimitChanged.bind(this);
|
|
|
this.deleteSinglePageButtonHandler = this.deleteSinglePageButtonHandler.bind(this);
|
|
|
@@ -84,6 +87,13 @@ class SearchPage extends React.Component {
|
|
|
this.setState({ excludeTrashPages: !this.state.excludeTrashPages });
|
|
|
}
|
|
|
|
|
|
+ onChangeSortInvoked(nextSort, nextOrder) {
|
|
|
+ this.setState({
|
|
|
+ sort: nextSort,
|
|
|
+ order: nextOrder,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
changeURL(keyword, refreshHash) {
|
|
|
let hash = window.location.hash || '';
|
|
|
// TODO 整理する
|
|
|
@@ -152,11 +162,14 @@ class SearchPage extends React.Component {
|
|
|
});
|
|
|
const pagingLimit = this.state.pagingLimit;
|
|
|
const offset = (this.state.activePage * pagingLimit) - pagingLimit;
|
|
|
+ const { sort, order } = this.state;
|
|
|
try {
|
|
|
const res = await this.props.appContainer.apiGet('/search', {
|
|
|
q: this.createSearchQuery(keyword),
|
|
|
limit: pagingLimit,
|
|
|
offset,
|
|
|
+ sort,
|
|
|
+ order,
|
|
|
});
|
|
|
this.changeURL(keyword);
|
|
|
if (res.data.length > 0) {
|
|
|
@@ -271,6 +284,7 @@ class SearchPage extends React.Component {
|
|
|
return (
|
|
|
<SearchResultList
|
|
|
pages={this.state.searchResults || []}
|
|
|
+ isEnableActions={!this.props.isGuestUser}
|
|
|
focusedSearchResultData={this.state.focusedSearchResultData}
|
|
|
selectedPagesIdList={this.state.selectedPagesIdList || []}
|
|
|
searchResultCount={this.state.searchResultCount}
|
|
|
@@ -288,6 +302,8 @@ class SearchPage extends React.Component {
|
|
|
return (
|
|
|
<SearchControl
|
|
|
searchingKeyword={this.state.searchingKeyword}
|
|
|
+ sort={this.state.sort}
|
|
|
+ order={this.state.order}
|
|
|
searchResultCount={this.state.searchResultCount || 0}
|
|
|
appContainer={this.props.appContainer}
|
|
|
onSearchInvoked={this.onSearchInvoked}
|
|
|
@@ -298,6 +314,7 @@ class SearchPage extends React.Component {
|
|
|
onExcludeTrashPagesSwitched={this.switchExcludeTrashPagesHandler}
|
|
|
excludeUserPages={this.state.excludeUserPages}
|
|
|
excludeTrashPages={this.state.excludeTrashPages}
|
|
|
+ onChangeSortInvoked={this.onChangeSortInvoked}
|
|
|
>
|
|
|
</SearchControl>
|
|
|
);
|
|
|
@@ -313,7 +330,8 @@ class SearchPage extends React.Component {
|
|
|
searchResultMeta={this.state.searchResultMeta}
|
|
|
searchingKeyword={this.state.searchedKeyword}
|
|
|
onPagingLimitChanged={this.onPagingLimitChanged}
|
|
|
- initialPagingLimit={this.props.appContainer.config.pageLimitationL || 50}
|
|
|
+ pagingLimit={this.state.pagingLimit}
|
|
|
+ activePage={this.state.activePage}
|
|
|
>
|
|
|
</SearchPageLayout>
|
|
|
<PageDeleteModal
|
|
|
@@ -330,16 +348,30 @@ class SearchPage extends React.Component {
|
|
|
/**
|
|
|
* Wrapper component for using unstated
|
|
|
*/
|
|
|
-const SearchPageWrapper = withUnstatedContainers(SearchPage, [AppContainer]);
|
|
|
+const SearchPageHOCWrapper = withTranslation()(withUnstatedContainers(SearchPage, [AppContainer]));
|
|
|
|
|
|
SearchPage.propTypes = {
|
|
|
t: PropTypes.func.isRequired, // i18next
|
|
|
appContainer: PropTypes.instanceOf(AppContainer).isRequired,
|
|
|
query: PropTypes.object,
|
|
|
+ isGuestUser: PropTypes.bool.isRequired,
|
|
|
};
|
|
|
SearchPage.defaultProps = {
|
|
|
// pollInterval: 1000,
|
|
|
query: SearchPage.getQueryByLocation(window.location || {}),
|
|
|
};
|
|
|
|
|
|
-export default withTranslation()(SearchPageWrapper);
|
|
|
+const SearchPageFCWrapper = (props) => {
|
|
|
+ const { data: isGuestUser } = useIsGuestUser();
|
|
|
+
|
|
|
+ /*
|
|
|
+ * dependencies
|
|
|
+ */
|
|
|
+ if (isGuestUser == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ return <SearchPageHOCWrapper {...props} isGuestUser={isGuestUser} />;
|
|
|
+};
|
|
|
+
|
|
|
+export default SearchPageFCWrapper;
|