only override the search on the frontend if its not already been handled by the backend to prevent duplicate queries
This commit is contained in:
parent
8111c214cc
commit
bad10ef03d
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -1,30 +1,32 @@
|
|||
import app from 'flarum/forum/app';
|
||||
|
||||
import { override } from 'flarum/common/extend';
|
||||
import {override} from 'flarum/common/extend';
|
||||
|
||||
import DiscussionListState from 'flarum/forum/states/DiscussionListState';
|
||||
|
||||
export default function extendDiscussionState() {
|
||||
override(DiscussionListState.prototype, 'loadPage', async function (this: DiscussionListState, original, page: number = 1) {
|
||||
if (!this.requestParams()?.filter?.q) return original.call(this, page);
|
||||
override(DiscussionListState.prototype, 'loadPage', async function (this: DiscussionListState, original, page: number = 1) {
|
||||
const preloaded = app.preloadedApiDocument() || null;
|
||||
|
||||
const params = this.requestParams();
|
||||
params.page = {
|
||||
offset: this.pageSize * (page - 1),
|
||||
...params.page,
|
||||
};
|
||||
if (preloaded || !this.requestParams()?.filter?.q) return original.call(this, page);
|
||||
|
||||
if (Array.isArray(params.include)) {
|
||||
params.include = params.include.join(',');
|
||||
}
|
||||
const params = this.requestParams();
|
||||
params.page = {
|
||||
offset: this.pageSize * (page - 1),
|
||||
...params.page,
|
||||
};
|
||||
|
||||
// Construct API search URI
|
||||
const url = `${app.forum.attribute('apiUrl')}/blomstra/search/${this.type}`;
|
||||
if (Array.isArray(params.include)) {
|
||||
params.include = params.include.join(',');
|
||||
}
|
||||
|
||||
// Make API GET request
|
||||
const results = await app.request({ params, url, method: 'GET' });
|
||||
// Construct API search URI
|
||||
const url = `${app.forum.attribute('apiUrl')}/blomstra/search/${this.type}`;
|
||||
|
||||
// Parse API response into models and push to store
|
||||
return app.store.pushPayload(results);
|
||||
});
|
||||
// Make API GET request
|
||||
const results = await app.request({params, url, method: 'GET'});
|
||||
|
||||
// Parse API response into models and push to store
|
||||
return app.store.pushPayload(results);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue