Mao 4 лет назад
Родитель
Сommit
d3c64172bb

+ 2 - 2
packages/app/src/components/LikeButtons.jsx

@@ -62,11 +62,11 @@ class LikeButtons extends React.Component {
         <button
           type="button"
           id="like-button"
-          onClick={() => {
+          onClick={async() => {
             if (onClickInvoked == null) {
               throw Error('onClickInvoked is null');
             }
-            onClickInvoked();
+            await onClickInvoked();
           }}
           className={`btn btn-like border-0
             ${isLiked ? 'active' : ''} ${isGuestUser ? 'disabled' : ''}`}

+ 2 - 1
packages/app/src/components/SearchPage/SearchResultSubNavButton.tsx

@@ -8,6 +8,7 @@ import { withUnstatedContainers } from '../UnstatedUtils';
 import BookmarkButton from '../BookmarkButton';
 import LikeButtons from '../LikeButtons';
 import PageManagement from '../Page/PageManagement';
+import { apiv3Put } from '~/client/util/apiv3-client';
 import { toastError } from '~/client/util/apiNotification';
 
 
@@ -45,7 +46,7 @@ const PageReactionButtons : React.FC<PageReactionButtonsProps> = (props: PageRea
       return;
     }
     try {
-      await appContainer.apiv3Put('/page/likes', { pageId, bool: isLiked });
+      await apiv3Put('/page/likes', { pageId, bool: isLiked });
     }
     catch (err) {
       toastError(err);

+ 2 - 12
packages/app/src/server/models/page.js

@@ -357,10 +357,6 @@ module.exports = function(crowi) {
   pageSchema.methods.like = function(userData) {
     const self = this;
 
-    console.log('printing out self ----------');
-    console.log(JSON.stringify(self));
-    console.log('printing out userData ---------------');
-    console.log(JSON.stringify(userData));
     return new Promise(((resolve, reject) => {
       const added = self.liker.addToSet(userData._id);
       if (added.length > 0) {
@@ -374,19 +370,14 @@ module.exports = function(crowi) {
       }
       else {
         logger.debug('liker not updated');
-        return reject(self);
+        return reject(new Error('already liked'));
       }
     }));
-    // return self;
   };
 
   pageSchema.methods.unlike = function(userData, callback) {
     const self = this;
 
-    console.log('printing out self ----------');
-    console.log(JSON.stringify(self));
-    console.log('printing out userData ---------------');
-    console.log(JSON.stringify(userData));
     return new Promise(((resolve, reject) => {
       const beforeCount = self.liker.length;
       self.liker.pull(userData._id);
@@ -400,10 +391,9 @@ module.exports = function(crowi) {
       }
       else {
         logger.debug('liker not updated');
-        return reject(self);
+        return reject(new Error('already unliked'));
       }
     }));
-    // return self;
   };
 
   pageSchema.methods.isSeenUser = function(userData) {