mirror of
https://github.com/flarum/core.git
synced 2025-08-06 08:27:42 +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:
@@ -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
|
||||
|
4
extensions/likes/js/src/forum/extend.ts
Normal file
4
extensions/likes/js/src/forum/extend.ts
Normal 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)];
|
@@ -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;
|
||||
|
||||
|
20
extensions/likes/js/tsconfig.json
Normal file
20
extensions/likes/js/tsconfig.json
Normal 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/*"],
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user