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:
Daniel Klabbers 2021-11-10 13:36:34 +01:00
parent 8111c214cc
commit bad10ef03d
3 changed files with 22 additions and 20 deletions

2
js/dist/forum.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,12 +1,14 @@
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);
const preloaded = app.preloadedApiDocument() || null;
if (preloaded || !this.requestParams()?.filter?.q) return original.call(this, page);
const params = this.requestParams();
params.page = {
@ -22,7 +24,7 @@ export default function extendDiscussionState() {
const url = `${app.forum.attribute('apiUrl')}/blomstra/search/${this.type}`;
// Make API GET request
const results = await app.request({ params, url, method: 'GET' });
const results = await app.request({params, url, method: 'GET'});
// Parse API response into models and push to store
return app.store.pushPayload(results);