From 68f42d53b5af1b579505e9ac95a335f2b68b8905 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Fri, 5 Jul 2019 14:29:59 +0200 Subject: [PATCH] Improved reaction filter in user profile tab --- .../templates/userProfileLikes.tpl | 4 +-- .../Core/Ui/Reaction/Profile/Loader.js | 25 +++++++++++-------- .../data/reaction/ReactionAction.class.php | 6 +++-- .../LikesUserProfileMenuContent.class.php | 8 +----- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/com.woltlab.wcf/templates/userProfileLikes.tpl b/com.woltlab.wcf/templates/userProfileLikes.tpl index de8b345ded..260c314460 100644 --- a/com.woltlab.wcf/templates/userProfileLikes.tpl +++ b/com.woltlab.wcf/templates/userProfileLikes.tpl @@ -5,7 +5,7 @@ 'wcf.like.reaction.more': '{lang}wcf.like.reaction.more{/lang}' }); - new UiReactionProfileLoader({@$userID}, {@$firstReactionTypeID}); + new UiReactionProfileLoader({@$userID}); }); @@ -18,7 +18,7 @@ diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/Profile/Loader.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/Profile/Loader.js index e145fba24e..0b74f16ddc 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/Profile/Loader.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/Profile/Loader.js @@ -13,17 +13,17 @@ define(['Ajax', 'Core', 'Language'], function(Ajax, Core, Language) { /** * @constructor */ - function UiReactionProfileLoader(userID, firstReactionTypeID) { this.init(userID, firstReactionTypeID); } + function UiReactionProfileLoader(userID) { this.init(userID); } UiReactionProfileLoader.prototype = { /** * Initializes a new ReactionListLoader object. * * @param integer userID */ - init: function(userID, firstReactionTypeID) { + init: function(userID) { this._container = elById('likeList'); this._userID = userID; - this._reactionTypeID = firstReactionTypeID; + this._reactionTypeID = null; this._targetType = 'received'; this._options = { parameters: [] @@ -33,10 +33,6 @@ define(['Ajax', 'Core', 'Language'], function(Ajax, Core, Language) { throw new Error("[WoltLabSuite/Core/Ui/Reaction/Profile/Loader] Invalid parameter 'userID' given."); } - if (!this._reactionTypeID) { - throw new Error("[WoltLabSuite/Core/Ui/Reaction/Profile/Loader] Invalid parameter 'firstReactionTypeID' given."); - } - var loadButtonList = elCreate('li'); loadButtonList.className = 'likeListMore showMore'; this._noMoreEntries = elCreate('small'); @@ -113,16 +109,23 @@ define(['Ajax', 'Core', 'Language'], function(Ajax, Core, Language) { * @param {int} reactionTypeID */ _changeReactionTypeValue: function(reactionTypeID) { + // remove old active state + var activeButton = elBySel('#reactionType .button.active'); + if (activeButton) { + activeButton.classList.remove('active'); + } + if (this._reactionTypeID !== reactionTypeID) { - // remove old active state - elBySel('#reactionType .button.active').classList.remove('active'); - // add active status to new button elBySel('#reactionType .button[data-reaction-type-id="'+ reactionTypeID +'"]').classList.add('active'); this._reactionTypeID = reactionTypeID; - this._reload(); } + else { + this._reactionTypeID = null; + } + + this._reload(); }, /** diff --git a/wcfsetup/install/files/lib/data/reaction/ReactionAction.class.php b/wcfsetup/install/files/lib/data/reaction/ReactionAction.class.php index 4c5e71aafa..98c91034ce 100644 --- a/wcfsetup/install/files/lib/data/reaction/ReactionAction.class.php +++ b/wcfsetup/install/files/lib/data/reaction/ReactionAction.class.php @@ -215,7 +215,7 @@ class ReactionAction extends AbstractDatabaseObjectAction { $this->readInteger('lastLikeTime', true); $this->readInteger('userID'); - $this->readInteger('reactionTypeID'); + $this->readInteger('reactionTypeID', true); $this->readString('targetType'); $user = UserProfileRuntimeCache::getInstance()->getObject($this->parameters['userID']); @@ -245,7 +245,9 @@ class ReactionAction extends AbstractDatabaseObjectAction { else { $likeList->getConditionBuilder()->add("like_table.userID = ?", [$this->parameters['userID']]); } - $likeList->getConditionBuilder()->add("like_table.reactionTypeID = ?", [$this->parameters['reactionTypeID']]); + if ($this->parameters['reactionTypeID']) { + $likeList->getConditionBuilder()->add("like_table.reactionTypeID = ?", [$this->parameters['reactionTypeID']]); + } $likeList->readObjects(); if (empty($likeList)) { diff --git a/wcfsetup/install/files/lib/system/menu/user/profile/content/LikesUserProfileMenuContent.class.php b/wcfsetup/install/files/lib/system/menu/user/profile/content/LikesUserProfileMenuContent.class.php index 692eb0ae80..3f8597cfaf 100644 --- a/wcfsetup/install/files/lib/system/menu/user/profile/content/LikesUserProfileMenuContent.class.php +++ b/wcfsetup/install/files/lib/system/menu/user/profile/content/LikesUserProfileMenuContent.class.php @@ -1,7 +1,6 @@ getReactionTypes(); - $firstReactionType = reset($reactionTypes); - $likeList = new ViewableLikeList(); $likeList->getConditionBuilder()->add("like_table.objectUserID = ?", [$userID]); - $likeList->getConditionBuilder()->add("like_table.reactionTypeID = ?", [$firstReactionType->reactionTypeID]); $likeList->readObjects(); WCF::getTPL()->assign([ 'likeList' => $likeList, 'userID' => $userID, - 'lastLikeTime' => $likeList->getLastLikeTime(), - 'firstReactionTypeID' => $firstReactionType->reactionTypeID + 'lastLikeTime' => $likeList->getLastLikeTime() ]); return WCF::getTPL()->fetch('userProfileLikes'); -- 2.20.1