Improved reaction filter in user profile tab
authorMarcel Werk <burntime@woltlab.com>
Fri, 5 Jul 2019 12:29:59 +0000 (14:29 +0200)
committerMarcel Werk <burntime@woltlab.com>
Fri, 5 Jul 2019 12:29:59 +0000 (14:29 +0200)
com.woltlab.wcf/templates/userProfileLikes.tpl
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/Profile/Loader.js
wcfsetup/install/files/lib/data/reaction/ReactionAction.class.php
wcfsetup/install/files/lib/system/menu/user/profile/content/LikesUserProfileMenuContent.class.php

index de8b345ded3044e96d503af816a0c5711edd5892..260c314460e17f87c755e9b8d5284a8b17b7cad3 100644 (file)
@@ -5,7 +5,7 @@
                        'wcf.like.reaction.more': '{lang}wcf.like.reaction.more{/lang}'
                });
                
-               new UiReactionProfileLoader({@$userID}, {@$firstReactionTypeID});
+               new UiReactionProfileLoader({@$userID});
        });
 </script>
 
@@ -18,7 +18,7 @@
                
                <ul class="buttonGroup" id="reactionType">
                        {foreach from=$__wcf->getReactionHandler()->getReactionTypes() item=reactionType name=reactionTypeLoop}
-                               <li><a class="button small jsTooltip{if $tpl.foreach.reactionTypeLoop.first} active{/if}" data-reaction-type-id="{$reactionType->reactionTypeID}" title="{$reactionType->getTitle()}">{@$reactionType->renderIcon()} <span class="invisible">{$reactionType->getTitle()}</span></a></li>
+                               <li><a class="button small jsTooltip" data-reaction-type-id="{$reactionType->reactionTypeID}" title="{$reactionType->getTitle()}">{@$reactionType->renderIcon()} <span class="invisible">{$reactionType->getTitle()}</span></a></li>
                        {/foreach}
                </ul>
        </li>
index e145fba24e8263d358087807c9cecb24deac06cb..0b74f16ddc659ae7f73352246b90689354c81c24 100644 (file)
@@ -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();
                },
                
                /**
index 4c5e71aafa3c94f58b4bf8b9cae9fbfdfe56f4f5..98c91034cea42edf3a24a0a211e8d27c667ce437 100644 (file)
@@ -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)) {
index 692eb0ae80d779f981e424052dd1064367083dfc..3f8597cfaf3b6068dec408d360eac13c313f0297 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 namespace wcf\system\menu\user\profile\content;
 use wcf\data\like\ViewableLikeList;
-use wcf\system\reaction\ReactionHandler;
 use wcf\system\SingletonFactory;
 use wcf\system\WCF;
 
@@ -18,19 +17,14 @@ class LikesUserProfileMenuContent extends SingletonFactory implements IUserProfi
         * @inheritDoc
         */
        public function getContent($userID) {
-               $reactionTypes = ReactionHandler::getInstance()->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');