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,12 +1,14 @@
|
||||||
import app from 'flarum/forum/app';
|
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';
|
import DiscussionListState from 'flarum/forum/states/DiscussionListState';
|
||||||
|
|
||||||
export default function extendDiscussionState() {
|
export default function extendDiscussionState() {
|
||||||
override(DiscussionListState.prototype, 'loadPage', async function (this: DiscussionListState, original, page: number = 1) {
|
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();
|
const params = this.requestParams();
|
||||||
params.page = {
|
params.page = {
|
||||||
|
|
@ -22,7 +24,7 @@ export default function extendDiscussionState() {
|
||||||
const url = `${app.forum.attribute('apiUrl')}/blomstra/search/${this.type}`;
|
const url = `${app.forum.attribute('apiUrl')}/blomstra/search/${this.type}`;
|
||||||
|
|
||||||
// Make API GET request
|
// 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
|
// Parse API response into models and push to store
|
||||||
return app.store.pushPayload(results);
|
return app.store.pushPayload(results);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue