From b26a9af51fb306cb470a0deaacb15403e30e730f Mon Sep 17 00:00:00 2001
From: Alexander Skvortsov <38059171+askvortsov1@users.noreply.github.com>
Date: Wed, 23 Sep 2020 22:57:08 -0400
Subject: [PATCH] Mithril 2 Update (#27)
Update for Mithril 2
---
.../src/forum/components/SuspendUserModal.js | 28 ++++++++++---------
.../components/UserSuspendedNotification.js | 4 +--
.../components/UserUnsuspendedNotification.js | 4 +--
extensions/suspend/js/src/forum/index.js | 3 +-
4 files changed, 20 insertions(+), 19 deletions(-)
diff --git a/extensions/suspend/js/src/forum/components/SuspendUserModal.js b/extensions/suspend/js/src/forum/components/SuspendUserModal.js
index 8f724e009..e5985dd2d 100644
--- a/extensions/suspend/js/src/forum/components/SuspendUserModal.js
+++ b/extensions/suspend/js/src/forum/components/SuspendUserModal.js
@@ -1,11 +1,13 @@
import Modal from 'flarum/components/Modal';
import Button from 'flarum/components/Button';
-export default class SuspendUserModal extends Modal {
- init() {
- super.init();
+import withAttr from 'flarum/utils/withAttr';
- let until = this.props.user.suspendedUntil();
+export default class SuspendUserModal extends Modal {
+ oninit(vnode) {
+ super.oninit(vnode);
+
+ let until = this.attrs.user.suspendedUntil();
let status = null;
if (new Date() > until) until = null;
@@ -15,8 +17,8 @@ export default class SuspendUserModal extends Modal {
else status = 'limited';
}
- this.status = m.prop(status);
- this.daysRemaining = m.prop(status === 'limited' && -dayjs().diff(until, 'days') + 1);
+ this.status = m.stream(status);
+ this.daysRemaining = m.stream(status === 'limited' && -dayjs().diff(until, 'days') + 1);
}
className() {
@@ -24,7 +26,7 @@ export default class SuspendUserModal extends Modal {
}
title() {
- return app.translator.trans('flarum-suspend.forum.suspend_user.title', {user: this.props.user});
+ return app.translator.trans('flarum-suspend.forum.suspend_user.title', {user: this.attrs.user});
}
content() {
@@ -35,21 +37,21 @@ export default class SuspendUserModal extends Modal {
@@ -95,7 +97,7 @@ export default class SuspendUserModal extends Modal {
// no default
}
- this.props.user.save({suspendedUntil}).then(
+ this.attrs.user.save({suspendedUntil}).then(
() => this.hide(),
this.loaded.bind(this)
);
diff --git a/extensions/suspend/js/src/forum/components/UserSuspendedNotification.js b/extensions/suspend/js/src/forum/components/UserSuspendedNotification.js
index 8e7114327..bce05ba18 100644
--- a/extensions/suspend/js/src/forum/components/UserSuspendedNotification.js
+++ b/extensions/suspend/js/src/forum/components/UserSuspendedNotification.js
@@ -6,11 +6,11 @@ export default class UserSuspendedNotification extends Notification {
}
href() {
- return app.route.user(this.props.notification.subject());
+ return app.route.user(this.attrs.notification.subject());
}
content() {
- const notification = this.props.notification;
+ const notification = this.attrs.notification;
const suspendedUntil = notification.content();
const timeReadable = dayjs(suspendedUntil.date).from(notification.createdAt(), true);
diff --git a/extensions/suspend/js/src/forum/components/UserUnsuspendedNotification.js b/extensions/suspend/js/src/forum/components/UserUnsuspendedNotification.js
index 55ab43b16..d6fc5c62d 100644
--- a/extensions/suspend/js/src/forum/components/UserUnsuspendedNotification.js
+++ b/extensions/suspend/js/src/forum/components/UserUnsuspendedNotification.js
@@ -6,11 +6,11 @@ export default class UserUnsuspendedNotification extends Notification {
}
href() {
- return app.route.user(this.props.notification.subject());
+ return app.route.user(this.attrs.notification.subject());
}
content() {
- const notification = this.props.notification;
+ const notification = this.attrs.notification;
return app.translator.trans('flarum-suspend.forum.notifications.user_unsuspended_text', {
user: notification.fromUser(),
diff --git a/extensions/suspend/js/src/forum/index.js b/extensions/suspend/js/src/forum/index.js
index 0e6717047..a73f3fffe 100644
--- a/extensions/suspend/js/src/forum/index.js
+++ b/extensions/suspend/js/src/forum/index.js
@@ -20,10 +20,9 @@ app.initializers.add('flarum-suspend', () => {
extend(UserControls, 'moderationControls', (items, user) => {
if (user.canSuspend()) {
items.add('suspend', Button.component({
- children: app.translator.trans('flarum-suspend.forum.user_controls.suspend_button'),
icon: 'fas fa-ban',
onclick: () => app.modal.show(SuspendUserModal, {user})
- }));
+ }, app.translator.trans('flarum-suspend.forum.user_controls.suspend_button')));
}
});