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')
.registerSetting({
setting: 'flarum-mentions.allow_username_format', setting: 'flarum-mentions.allow_username_format',
type: 'boolean', type: 'boolean',
label: app.translator.trans('flarum-mentions.admin.settings.allow_username_format_label'), label: app.translator.trans('flarum-mentions.admin.settings.allow_username_format_label'),
help: app.translator.trans('flarum-mentions.admin.settings.allow_username_format_text') help: app.translator.trans('flarum-mentions.admin.settings.allow_username_format_text'),
}); });
}); });

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

@ -9,15 +9,19 @@ 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.$()
.show()
.css({
left: left + 'px', left: left + 'px',
top: top + '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
class="Button PostQuoteButton"
onclick={() => {
reply(this.post, this.content); 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,7 +10,7 @@ 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';
@ -42,13 +42,13 @@ app.initializers.add('flarum-mentions', function() {
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'),
}); });
}); });
@ -56,12 +56,16 @@ app.initializers.add('flarum-mentions', function() {
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',
LinkButton.component(
{
href: app.route('user.mentions', { username: user.slug() }), href: app.route('user.mentions', { username: user.slug() }),
name: 'mentions', name: 'mentions',
icon: 'fas fa-at' icon: 'fas fa-at',
}, app.translator.trans('flarum-mentions.forum.user.mentions_link')), },
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());