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

feat: frontend Model extender (#3646)

* 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>
This commit is contained in:
Sami Mazouz
2023-02-08 21:13:53 +01:00
committed by GitHub
parent f9a5d485c3
commit 47b670aa29
28 changed files with 220 additions and 67 deletions

View File

@@ -1,4 +1,13 @@
import Extend from 'flarum/common/extenders';
import Post from 'flarum/common/models/Post';
import User from 'flarum/common/models/User';
import LikesUserPage from './components/LikesUserPage';
export default [new Extend.Routes().add('user.likes', '/u/:username/likes', LikesUserPage)];
export default [
new Extend.Routes() //
.add('user.likes', '/u/:username/likes', LikesUserPage),
new Extend.Model(Post) //
.hasMany<User>('likes')
.attribute<boolean>('canLike'),
];

View File

@@ -1,7 +1,5 @@
import { extend } from 'flarum/common/extend';
import app from 'flarum/forum/app';
import Post from 'flarum/common/models/Post';
import Model from 'flarum/common/Model';
import NotificationGrid from 'flarum/forum/components/NotificationGrid';
import addLikeAction from './addLikeAction';
@@ -14,9 +12,6 @@ export { default as extend } from './extend';
app.initializers.add('flarum-likes', () => {
app.notificationComponents.postLiked = PostLikedNotification;
Post.prototype.canLike = Model.attribute('canLike');
Post.prototype.likes = Model.hasMany('likes');
addLikeAction();
addLikesList();
addLikesTabToUserProfile();