mirror of
https://github.com/flarum/core.git
synced 2025-08-12 19:34:18 +02:00
@@ -1,13 +0,0 @@
|
||||
import { extend } from 'flarum/extend';
|
||||
import app from 'flarum/app';
|
||||
import PermissionGrid from 'flarum/components/PermissionGrid';
|
||||
|
||||
app.initializers.add('flarum-likes', () => {
|
||||
app.extensionData
|
||||
.for('flarum-likes')
|
||||
.registerPermission({
|
||||
icon: 'far fa-thumbs-up',
|
||||
label: app.translator.trans('flarum-likes.admin.permissions.like_posts_label'),
|
||||
permission: 'discussion.likePosts'
|
||||
}, 'reply');
|
||||
});
|
12
extensions/likes/js/src/admin/index.ts
Normal file
12
extensions/likes/js/src/admin/index.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import app from 'flarum/admin/app';
|
||||
|
||||
app.initializers.add('flarum-likes', () => {
|
||||
app.extensionData.for('flarum-likes').registerPermission(
|
||||
{
|
||||
icon: 'far fa-thumbs-up',
|
||||
label: app.translator.trans('flarum-likes.admin.permissions.like_posts_label'),
|
||||
permission: 'discussion.likePosts',
|
||||
},
|
||||
'reply'
|
||||
);
|
||||
});
|
@@ -1,42 +1,46 @@
|
||||
import { extend } from 'flarum/extend';
|
||||
import app from 'flarum/app';
|
||||
import Button from 'flarum/components/Button';
|
||||
import CommentPost from 'flarum/components/CommentPost';
|
||||
import { extend } from 'flarum/common/extend';
|
||||
import app from 'flarum/forum/app';
|
||||
import Button from 'flarum/common/components/Button';
|
||||
import CommentPost from 'flarum/forum/components/CommentPost';
|
||||
|
||||
export default function() {
|
||||
extend(CommentPost.prototype, 'actionItems', function(items) {
|
||||
export default function () {
|
||||
extend(CommentPost.prototype, 'actionItems', function (items) {
|
||||
const post = this.attrs.post;
|
||||
|
||||
if (post.isHidden() || !post.canLike()) return;
|
||||
|
||||
const likes = post.likes();
|
||||
|
||||
let isLiked = app.session.user && likes && likes.some(user => user === app.session.user);
|
||||
let isLiked = app.session.user && likes && likes.some((user) => user === app.session.user);
|
||||
|
||||
items.add('like',
|
||||
Button.component({
|
||||
className: 'Button Button--link',
|
||||
onclick: () => {
|
||||
isLiked = !isLiked;
|
||||
items.add(
|
||||
'like',
|
||||
Button.component(
|
||||
{
|
||||
className: 'Button Button--link',
|
||||
onclick: () => {
|
||||
isLiked = !isLiked;
|
||||
|
||||
post.save({isLiked});
|
||||
post.save({ isLiked });
|
||||
|
||||
// We've saved the fact that we do or don't like the post, but in order
|
||||
// to provide instantaneous feedback to the user, we'll need to add or
|
||||
// remove the like from the relationship data manually.
|
||||
const data = post.data.relationships.likes.data;
|
||||
data.some((like, i) => {
|
||||
if (like.id === app.session.user.id()) {
|
||||
data.splice(i, 1);
|
||||
return true;
|
||||
// We've saved the fact that we do or don't like the post, but in order
|
||||
// to provide instantaneous feedback to the user, we'll need to add or
|
||||
// remove the like from the relationship data manually.
|
||||
const data = post.data.relationships.likes.data;
|
||||
data.some((like, i) => {
|
||||
if (like.id === app.session.user.id()) {
|
||||
data.splice(i, 1);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (isLiked) {
|
||||
data.unshift({ type: 'users', id: app.session.user.id() });
|
||||
}
|
||||
});
|
||||
|
||||
if (isLiked) {
|
||||
data.unshift({type: 'users', id: app.session.user.id()});
|
||||
}
|
||||
}
|
||||
}, app.translator.trans(isLiked ? 'flarum-likes.forum.post.unlike_link' : 'flarum-likes.forum.post.like_link'))
|
||||
},
|
||||
},
|
||||
app.translator.trans(isLiked ? 'flarum-likes.forum.post.unlike_link' : 'flarum-likes.forum.post.like_link')
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
@@ -1,15 +1,15 @@
|
||||
import { extend } from 'flarum/extend';
|
||||
import app from 'flarum/app';
|
||||
import CommentPost from 'flarum/components/CommentPost';
|
||||
import Link from 'flarum/components/Link';
|
||||
import punctuateSeries from 'flarum/helpers/punctuateSeries';
|
||||
import username from 'flarum/helpers/username';
|
||||
import icon from 'flarum/helpers/icon';
|
||||
import { extend } from 'flarum/common/extend';
|
||||
import app from 'flarum/forum/app';
|
||||
import CommentPost from 'flarum/forum/components/CommentPost';
|
||||
import Link from 'flarum/common/components/Link';
|
||||
import punctuateSeries from 'flarum/common/helpers/punctuateSeries';
|
||||
import username from 'flarum/common/helpers/username';
|
||||
import icon from 'flarum/common/helpers/icon';
|
||||
|
||||
import PostLikesModal from './components/PostLikesModal';
|
||||
|
||||
export default function() {
|
||||
extend(CommentPost.prototype, 'footerItems', function(items) {
|
||||
export default function () {
|
||||
extend(CommentPost.prototype, 'footerItems', function (items) {
|
||||
const post = this.attrs.post;
|
||||
const likes = post.likes();
|
||||
|
||||
@@ -19,9 +19,10 @@ export default function() {
|
||||
|
||||
// Construct a list of names of users who have liked this post. Make sure the
|
||||
// current user is first in the list, and cap a maximum of 4 items.
|
||||
const names = likes.sort(a => a === app.session.user ? -1 : 1)
|
||||
const names = likes
|
||||
.sort((a) => (a === app.session.user ? -1 : 1))
|
||||
.slice(0, overLimit ? limit - 1 : limit)
|
||||
.map(user => {
|
||||
.map((user) => {
|
||||
return (
|
||||
<Link href={app.route.user(user)}>
|
||||
{user === app.session.user ? app.translator.trans('flarum-likes.forum.post.you_text') : username(user)}
|
||||
@@ -36,24 +37,28 @@ export default function() {
|
||||
const count = likes.length - names.length;
|
||||
|
||||
names.push(
|
||||
<a href="#" onclick={e => {
|
||||
e.preventDefault();
|
||||
app.modal.show(PostLikesModal, {post});
|
||||
}}>
|
||||
{app.translator.trans('flarum-likes.forum.post.others_link', {count})}
|
||||
<a
|
||||
href="#"
|
||||
onclick={(e) => {
|
||||
e.preventDefault();
|
||||
app.modal.show(PostLikesModal, { post });
|
||||
}}
|
||||
>
|
||||
{app.translator.trans('flarum-likes.forum.post.others_link', { count })}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
items.add('liked', (
|
||||
items.add(
|
||||
'liked',
|
||||
<div className="Post-likedBy">
|
||||
{icon('far fa-thumbs-up')}
|
||||
{app.translator.trans('flarum-likes.forum.post.liked_by' + (likes[0] === app.session.user ? '_self' : '') + '_text', {
|
||||
count: names.length,
|
||||
users: punctuateSeries(names)
|
||||
users: punctuateSeries(names),
|
||||
})}
|
||||
</div>
|
||||
));
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import Notification from 'flarum/components/Notification';
|
||||
import { truncate } from 'flarum/utils/string';
|
||||
import app from 'flarum/forum/app';
|
||||
import Notification from 'flarum/forum/components/Notification';
|
||||
import { truncate } from 'flarum/common/utils/string';
|
||||
|
||||
export default class PostLikedNotification extends Notification {
|
||||
icon() {
|
||||
@@ -14,7 +15,7 @@ export default class PostLikedNotification extends Notification {
|
||||
const notification = this.attrs.notification;
|
||||
const user = notification.fromUser();
|
||||
|
||||
return app.translator.trans('flarum-likes.forum.notifications.post_liked_text', {user, count: 1});
|
||||
return app.translator.trans('flarum-likes.forum.notifications.post_liked_text', { user, count: 1 });
|
||||
}
|
||||
|
||||
excerpt() {
|
||||
|
@@ -1,7 +1,8 @@
|
||||
import Modal from 'flarum/components/Modal';
|
||||
import Link from 'flarum/components/Link';
|
||||
import avatar from 'flarum/helpers/avatar';
|
||||
import username from 'flarum/helpers/username';
|
||||
import app from 'flarum/forum/app';
|
||||
import Modal from 'flarum/common/components/Modal';
|
||||
import Link from 'flarum/common/components/Link';
|
||||
import avatar from 'flarum/common/helpers/avatar';
|
||||
import username from 'flarum/common/helpers/username';
|
||||
|
||||
export default class PostLikesModal extends Modal {
|
||||
className() {
|
||||
@@ -16,11 +17,10 @@ export default class PostLikesModal extends Modal {
|
||||
return (
|
||||
<div className="Modal-body">
|
||||
<ul className="PostLikesModal-list">
|
||||
{this.attrs.post.likes().map(user => (
|
||||
{this.attrs.post.likes().map((user) => (
|
||||
<li>
|
||||
<Link href={app.route.user(user)}>
|
||||
{avatar(user)} {' '}
|
||||
{username(user)}
|
||||
{avatar(user)} {username(user)}
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import { extend } from 'flarum/extend';
|
||||
import app from 'flarum/app';
|
||||
import Post from 'flarum/models/Post';
|
||||
import Model from 'flarum/Model';
|
||||
import NotificationGrid from 'flarum/components/NotificationGrid';
|
||||
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';
|
||||
import addLikesList from './addLikesList';
|
||||
@@ -21,7 +21,7 @@ app.initializers.add('flarum-likes', () => {
|
||||
items.add('postLiked', {
|
||||
name: 'postLiked',
|
||||
icon: 'far fa-thumbs-up',
|
||||
label: app.translator.trans('flarum-likes.forum.settings.notify_post_liked_label')
|
||||
label: app.translator.trans('flarum-likes.forum.settings.notify_post_liked_label'),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user