mirror of
https://github.com/flarum/core.git
synced 2025-08-06 08:27:42 +02:00
feat(likes): Add likes tab to user profile (#3528)
This commit is contained in:
21
extensions/likes/js/src/forum/addLikesTabToUserProfile.tsx
Normal file
21
extensions/likes/js/src/forum/addLikesTabToUserProfile.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
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">
|
||||
{app.translator.trans('flarum-likes.forum.user.likes_link')}
|
||||
</LinkButton>,
|
||||
88
|
||||
);
|
||||
});
|
||||
}
|
24
extensions/likes/js/src/forum/components/LikesUserPage.tsx
Normal file
24
extensions/likes/js/src/forum/components/LikesUserPage.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import app from 'flarum/forum/app';
|
||||
import PostsUserPage from 'flarum/forum/components/PostsUserPage';
|
||||
|
||||
/**
|
||||
* The `LikesUserPage` component shows posts which user the user liked.
|
||||
*/
|
||||
export default class LikesUserPage extends PostsUserPage {
|
||||
/**
|
||||
* Load a new page of the user's activity feed.
|
||||
*
|
||||
* @param offset The position to start getting results from.
|
||||
* @protected
|
||||
*/
|
||||
loadResults(offset: number) {
|
||||
return app.store.find('posts', {
|
||||
filter: {
|
||||
type: 'comment',
|
||||
likedBy: this.user.id(),
|
||||
},
|
||||
page: { offset, limit: this.loadLimit },
|
||||
sort: '-createdAt',
|
||||
});
|
||||
}
|
||||
}
|
@@ -7,6 +7,7 @@ import NotificationGrid from 'flarum/forum/components/NotificationGrid';
|
||||
import addLikeAction from './addLikeAction';
|
||||
import addLikesList from './addLikesList';
|
||||
import PostLikedNotification from './components/PostLikedNotification';
|
||||
import addLikesTabToUserProfile from './addLikesTabToUserProfile';
|
||||
|
||||
app.initializers.add('flarum-likes', () => {
|
||||
app.notificationComponents.postLiked = PostLikedNotification;
|
||||
@@ -16,6 +17,7 @@ app.initializers.add('flarum-likes', () => {
|
||||
|
||||
addLikeAction();
|
||||
addLikesList();
|
||||
addLikesTabToUserProfile();
|
||||
|
||||
extend(NotificationGrid.prototype, 'notificationTypes', function (items) {
|
||||
items.add('postLiked', {
|
||||
|
Reference in New Issue
Block a user