From 88218e9aff183d4d2ae073fa22ec1e2cf850c1f1 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 31 Oct 2020 13:07:13 +0100 Subject: [PATCH] Convert `Ui/User/Profile/Menu/Item/Follow` to TypeScript --- .../Ui/User/Profile/Menu/Item/Abstract.js | 3 +- .../Core/Ui/User/Profile/Menu/Item/Follow.js | 51 ++++++++----------- .../Ui/User/Profile/Menu/Item/Abstract.ts | 13 ++--- .../Core/Ui/User/Profile/Menu/Item/Follow.js | 46 ----------------- .../Core/Ui/User/Profile/Menu/Item/Follow.ts | 41 +++++++++++++++ 5 files changed, 71 insertions(+), 83 deletions(-) delete mode 100644 wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Profile/Menu/Item/Follow.js create mode 100644 wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Profile/Menu/Item/Follow.ts diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Profile/Menu/Item/Abstract.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Profile/Menu/Item/Abstract.js index 976d53d1fe..c7b959a751 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Profile/Menu/Item/Abstract.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Profile/Menu/Item/Abstract.js @@ -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!"); } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Profile/Menu/Item/Follow.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Profile/Menu/Item/Follow.js index 33a832cdec..26d801855f 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Profile/Menu/Item/Follow.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Profile/Menu/Item/Follow.js @@ -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; }); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Profile/Menu/Item/Abstract.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Profile/Menu/Item/Abstract.ts index 311c89ede7..5794b55945 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Profile/Menu/Item/Abstract.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Profile/Menu/Item/Abstract.ts @@ -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 index 5238020edc..0000000000 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Profile/Menu/Item/Follow.js +++ /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 index 0000000000..d836cba227 --- /dev/null +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/User/Profile/Menu/Item/Follow.ts @@ -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; -- 2.20.1