chore: format javascript

This commit is contained in:
David Wheatley 2021-11-28 15:56:20 +00:00
parent dc35f048b5
commit 140d6ea221
12 changed files with 55 additions and 50 deletions

View File

@ -1,10 +1,8 @@
app.initializers.add('flarum-mentions', function() { app.initializers.add('flarum-mentions', function () {
app.extensionData app.extensionData.for('flarum-mentions').registerSetting({
.for('flarum-mentions') setting: 'flarum-mentions.allow_username_format',
.registerSetting({ type: 'boolean',
setting: 'flarum-mentions.allow_username_format', label: app.translator.trans('flarum-mentions.admin.settings.allow_username_format_label'),
type: 'boolean', help: app.translator.trans('flarum-mentions.admin.settings.allow_username_format_text'),
label: app.translator.trans('flarum-mentions.admin.settings.allow_username_format_label'), });
help: app.translator.trans('flarum-mentions.admin.settings.allow_username_format_text')
});
}); });

View File

@ -25,7 +25,7 @@ const throttledSearch = throttle(
returnedUsers.push(u); returnedUsers.push(u);
} }
}); });
buildSuggestions(); buildSuggestions();
}); });
searched.push(typedLower); searched.push(typedLower);

View File

@ -5,7 +5,7 @@ import PostQuoteButton from './fragments/PostQuoteButton';
import selectedText from './utils/selectedText'; import selectedText from './utils/selectedText';
export default function addPostQuoteButton() { export default function addPostQuoteButton() {
extend(CommentPost.prototype, 'oncreate', function() { extend(CommentPost.prototype, 'oncreate', function () {
const post = this.attrs.post; const post = this.attrs.post;
if (post.isHidden() || (app.session.user && !post.discussion().canReply())) return; if (post.isHidden() || (app.session.user && !post.discussion().canReply())) return;
@ -18,7 +18,7 @@ export default function addPostQuoteButton() {
const button = new PostQuoteButton(post); const button = new PostQuoteButton(post);
const handler = function(e) { const handler = function (e) {
setTimeout(() => { setTimeout(() => {
const content = selectedText($postBody); const content = selectedText($postBody);
if (content) { if (content) {

View File

@ -6,13 +6,13 @@ import reply from './utils/reply';
export default function () { export default function () {
extend(CommentPost.prototype, 'actionItems', function (items) { extend(CommentPost.prototype, 'actionItems', function (items) {
const post = this.attrs.post; const post = this.attrs.post;
if (post.isHidden() || (app.session.user && !post.discussion().canReply())) return; if (post.isHidden() || (app.session.user && !post.discussion().canReply())) return;
items.add('reply', items.add(
<Button className='Button Button--link' onclick={() => reply(post)}> 'reply',
<Button className="Button Button--link" onclick={() => reply(post)}>
{app.translator.trans('flarum-mentions.forum.post.reply_link')} {app.translator.trans('flarum-mentions.forum.post.reply_link')}
</Button> </Button>
); );

View File

@ -19,5 +19,5 @@ export default {
'mentions/utils/getMentionText': getMentionText, 'mentions/utils/getMentionText': getMentionText,
'mentions/utils/reply': reply, 'mentions/utils/reply': reply,
'mentions/utils/selectedText': selectedText, 'mentions/utils/selectedText': selectedText,
'mentions/utils/textFormatter': textFormatter 'mentions/utils/textFormatter': textFormatter,
}; };

View File

@ -15,10 +15,10 @@ export default class MentionsUserPage extends PostsUserPage {
return app.store.find('posts', { return app.store.find('posts', {
filter: { filter: {
type: 'comment', type: 'comment',
mentioned: this.user.id() mentioned: this.user.id(),
}, },
page: {offset, limit: this.loadLimit}, page: { offset, limit: this.loadLimit },
sort: '-createdAt' sort: '-createdAt',
}); });
} }
} }

View File

@ -18,7 +18,7 @@ export default class PostMentionedNotification extends Notification {
const notification = this.attrs.notification; const notification = this.attrs.notification;
const user = notification.fromUser(); const user = notification.fromUser();
return app.translator.trans('flarum-mentions.forum.notifications.post_mentioned_text', {user, count: 1}); return app.translator.trans('flarum-mentions.forum.notifications.post_mentioned_text', { user, count: 1 });
} }
excerpt() { excerpt() {

View File

@ -15,7 +15,7 @@ export default class UserMentionedNotification extends Notification {
content() { content() {
const user = this.attrs.notification.fromUser(); const user = this.attrs.notification.fromUser();
return app.translator.trans('flarum-mentions.forum.notifications.user_mentioned_text', {user}); return app.translator.trans('flarum-mentions.forum.notifications.user_mentioned_text', { user });
} }
excerpt() { excerpt() {

View File

@ -9,16 +9,20 @@ export default class AutocompleteDropdown extends Fragment {
view() { view() {
return ( return (
<ul className="Dropdown-menu MentionsDropdown"> <ul className="Dropdown-menu MentionsDropdown">
{this.items.map(item => <li>{item}</li>)} {this.items.map((item) => (
<li>{item}</li>
))}
</ul> </ul>
); );
} }
show(left, top) { show(left, top) {
this.$().show().css({ this.$()
left: left + 'px', .show()
top: top + 'px' .css({
}); left: left + 'px',
top: top + 'px',
});
this.active = true; this.active = true;
} }
@ -31,7 +35,7 @@ export default class AutocompleteDropdown extends Fragment {
this.keyWasJustPressed = true; this.keyWasJustPressed = true;
this.setIndex(this.index + delta, true); this.setIndex(this.index + delta, true);
clearTimeout(this.keyWasJustPressedTimeout); clearTimeout(this.keyWasJustPressedTimeout);
this.keyWasJustPressedTimeout = setTimeout(() => this.keyWasJustPressed = false, 500); this.keyWasJustPressedTimeout = setTimeout(() => (this.keyWasJustPressed = false), 500);
} }
complete() { complete() {

View File

@ -12,9 +12,12 @@ export default class PostQuoteButton extends Fragment {
view() { view() {
return ( return (
<button class="Button PostQuoteButton" onclick={() => { <button
reply(this.post, this.content); class="Button PostQuoteButton"
}}> onclick={() => {
reply(this.post, this.content);
}}
>
{icon('fas fa-quote-left', { className: 'Button-icon' })} {icon('fas fa-quote-left', { className: 'Button-icon' })}
{app.translator.trans('flarum-mentions.forum.post.quote_button')} {app.translator.trans('flarum-mentions.forum.post.quote_button')}
</button> </button>
@ -25,10 +28,7 @@ export default class PostQuoteButton extends Fragment {
const $this = this.$().show(); const $this = this.$().show();
const parentOffset = $this.offsetParent().offset(); const parentOffset = $this.offsetParent().offset();
$this $this.css('left', left - parentOffset.left).css('top', top - parentOffset.top);
.css('left', left - parentOffset.left)
.css('top', top - parentOffset.top);
this.hideHandler = this.hide.bind(this); this.hideHandler = this.hide.bind(this);
$(document).on('mouseup', this.hideHandler); $(document).on('mouseup', this.hideHandler);

View File

@ -10,11 +10,11 @@ import addPostQuoteButton from './addPostQuoteButton';
import addComposerAutocomplete from './addComposerAutocomplete'; import addComposerAutocomplete from './addComposerAutocomplete';
import PostMentionedNotification from './components/PostMentionedNotification'; import PostMentionedNotification from './components/PostMentionedNotification';
import UserMentionedNotification from './components/UserMentionedNotification'; import UserMentionedNotification from './components/UserMentionedNotification';
import UserPage from 'flarum/components/UserPage' import UserPage from 'flarum/components/UserPage';
import LinkButton from 'flarum/components/LinkButton'; import LinkButton from 'flarum/components/LinkButton';
import MentionsUserPage from './components/MentionsUserPage'; import MentionsUserPage from './components/MentionsUserPage';
app.initializers.add('flarum-mentions', function() { app.initializers.add('flarum-mentions', function () {
// For every mention of a post inside a post's content, set up a hover handler // For every mention of a post inside a post's content, set up a hover handler
// that shows a preview of the mentioned post. // that shows a preview of the mentioned post.
addPostMentionPreviews(); addPostMentionPreviews();
@ -38,30 +38,34 @@ app.initializers.add('flarum-mentions', function() {
app.notificationComponents.userMentioned = UserMentionedNotification; app.notificationComponents.userMentioned = UserMentionedNotification;
// Add notification preferences. // Add notification preferences.
extend(NotificationGrid.prototype, 'notificationTypes', function(items) { extend(NotificationGrid.prototype, 'notificationTypes', function (items) {
items.add('postMentioned', { items.add('postMentioned', {
name: 'postMentioned', name: 'postMentioned',
icon: 'fas fa-reply', icon: 'fas fa-reply',
label: app.translator.trans('flarum-mentions.forum.settings.notify_post_mentioned_label') label: app.translator.trans('flarum-mentions.forum.settings.notify_post_mentioned_label'),
}); });
items.add('userMentioned', { items.add('userMentioned', {
name: 'userMentioned', name: 'userMentioned',
icon: 'fas fa-at', icon: 'fas fa-at',
label: app.translator.trans('flarum-mentions.forum.settings.notify_user_mentioned_label') label: app.translator.trans('flarum-mentions.forum.settings.notify_user_mentioned_label'),
}); });
}); });
// Add mentions tab in user profile // Add mentions tab in user profile
app.routes['user.mentions'] = {path: '/u/:username/mentions', component: MentionsUserPage}; app.routes['user.mentions'] = { path: '/u/:username/mentions', component: MentionsUserPage };
extend(UserPage.prototype, 'navItems', function(items) { extend(UserPage.prototype, 'navItems', function (items) {
const user = this.user; const user = this.user;
items.add('mentions', items.add(
LinkButton.component({ 'mentions',
href: app.route('user.mentions', {username: user.slug()}), LinkButton.component(
name: 'mentions', {
icon: 'fas fa-at' href: app.route('user.mentions', { username: user.slug() }),
}, app.translator.trans('flarum-mentions.forum.user.mentions_link')), name: 'mentions',
icon: 'fas fa-at',
},
app.translator.trans('flarum-mentions.forum.user.mentions_link')
),
80 80
); );
}); });

View File

@ -6,8 +6,7 @@ export function filterUserMentions(tag) {
if (app.forum.attribute('allowUsernameMentionFormat') && tag.hasAttribute('username')) if (app.forum.attribute('allowUsernameMentionFormat') && tag.hasAttribute('username'))
user = app.store.getBy('users', 'username', tag.getAttribute('username')); user = app.store.getBy('users', 'username', tag.getAttribute('username'));
else if (tag.hasAttribute('id')) else if (tag.hasAttribute('id')) user = app.store.getById('users', tag.getAttribute('id'));
user = app.store.getById('users', tag.getAttribute('id'));
if (user) { if (user) {
tag.setAttribute('id', user.id()); tag.setAttribute('id', user.id());