From b22285674447bbffa554274cf3b44d9e54294a6e Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov <38059171+askvortsov1@users.noreply.github.com> Date: Thu, 7 Jan 2021 10:24:41 -0500 Subject: [PATCH] Add an `onFollowing` param to GlobalSearchState (#38) Add an `onFollowing` param to GlobalSearchState This ensures that it will be taken into account by IndexPage's `refreshParams` call, preventing the following page from being shown if the user: 1. goes to following 2. goes to any other page not inheriting IndexPage 3. goes to 'all discussions' Ref https://github.com/flarum/core/issues/2516 for a full explanation. --- .../js/src/forum/addSubscriptionFilter.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/extensions/subscriptions/js/src/forum/addSubscriptionFilter.js b/extensions/subscriptions/js/src/forum/addSubscriptionFilter.js index d75173aa5..5cfd63980 100644 --- a/extensions/subscriptions/js/src/forum/addSubscriptionFilter.js +++ b/extensions/subscriptions/js/src/forum/addSubscriptionFilter.js @@ -2,6 +2,7 @@ import { extend } from 'flarum/extend'; import LinkButton from 'flarum/components/LinkButton'; import IndexPage from 'flarum/components/IndexPage'; import DiscussionListState from 'flarum/states/DiscussionListState'; +import GlobalSearchState from 'flarum/states/GlobalSearchState'; export default function addSubscriptionFilter() { extend(IndexPage.prototype, 'navItems', function(items) { @@ -21,8 +22,14 @@ export default function addSubscriptionFilter() { } }); - extend(DiscussionListState.prototype, 'requestParams', function(params) { - if (app.current.get('routeName') === 'following') { + extend(GlobalSearchState.prototype, 'params', function (params) { + // We can't set `q` here directly, as that would make the search bar + // think that text has been entered, and display the "clear" button. + params.onFollowing = app.current.get('routeName') === 'following'; + }); + + extend(DiscussionListState.prototype, 'requestParams', function (params) { + if (this.params.onFollowing) { params.filter.q = (params.filter.q || '') + ' is:following'; } });