Skip to content

Commit

Permalink
feat: frontend Model extender (#3646)
Browse files Browse the repository at this point in the history
* feat: reintroduce frontend extenders
* chore: used `Routes` extender in bundled extensions
* chore: used `PostTypes` extender in bundled extensions
* chore: `yarn format`
* feat: `Model` frontend extender
* chore: naming
* chore(review): attributes can be nullable or undefined
* chore(review): delay extender implementation
* chore(review): unnecessary check
* chore(review): stay consistent
* chore: merge conflicts
* chore: unused import
* chore: multiline extenders
* feat: add Store extender

Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
  • Loading branch information
SychO9 authored Feb 8, 2023
1 parent 214f91e commit 1b698c6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 0 additions & 4 deletions js/src/forum/addMentionedByList.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import app from 'flarum/forum/app';
import { extend } from 'flarum/common/extend';
import Model from 'flarum/common/Model';
import Post from 'flarum/common/models/Post';
import CommentPost from 'flarum/forum/components/CommentPost';
import Link from 'flarum/common/components/Link';
import PostPreview from 'flarum/forum/components/PostPreview';
Expand All @@ -10,8 +8,6 @@ import username from 'flarum/common/helpers/username';
import icon from 'flarum/common/helpers/icon';

export default function addMentionedByList() {
Post.prototype.mentionedBy = Model.hasMany('mentionedBy');

function hidePreview() {
this.$('.Post-mentionedBy-preview')
.removeClass('in')
Expand Down
13 changes: 12 additions & 1 deletion js/src/forum/extend.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import Extend from 'flarum/common/extenders';
import Post from 'flarum/common/models/Post';
import User from 'flarum/common/models/User';
import MentionsUserPage from './components/MentionsUserPage';

export default [new Extend.Routes().add('user.mentions', '/u/:username/mentions', MentionsUserPage)];
export default [
new Extend.Routes() //
.add('user.mentions', '/u/:username/mentions', MentionsUserPage),

new Extend.Model(Post) //
.hasMany<Post>('mentionedBy'),

new Extend.Model(User) //
.attribute<boolean>('canMentionGroups'),
];
2 changes: 0 additions & 2 deletions js/src/forum/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import Model from 'flarum/common/Model';
export { default as extend } from './extend';

app.initializers.add('flarum-mentions', function () {
User.prototype.canMentionGroups = Model.attribute('canMentionGroups');

// For every mention of a post inside a post's content, set up a hover handler
// that shows a preview of the mentioned post.
addPostMentionPreviews();
Expand Down

0 comments on commit 1b698c6

Please sign in to comment.