1
0
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:
Ian Morland
2022-07-14 14:38:31 +01:00
committed by GitHub
parent bf6f63cfe1
commit 3246f5a8f6
6 changed files with 90 additions and 0 deletions

View 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
);
});
}

View 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',
});
}
}

View File

@@ -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', {