mirror of
https://github.com/flarum/core.git
synced 2025-08-12 19:34:18 +02:00
feat: post search adapted with global search (#4019)
This commit is contained in:
3
extensions/mentions/js/src/admin/extend.ts
Normal file
3
extensions/mentions/js/src/admin/extend.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import commonExtend from '../common/extend';
|
||||
|
||||
export default [...commonExtend];
|
@@ -1,5 +1,7 @@
|
||||
import app from 'flarum/admin/app';
|
||||
|
||||
export { default as extend } from './extend';
|
||||
|
||||
app.initializers.add('flarum-mentions', () => {
|
||||
app.extensionData
|
||||
.for('flarum-mentions')
|
||||
|
7
extensions/mentions/js/src/common/extend.ts
Normal file
7
extensions/mentions/js/src/common/extend.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import Extend from 'flarum/common/extenders';
|
||||
import MentionedGambit from './query/posts/MentionedGambit';
|
||||
|
||||
export default [
|
||||
new Extend.Search() //
|
||||
.gambit('posts', MentionedGambit),
|
||||
];
|
@@ -0,0 +1,16 @@
|
||||
import { KeyValueGambit } from 'flarum/common/query/IGambit';
|
||||
import app from 'flarum/common/app';
|
||||
|
||||
export default class MentionedGambit extends KeyValueGambit {
|
||||
key(): string {
|
||||
return app.translator.trans('flarum-mentions.lib.gambits.posts.mentioned.key', {}, true);
|
||||
}
|
||||
|
||||
hint(): string {
|
||||
return app.translator.trans('flarum-mentions.lib.gambits.posts.mentioned.hint', {}, true);
|
||||
}
|
||||
|
||||
filterKey(): string {
|
||||
return 'mentioned';
|
||||
}
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
import app from 'flarum/forum/app';
|
||||
import PostsUserPage from 'flarum/forum/components/PostsUserPage';
|
||||
|
||||
/**
|
||||
* The `MentionsUserPage` component shows post which user Mentioned at
|
||||
*/
|
||||
export default class MentionsUserPage extends PostsUserPage {
|
||||
/**
|
||||
* Load a new page of the user's activity feed.
|
||||
*
|
||||
* @param {Integer} [offset] The position to start getting results from.
|
||||
* @return {Promise}
|
||||
* @protected
|
||||
*/
|
||||
loadResults(offset) {
|
||||
return app.store.find('posts', {
|
||||
filter: {
|
||||
type: 'comment',
|
||||
mentioned: this.user.id(),
|
||||
},
|
||||
page: { offset, limit: this.loadLimit },
|
||||
sort: '-createdAt',
|
||||
});
|
||||
}
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
import PostsUserPage from 'flarum/forum/components/PostsUserPage';
|
||||
import type User from 'flarum/common/models/User';
|
||||
|
||||
/**
|
||||
* The `MentionsUserPage` component shows post which user Mentioned at
|
||||
*/
|
||||
export default class MentionsUserPage extends PostsUserPage {
|
||||
params(user: User) {
|
||||
return {
|
||||
filter: {
|
||||
type: 'comment',
|
||||
mentioned: user.id(),
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
@@ -6,7 +6,11 @@ import PostMentionedNotification from './components/PostMentionedNotification';
|
||||
import UserMentionedNotification from './components/UserMentionedNotification';
|
||||
import GroupMentionedNotification from './components/GroupMentionedNotification';
|
||||
|
||||
import commonExtend from '../common/extend';
|
||||
|
||||
export default [
|
||||
...commonExtend,
|
||||
|
||||
new Extend.Routes() //
|
||||
.add('user.mentions', '/u/:username/mentions', MentionsUserPage),
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { extend } from 'flarum/common/extend';
|
||||
import { extend, override } from 'flarum/common/extend';
|
||||
import app from 'flarum/forum/app';
|
||||
import { getPlainContent } from 'flarum/common/utils/string';
|
||||
import textContrastClass from 'flarum/common/helpers/textContrastClass';
|
||||
@@ -79,6 +79,22 @@ app.initializers.add('flarum-mentions', () => {
|
||||
this.classList.add(textContrastClass(getComputedStyle(this).getPropertyValue('--color')));
|
||||
});
|
||||
});
|
||||
|
||||
// Auto scope the search to the current user mentioned posts.
|
||||
override('flarum/forum/components/SearchModal', 'defaultActiveSource', function (original) {
|
||||
const orig = original();
|
||||
|
||||
if (!orig && app.current.data.routeName && app.current.data.routeName.includes('user.mentions') && app.current.data.user) {
|
||||
return 'posts';
|
||||
}
|
||||
|
||||
return orig;
|
||||
});
|
||||
extend('flarum/forum/components/SearchModal', 'defaultFilters', function (filters) {
|
||||
if (app.current.data.routeName && app.current.data.routeName.includes('user.mentions') && app.current.data.user) {
|
||||
filters.posts.mentioned = app.current.data.user.username();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
export * from './utils/textFormatter';
|
||||
|
Reference in New Issue
Block a user