mirror of
https://github.com/discourse/discourse.git
synced 2025-01-16 03:52:41 +08:00
DEV: Add behavior transformer for full page search loadMore (#30648)
This commit is contained in:
parent
40f7941f2b
commit
a29b964329
|
@ -18,6 +18,7 @@ import {
|
|||
translateResults,
|
||||
updateRecentSearches,
|
||||
} from "discourse/lib/search";
|
||||
import { applyBehaviorTransformer } from "discourse/lib/transformer";
|
||||
import userSearch from "discourse/lib/user-search";
|
||||
import { escapeExpression } from "discourse/lib/utilities";
|
||||
import { scrollTop } from "discourse/mixins/scroll-top";
|
||||
|
@ -565,17 +566,24 @@ export default class FullPageSearchController extends Controller {
|
|||
this._search();
|
||||
}
|
||||
|
||||
@action
|
||||
loadMore() {
|
||||
let page = this.page;
|
||||
if (
|
||||
get canLoadMore() {
|
||||
return (
|
||||
this.get("model.grouped_search_result.more_full_page_results") &&
|
||||
!this.loading &&
|
||||
page < PAGE_LIMIT
|
||||
) {
|
||||
this.page < PAGE_LIMIT
|
||||
);
|
||||
}
|
||||
|
||||
@action
|
||||
loadMore() {
|
||||
if (!this.canLoadMore) {
|
||||
return;
|
||||
}
|
||||
|
||||
applyBehaviorTransformer("full-page-search-load-more", () => {
|
||||
this.incrementProperty("page");
|
||||
this._search();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@action
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
export const BEHAVIOR_TRANSFORMERS = Object.freeze([
|
||||
// use only lowercase names
|
||||
"discovery-topic-list-load-more",
|
||||
"full-page-search-load-more",
|
||||
]);
|
||||
|
||||
export const VALUE_TRANSFORMERS = Object.freeze([
|
||||
|
|
|
@ -297,6 +297,10 @@
|
|||
{{/if}}
|
||||
</ConditionalLoadingSpinner>
|
||||
{{/if}}
|
||||
<PluginOutlet
|
||||
@name="full-page-search-below-results"
|
||||
@outletArgs={{hash canLoadMore=this.canLoadMore}}
|
||||
/>
|
||||
</LoadMore>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
import { setupTest } from "ember-qunit";
|
||||
import { module, test } from "qunit";
|
||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||
|
||||
module("Unit | Controller | full-page-search", function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test("full-page-search-load-more behavior transformer", function (assert) {
|
||||
withPluginApi("2.0.0", (api) => {
|
||||
const controller = this.owner.lookup("controller:full-page-search");
|
||||
controller.model = {
|
||||
grouped_search_result: { more_full_page_results: true },
|
||||
};
|
||||
|
||||
api.registerBehaviorTransformer(
|
||||
"full-page-search-load-more",
|
||||
({ next }) => {
|
||||
if (controller.blockWithTransformer) {
|
||||
return;
|
||||
}
|
||||
next();
|
||||
}
|
||||
);
|
||||
|
||||
assert.strictEqual(controller.page, 1);
|
||||
|
||||
controller.loadMore();
|
||||
assert.strictEqual(controller.page, 2);
|
||||
|
||||
// Block loading by setting variable on controller which transformer sees
|
||||
controller.blockWithTransformer = true;
|
||||
controller.loadMore();
|
||||
assert.strictEqual(controller.page, 2);
|
||||
|
||||
// Now unblock and ensure next() functions
|
||||
controller.blockWithTransformer = false;
|
||||
controller.loadMore();
|
||||
assert.strictEqual(controller.page, 3);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user