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

feat: introduce frontend extenders (#3645)

* feat: reintroduce frontend extenders
* chore: used `Routes` extender in bundled extensions
* chore: used `PostTypes` extender in bundled extensions
* chore: `yarn format`
* chore: naming
* chore(review): unnecessary check
* chore(review): stay consistent
* chore: unused import

Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
This commit is contained in:
Sami Mazouz
2023-01-17 19:10:24 +01:00
committed by GitHub
parent 5fe3cfd837
commit d7f4975330
30 changed files with 213 additions and 101 deletions

View File

@@ -0,0 +1,4 @@
import Extend from 'flarum/common/extenders';
import FlagsPage from './components/FlagsPage';
export default [new Extend.Routes().add('flags', '/flags', FlagsPage)];

View File

@@ -8,14 +8,14 @@ import addFlagControl from './addFlagControl';
import addFlagsDropdown from './addFlagsDropdown';
import addFlagsToPosts from './addFlagsToPosts';
export { default as extend } from './extend';
app.initializers.add('flarum-flags', () => {
Post.prototype.flags = Model.hasMany<Flag>('flags');
Post.prototype.canFlag = Model.attribute<boolean>('canFlag');
app.store.models.flags = Flag;
app.routes.flags = { path: '/flags', component: FlagsPage };
app.flags = new FlagListState(app);
addFlagControl();

View File

@@ -2,17 +2,15 @@ import { extend } from 'flarum/common/extend';
import app from 'flarum/forum/app';
import UserPage from 'flarum/forum/components/UserPage';
import LinkButton from 'flarum/common/components/LinkButton';
import LikesUserPage from './components/LikesUserPage';
import ItemList from 'flarum/common/utils/ItemList';
import type Mithril from 'mithril';
export default function addLikesTabToUserProfile() {
app.routes['user.likes'] = { path: '/u/:username/likes', component: LikesUserPage };
extend(UserPage.prototype, 'navItems', function (items: ItemList<Mithril.Children>) {
const user = this.user;
items.add(
'likes',
<LinkButton href={app.route('user.likes', { username: user.slug() })} icon="far fa-thumbs-up">
<LinkButton href={app.route('user.likes', { username: user?.slug() })} icon="far fa-thumbs-up">
{app.translator.trans('flarum-likes.forum.user.likes_link')}
</LinkButton>,
88

View File

@@ -0,0 +1,4 @@
import Extend from 'flarum/common/extenders';
import LikesUserPage from './components/LikesUserPage';
export default [new Extend.Routes().add('user.likes', '/u/:username/likes', LikesUserPage)];

View File

@@ -9,6 +9,8 @@ import addLikesList from './addLikesList';
import PostLikedNotification from './components/PostLikedNotification';
import addLikesTabToUserProfile from './addLikesTabToUserProfile';
export { default as extend } from './extend';
app.initializers.add('flarum-likes', () => {
app.notificationComponents.postLiked = PostLikedNotification;

View File

@@ -0,0 +1,20 @@
{
// Use Flarum's tsconfig as a starting point
"extends": "flarum-tsconfig",
// This will match all .ts, .tsx, .d.ts, .js, .jsx files in your `src` folder
// and also tells your Typescript server to read core's global typings for
// access to `dayjs` and `$` in the global namespace.
"include": ["src/**/*", "../../../framework/core/js/dist-typings/@types/**/*", "@types/**/*"],
"compilerOptions": {
// This will output typings to `dist-typings`
"declarationDir": "./dist-typings",
"paths": {
"flarum/*": ["../../../framework/core/js/dist-typings/*"],
// TODO: remove after export registry system implemented
// Without this, the old-style `@flarum/core` import is resolved to
// source code in flarum/core instead of the dist typings.
// This causes an inaccurate "duplicate export" error.
"@flarum/core/*": ["../../../framework/core/js/dist-typings/*"],
}
}
}

View File

@@ -0,0 +1,4 @@
import Extend from 'flarum/common/extenders';
import DiscussionLockedPost from './components/DiscussionLockedPost';
export default [new Extend.PostTypes().add('discussionLocked', DiscussionLockedPost)];

View File

@@ -4,13 +4,13 @@ import Model from 'flarum/common/Model';
import Discussion from 'flarum/common/models/Discussion';
import NotificationGrid from 'flarum/forum/components/NotificationGrid';
import DiscussionLockedPost from './components/DiscussionLockedPost';
import DiscussionLockedNotification from './components/DiscussionLockedNotification';
import addLockBadge from './addLockBadge';
import addLockControl from './addLockControl';
export { default as extend } from './extend';
app.initializers.add('flarum-lock', () => {
app.postComponents.discussionLocked = DiscussionLockedPost;
app.notificationComponents.discussionLocked = DiscussionLockedNotification;
Discussion.prototype.isLocked = Model.attribute('isLocked');

View File

@@ -0,0 +1,20 @@
{
// Use Flarum's tsconfig as a starting point
"extends": "flarum-tsconfig",
// This will match all .ts, .tsx, .d.ts, .js, .jsx files in your `src` folder
// and also tells your Typescript server to read core's global typings for
// access to `dayjs` and `$` in the global namespace.
"include": ["src/**/*", "../../../framework/core/js/dist-typings/@types/**/*", "@types/**/*"],
"compilerOptions": {
// This will output typings to `dist-typings`
"declarationDir": "./dist-typings",
"paths": {
"flarum/*": ["../../../framework/core/js/dist-typings/*"],
// TODO: remove after export registry system implemented
// Without this, the old-style `@flarum/core` import is resolved to
// source code in flarum/core instead of the dist typings.
// This causes an inaccurate "duplicate export" error.
"@flarum/core/*": ["../../../framework/core/js/dist-typings/*"],
}
}
}

View File

@@ -0,0 +1,4 @@
import Extend from 'flarum/common/extenders';
import MentionsUserPage from './components/MentionsUserPage';
export default [new Extend.Routes().add('user.mentions', '/u/:username/mentions', MentionsUserPage)];

View File

@@ -13,10 +13,11 @@ import UserMentionedNotification from './components/UserMentionedNotification';
import GroupMentionedNotification from './components/GroupMentionedNotification';
import UserPage from 'flarum/forum/components/UserPage';
import LinkButton from 'flarum/common/components/LinkButton';
import MentionsUserPage from './components/MentionsUserPage';
import User from 'flarum/common/models/User';
import Model from 'flarum/common/Model';
export { default as extend } from './extend';
app.initializers.add('flarum-mentions', function () {
User.prototype.canMentionGroups = Model.attribute('canMentionGroups');
@@ -65,7 +66,6 @@ app.initializers.add('flarum-mentions', function () {
});
// Add mentions tab in user profile
app.routes['user.mentions'] = { path: '/u/:username/mentions', component: MentionsUserPage };
extend(UserPage.prototype, 'navItems', function (items) {
const user = this.user;
items.add(

View File

@@ -0,0 +1,20 @@
{
// Use Flarum's tsconfig as a starting point
"extends": "flarum-tsconfig",
// This will match all .ts, .tsx, .d.ts, .js, .jsx files in your `src` folder
// and also tells your Typescript server to read core's global typings for
// access to `dayjs` and `$` in the global namespace.
"include": ["src/**/*", "../../../framework/core/js/dist-typings/@types/**/*", "@types/**/*"],
"compilerOptions": {
// This will output typings to `dist-typings`
"declarationDir": "./dist-typings",
"paths": {
"flarum/*": ["../../../framework/core/js/dist-typings/*"],
// TODO: remove after export registry system implemented
// Without this, the old-style `@flarum/core` import is resolved to
// source code in flarum/core instead of the dist typings.
// This causes an inaccurate "duplicate export" error.
"@flarum/core/*": ["../../../framework/core/js/dist-typings/*"],
}
}
}

View File

@@ -0,0 +1,4 @@
import Extend from 'flarum/common/extenders';
import DiscussionStickiedPost from './components/DiscussionStickiedPost';
export default [new Extend.PostTypes().add('discussionStickied', DiscussionStickiedPost)];

View File

@@ -2,15 +2,14 @@ import app from 'flarum/forum/app';
import Model from 'flarum/common/Model';
import Discussion from 'flarum/common/models/Discussion';
import DiscussionStickiedPost from './components/DiscussionStickiedPost';
import addStickyBadge from './addStickyBadge';
import addStickyControl from './addStickyControl';
import addStickyExcerpt from './addStickyExcerpt';
import addStickyClass from './addStickyClass';
app.initializers.add('flarum-sticky', () => {
app.postComponents.discussionStickied = DiscussionStickiedPost;
export { default as extend } from './extend';
app.initializers.add('flarum-sticky', () => {
Discussion.prototype.isSticky = Model.attribute('isSticky');
Discussion.prototype.canSticky = Model.attribute('canSticky');

View File

@@ -0,0 +1,20 @@
{
// Use Flarum's tsconfig as a starting point
"extends": "flarum-tsconfig",
// This will match all .ts, .tsx, .d.ts, .js, .jsx files in your `src` folder
// and also tells your Typescript server to read core's global typings for
// access to `dayjs` and `$` in the global namespace.
"include": ["src/**/*", "../../../framework/core/js/dist-typings/@types/**/*", "@types/**/*"],
"compilerOptions": {
// This will output typings to `dist-typings`
"declarationDir": "./dist-typings",
"paths": {
"flarum/*": ["../../../framework/core/js/dist-typings/*"],
// TODO: remove after export registry system implemented
// Without this, the old-style `@flarum/core` import is resolved to
// source code in flarum/core instead of the dist typings.
// This causes an inaccurate "duplicate export" error.
"@flarum/core/*": ["../../../framework/core/js/dist-typings/*"],
}
}
}

View File

@@ -0,0 +1,4 @@
import Extend from 'flarum/common/extenders';
import IndexPage from 'flarum/forum/components/IndexPage';
export default [new Extend.Routes().add('following', '/following', IndexPage)];

View File

@@ -2,7 +2,6 @@ import { extend } from 'flarum/common/extend';
import app from 'flarum/forum/app';
import Model from 'flarum/common/Model';
import Discussion from 'flarum/common/models/Discussion';
import IndexPage from 'flarum/forum/components/IndexPage';
import NotificationGrid from 'flarum/forum/components/NotificationGrid';
import addSubscriptionBadge from './addSubscriptionBadge';
@@ -12,8 +11,9 @@ import addSubscriptionSettings from './addSubscriptionSettings';
import NewPostNotification from './components/NewPostNotification';
export { default as extend } from './extend';
app.initializers.add('subscriptions', function () {
app.routes.following = { path: '/following', component: IndexPage };
app.notificationComponents.newPost = NewPostNotification;
Discussion.prototype.subscription = Model.attribute('subscription');

View File

@@ -0,0 +1,14 @@
import app from 'flarum/forum/app';
import Extend from 'flarum/common/extenders';
import IndexPage from 'flarum/forum/components/IndexPage';
import DiscussionTaggedPost from './components/DiscussionTaggedPost';
import TagsPage from './components/TagsPage';
export default [
new Extend.Routes()
.add('tags', '/tags', TagsPage)
.add('tag', '/t/:tags', IndexPage)
.helper('tag', (tag) => app.route('tag', { tags: tag.slug() })),
new Extend.PostTypes().add('discussionTagged', DiscussionTaggedPost),
];

View File

@@ -1,12 +1,9 @@
import app from 'flarum/forum/app';
import Model from 'flarum/common/Model';
import Discussion from 'flarum/common/models/Discussion';
import IndexPage from 'flarum/forum/components/IndexPage';
import TagListState from '../common/states/TagListState';
import Tag from '../common/models/Tag';
import TagsPage from './components/TagsPage';
import DiscussionTaggedPost from './components/DiscussionTaggedPost';
import addTagList from './addTagList';
import addTagFilter from './addTagFilter';
@@ -14,14 +11,9 @@ import addTagLabels from './addTagLabels';
import addTagControl from './addTagControl';
import addTagComposer from './addTagComposer';
export { default as extend } from './extend';
app.initializers.add('flarum-tags', function () {
app.routes.tags = { path: '/tags', component: TagsPage };
app.routes.tag = { path: '/t/:tags', component: IndexPage };
app.route.tag = (tag: Tag) => app.route('tag', { tags: tag.slug() });
app.postComponents.discussionTagged = DiscussionTaggedPost;
app.store.models.tags = Tag;
app.tagList = new TagListState();