Format JS

This commit is contained in:
Ian Morland 2022-01-07 17:31:22 +00:00
parent a4b678ce51
commit 30b2fcce66
7 changed files with 52 additions and 35 deletions

View File

@ -4,7 +4,7 @@ import Discussion from 'flarum/common/models/Discussion';
import Badge from 'flarum/common/components/Badge';
export default function addSubscriptionBadge() {
extend(Discussion.prototype, 'badges', function(badges) {
extend(Discussion.prototype, 'badges', function (badges) {
let badge;
switch (this.subscription()) {
@ -12,7 +12,7 @@ export default function addSubscriptionBadge() {
badge = Badge.component({
label: app.translator.trans('flarum-subscriptions.forum.badge.following_tooltip'),
icon: 'fas fa-star',
type: 'following'
type: 'following',
});
break;
@ -20,12 +20,12 @@ export default function addSubscriptionBadge() {
badge = Badge.component({
label: app.translator.trans('flarum-subscriptions.forum.badge.ignoring_tooltip'),
icon: 'far fa-eye-slash',
type: 'ignoring'
type: 'ignoring',
});
break;
default:
// no default
// no default
}
if (badge) {

View File

@ -7,28 +7,34 @@ import DiscussionControls from 'flarum/forum/utils/DiscussionControls';
import SubscriptionMenu from './components/SubscriptionMenu';
export default function addSubscriptionControls() {
extend(DiscussionControls, 'userControls', function(items, discussion, context) {
extend(DiscussionControls, 'userControls', function (items, discussion, context) {
if (app.session.user && !(context instanceof DiscussionPage)) {
const states = {
none: {label: app.translator.trans('flarum-subscriptions.forum.discussion_controls.follow_button'), icon: 'fas fa-star', save: 'follow'},
follow: {label: app.translator.trans('flarum-subscriptions.forum.discussion_controls.unfollow_button'), icon: 'far fa-star', save: null},
ignore: {label: app.translator.trans('flarum-subscriptions.forum.discussion_controls.unignore_button'), icon: 'fas fa-eye', save: null}
none: { label: app.translator.trans('flarum-subscriptions.forum.discussion_controls.follow_button'), icon: 'fas fa-star', save: 'follow' },
follow: { label: app.translator.trans('flarum-subscriptions.forum.discussion_controls.unfollow_button'), icon: 'far fa-star', save: null },
ignore: { label: app.translator.trans('flarum-subscriptions.forum.discussion_controls.unignore_button'), icon: 'fas fa-eye', save: null },
};
const subscription = discussion.subscription() || 'none';
items.add('subscription', Button.component({
icon: states[subscription].icon,
onclick: discussion.save.bind(discussion, {subscription: states[subscription].save})
}, states[subscription].label));
items.add(
'subscription',
Button.component(
{
icon: states[subscription].icon,
onclick: discussion.save.bind(discussion, { subscription: states[subscription].save }),
},
states[subscription].label
)
);
}
});
extend(DiscussionPage.prototype, 'sidebarItems', function(items) {
extend(DiscussionPage.prototype, 'sidebarItems', function (items) {
if (app.session.user) {
const discussion = this.discussion;
items.add('subscription', SubscriptionMenu.component({discussion}), 80);
items.add('subscription', SubscriptionMenu.component({ discussion }), 80);
}
});
}

View File

@ -6,14 +6,21 @@ import DiscussionListState from 'flarum/forum/states/DiscussionListState';
import GlobalSearchState from 'flarum/forum/states/GlobalSearchState';
export default function addSubscriptionFilter() {
extend(IndexPage.prototype, 'navItems', function(items) {
extend(IndexPage.prototype, 'navItems', function (items) {
if (app.session.user) {
const params = app.search.stickyParams();
items.add('following', LinkButton.component({
href: app.route('following', params),
icon: 'fas fa-star'
}, app.translator.trans('flarum-subscriptions.forum.index.following_link')), 50);
items.add(
'following',
LinkButton.component(
{
href: app.route('following', params),
icon: 'fas fa-star',
},
app.translator.trans('flarum-subscriptions.forum.index.following_link')
),
50
);
}
});

View File

@ -5,19 +5,23 @@ import Switch from 'flarum/common/components/Switch';
export default function () {
extend(SettingsPage.prototype, 'notificationsItems', function (items) {
items.add('followAfterReply',
Switch.component({
state: this.user.preferences().followAfterReply,
onchange: (value) => {
this.followAfterReplyLoading = true;
items.add(
'followAfterReply',
Switch.component(
{
state: this.user.preferences().followAfterReply,
onchange: (value) => {
this.followAfterReplyLoading = true;
this.user.savePreferences({ followAfterReply: value }).then(() => {
this.followAfterReplyLoading = false;
m.redraw();
});
this.user.savePreferences({ followAfterReply: value }).then(() => {
this.followAfterReplyLoading = false;
m.redraw();
});
},
loading: this.followAfterReplyLoading,
},
loading: this.followAfterReplyLoading
}, app.translator.trans('flarum-subscriptions.forum.settings.follow_after_reply_label'))
app.translator.trans('flarum-subscriptions.forum.settings.follow_after_reply_label')
)
);
});
}

View File

@ -15,6 +15,6 @@ export default class NewPostNotification extends Notification {
}
content() {
return app.translator.trans('flarum-subscriptions.forum.notifications.new_post_text', {user: this.attrs.notification.fromUser()});
return app.translator.trans('flarum-subscriptions.forum.notifications.new_post_text', { user: this.attrs.notification.fromUser() });
}
}

View File

@ -5,9 +5,9 @@ export default class SubscriptionMenuItem extends Component {
view() {
return (
<button className="SubscriptionMenuItem hasIcon" onclick={this.attrs.onclick}>
{this.attrs.active ? icon('fas fa-check', {className: 'Button-icon'}) : ''}
{this.attrs.active ? icon('fas fa-check', { className: 'Button-icon' }) : ''}
<span className="SubscriptionMenuItem-label">
{icon(this.attrs.icon, {className: 'Button-icon'})}
{icon(this.attrs.icon, { className: 'Button-icon' })}
<strong>{this.attrs.label}</strong>
<span className="SubscriptionMenuItem-description">{this.attrs.description}</span>
</span>

View File

@ -23,11 +23,11 @@ app.initializers.add('subscriptions', function () {
addSubscriptionFilter();
addSubscriptionSettings();
extend(NotificationGrid.prototype, 'notificationTypes', function(items) {
extend(NotificationGrid.prototype, 'notificationTypes', function (items) {
items.add('newPost', {
name: 'newPost',
icon: 'fas fa-star',
label: app.translator.trans('flarum-subscriptions.forum.settings.notify_new_post_label')
label: app.translator.trans('flarum-subscriptions.forum.settings.notify_new_post_label'),
});
});
});