1
0
mirror of https://github.com/flarum/core.git synced 2025-08-07 17:07:19 +02:00

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.
This commit is contained in:
Alexander Skvortsov
2021-01-07 10:24:41 -05:00
committed by GitHub
parent 1b69d455d1
commit b222856744

View File

@@ -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';
}
});