Convert `Ui/User/Profile/Menu/Item/Follow` to TypeScript
authorAlexander Ebert <ebert@woltlab.com>
Sat, 31 Oct 2020 12:07:13 +0000 (13:07 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 31 Oct 2020 12:07:13 +0000 (13:07 +0100)
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Profile/Menu/Item/Abstract.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Profile/Menu/Item/Follow.js
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Profile/Menu/Item/Abstract.ts
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Profile/Menu/Item/Follow.js [deleted file]
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Profile/Menu/Item/Follow.ts [new file with mode: 0644]

index 976d53d1fe1cdcd654bae375ffe340a10ced1c33..c7b959a751a1ce08bbf332cc388dbcd5d3647b5a 100644 (file)
@@ -76,7 +76,8 @@ define(["require", "exports", "tslib", "../../../../../Ajax"], function (require
         /**
          * Handles successful Ajax requests.
          */
-        _ajaxSuccess() {
+        // eslint-disable-next-line @typescript-eslint/no-unused-vars
+        _ajaxSuccess(data) {
             // This should be an abstract method, but cannot be marked as such for backwards compatibility.
             throw new Error("Implement me!");
         }
index 33a832cdecf0c95f23131039296fe308016571d7..26d801855fe4378aa05bb7b35c40545d3eca190f 100644 (file)
@@ -1,39 +1,30 @@
-define(['Core', 'Language', 'Ui/Notification', './Abstract'], function (Core, Language, UiNotification, UiUserProfileMenuItemAbstract) {
+define(["require", "exports", "tslib", "../../../../../Language", "../../../../Notification", "./Abstract"], function (require, exports, tslib_1, Language, UiNotification, Abstract_1) {
     "use strict";
-    if (!COMPILER_TARGET_DEFAULT) {
-        var Fake = function () { };
-        Fake.prototype = {
-            _getLabel: function () { },
-            _getAjaxActionName: function () { },
-            _ajaxSuccess: function () { },
-            _ajaxSetup: function () { },
-            init: function () { },
-            _initButton: function () { },
-            _toggle: function () { },
-            _updateButton: function () { }
-        };
-        return Fake;
-    }
-    function UiUserProfileMenuItemFollow(userId, isActive) { this.init(userId, isActive); }
-    Core.inherit(UiUserProfileMenuItemFollow, UiUserProfileMenuItemAbstract, {
-        _getLabel: function () {
-            return Language.get('wcf.user.button.' + (this._isActive ? 'un' : '') + 'follow');
-        },
-        _getAjaxActionName: function () {
-            return this._isActive ? 'unfollow' : 'follow';
-        },
-        _ajaxSuccess: function (data) {
-            this._isActive = (data.returnValues.following ? true : false);
+    Language = tslib_1.__importStar(Language);
+    UiNotification = tslib_1.__importStar(UiNotification);
+    Abstract_1 = tslib_1.__importDefault(Abstract_1);
+    class UiUserProfileMenuItemFollow extends Abstract_1.default {
+        constructor(userId, isActive) {
+            super(userId, isActive);
+        }
+        _getLabel() {
+            return Language.get("wcf.user.button." + (this._isActive ? "un" : "") + "follow");
+        }
+        _getAjaxActionName() {
+            return this._isActive ? "unfollow" : "follow";
+        }
+        _ajaxSuccess(data) {
+            this._isActive = !!data.returnValues.following;
             this._updateButton();
             UiNotification.show();
-        },
-        _ajaxSetup: function () {
+        }
+        _ajaxSetup() {
             return {
                 data: {
-                    className: 'wcf\\data\\user\\follow\\UserFollowAction'
-                }
+                    className: "wcf\\data\\user\\follow\\UserFollowAction",
+                },
             };
         }
-    });
+    }
     return UiUserProfileMenuItemFollow;
 });
index 311c89ede7c5abf777d45132a8e63c36d7969fee..5794b55945e6664da7f0d40df200eb80faf90d71 100644 (file)
@@ -8,13 +8,13 @@
  */
 
 import * as Ajax from "../../../../../Ajax";
-import { AjaxCallbackObject, RequestOptions } from "../../../../../Ajax/Data";
+import { AjaxCallbackObject, RequestOptions, ResponseData } from "../../../../../Ajax/Data";
 
 abstract class UiUserProfileMenuItemAbstract implements AjaxCallbackObject {
-  readonly _button = document.createElement("a");
-  readonly _isActive: boolean;
-  readonly _listItem = document.createElement("li");
-  readonly _userId: number;
+  protected readonly _button = document.createElement("a");
+  protected _isActive: boolean;
+  protected readonly _listItem = document.createElement("li");
+  protected readonly _userId: number;
 
   /**
    * Creates a new user profile menu item.
@@ -90,7 +90,8 @@ abstract class UiUserProfileMenuItemAbstract implements AjaxCallbackObject {
   /**
    * Handles successful Ajax requests.
    */
-  _ajaxSuccess(): void {
+  // eslint-disable-next-line @typescript-eslint/no-unused-vars
+  _ajaxSuccess(data: ResponseData): void {
     // This should be an abstract method, but cannot be marked as such for backwards compatibility.
 
     throw new Error("Implement me!");
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Profile/Menu/Item/Follow.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Profile/Menu/Item/Follow.js
deleted file mode 100644 (file)
index 5238020..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-define(['Core', 'Language', 'Ui/Notification', './Abstract'], function(Core, Language, UiNotification, UiUserProfileMenuItemAbstract) {
-       "use strict";
-       
-       if (!COMPILER_TARGET_DEFAULT) {
-               var Fake = function() {};
-               Fake.prototype = {
-                       _getLabel: function() {},
-                       _getAjaxActionName: function() {},
-                       _ajaxSuccess: function() {},
-                       _ajaxSetup: function() {},
-                       init: function() {},
-                       _initButton: function() {},
-                       _toggle: function() {},
-                       _updateButton: function() {}
-               };
-               return Fake;
-       }
-       
-       function UiUserProfileMenuItemFollow(userId, isActive) { this.init(userId, isActive); }
-       Core.inherit(UiUserProfileMenuItemFollow, UiUserProfileMenuItemAbstract, {
-               _getLabel: function() {
-                       return Language.get('wcf.user.button.' + (this._isActive ? 'un' : '') + 'follow');
-               },
-               
-               _getAjaxActionName: function() {
-                       return this._isActive ? 'unfollow' : 'follow';
-               },
-               
-               _ajaxSuccess: function(data) {
-                       this._isActive = (data.returnValues.following ? true : false);
-                       this._updateButton();
-                       
-                       UiNotification.show();
-               },
-               
-               _ajaxSetup: function() {
-                       return {
-                               data: {
-                                       className: 'wcf\\data\\user\\follow\\UserFollowAction'
-                               }
-                       };
-               }
-       });
-       
-       return UiUserProfileMenuItemFollow;
-});
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Profile/Menu/Item/Follow.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Profile/Menu/Item/Follow.ts
new file mode 100644 (file)
index 0000000..d836cba
--- /dev/null
@@ -0,0 +1,41 @@
+import * as Language from "../../../../../Language";
+import { RequestOptions, ResponseData } from "../../../../../Ajax/Data";
+import * as UiNotification from "../../../../Notification";
+import UiUserProfileMenuItemAbstract from "./Abstract";
+
+interface AjaxResponse extends ResponseData {
+  returnValues: {
+    following: 1 | 0;
+  };
+}
+
+class UiUserProfileMenuItemFollow extends UiUserProfileMenuItemAbstract {
+  constructor(userId: number, isActive: boolean) {
+    super(userId, isActive);
+  }
+
+  protected _getLabel(): string {
+    return Language.get("wcf.user.button." + (this._isActive ? "un" : "") + "follow");
+  }
+
+  protected _getAjaxActionName(): string {
+    return this._isActive ? "unfollow" : "follow";
+  }
+
+  _ajaxSuccess(data: AjaxResponse): void {
+    this._isActive = !!data.returnValues.following;
+    this._updateButton();
+
+    UiNotification.show();
+  }
+
+  _ajaxSetup(): RequestOptions {
+    return {
+      data: {
+        className: "wcf\\data\\user\\follow\\UserFollowAction",
+      },
+    };
+  }
+}
+
+export = UiUserProfileMenuItemFollow;