Skip to content

Commit

Permalink
chore: major frontend JS cleanup (#3609)
Browse files Browse the repository at this point in the history
  • Loading branch information
davwheat authored May 7, 2023
1 parent d8e33e7 commit d4fa864
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
49 changes: 24 additions & 25 deletions js/src/forum/addLikeAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,31 @@ export default function () {

items.add(
'like',
Button.component(
{
className: 'Button Button--link',
onclick: () => {
isLiked = !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;
}
});

if (isLiked) {
data.unshift({ type: 'users', id: app.session.user.id() });
<Button
className="Button Button--link"
onclick={() => {
isLiked = !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;
}
},
},
app.translator.trans(isLiked ? 'flarum-likes.forum.post.unlike_link' : 'flarum-likes.forum.post.like_link')
)
});

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')}
</Button>
);
});
}
2 changes: 1 addition & 1 deletion js/src/forum/addLikesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default function () {
'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', {
{app.translator.trans(`flarum-likes.forum.post.liked_by${likes[0] === app.session.user ? '_self' : ''}_text`, {
count: names.length,
users: punctuateSeries(names),
})}
Expand Down

0 comments on commit d4fa864

Please sign in to comment.