1
0
mirror of https://github.com/flarum/core.git synced 2025-08-13 20:04:24 +02:00

Fix extension to work with latest state changes

Refs flarum/core#2150, flarum/core#2151, flarum/core#2156.
This commit is contained in:
Franz Liedke
2020-06-26 14:44:08 +02:00
parent dcf814fb12
commit 942d39a37a
4 changed files with 15 additions and 15 deletions

View File

@@ -7,7 +7,7 @@ import tagsLabel from '../common/helpers/tagsLabel';
export default function() {
extend(IndexPage.prototype, 'newDiscussionAction', function(promise) {
const tag = app.store.getBy('tags', 'slug', this.params().tags);
const tag = app.store.getBy('tags', 'slug', app.search.params().tags);
if (tag) {
const parent = tag.parent();

View File

@@ -1,12 +1,13 @@
import { extend, override } from 'flarum/extend';
import IndexPage from 'flarum/components/IndexPage';
import DiscussionList from 'flarum/components/DiscussionList';
import DiscussionListState from 'flarum/states/DiscussionListState';
import GlobalSearchState from 'flarum/states/GlobalSearchState';
import TagHero from './components/TagHero';
export default function() {
IndexPage.prototype.currentTag = function() {
const slug = this.params().tags;
const slug = app.search.params().tags;
if (slug) return app.store.getBy('tags', 'slug', slug);
};
@@ -46,25 +47,24 @@ export default function() {
if (color) {
items.get('newDiscussion').props.style = {backgroundColor: color};
}
items.get('newDiscussion').props.disabled = !canStartDiscussion;
items.get('newDiscussion').props.children = app.translator.trans(canStartDiscussion ? 'core.forum.index.start_discussion_button' : 'core.forum.index.cannot_start_discussion_button');
}
});
// Add a parameter for the IndexPage to pass on to the DiscussionList that
// will let us filter discussions by tag.
extend(IndexPage.prototype, 'params', function(params) {
// Add a parameter for the global search state to pass on to the
// DiscussionListState that will let us filter discussions by tag.
extend(GlobalSearchState.prototype, 'params', function(params) {
params.tags = m.route.param('tags');
});
// Translate that parameter into a gambit appended to the search query.
extend(DiscussionList.prototype, 'requestParams', function(params) {
extend(DiscussionListState.prototype, 'requestParams', function(params) {
params.include.push('tags');
if (this.props.params.tags) {
params.filter.q = (params.filter.q || '') + ' tag:' + this.props.params.tags;
if (this.params.tags) {
params.filter.q = (params.filter.q || '') + ' tag:' + this.params.tags;
}
});
}

View File

@@ -17,11 +17,11 @@ export default function() {
href: app.route('tags')
}), -10);
if (app.current instanceof TagsPage) return;
if (app.current.matches(TagsPage)) return;
items.add('separator', Separator.component(), -12);
const params = this.stickyParams();
const params = app.search.stickyParams();
const tags = app.store.all('tags');
const currentTag = this.currentTag();

View File

@@ -310,8 +310,8 @@ export default class TagDiscussionModal extends Modal {
if (discussion) {
discussion.save({relationships: {tags}})
.then(() => {
if (app.current instanceof DiscussionPage) {
app.current.stream.update();
if (app.current.matches(DiscussionPage)) {
app.current.get('stream').update();
}
m.redraw();
});