itizawa 6 lat temu
rodzic
commit
25db5107e5

+ 3 - 3
src/client/js/components/BookmarkButton.jsx

@@ -34,11 +34,11 @@ class BookmarkButton extends React.Component {
 
   async handleClick() {
     const { appContainer, pageId } = this.props;
-    const { isBookmarked } = this.state;
+    const bool = !this.state.isBookmarked;
 
     try {
-      this.setState({ isBookmarked: !isBookmarked });
-      await appContainer.apiv3.put('/bookmarks', { pageId, isBookmarked });
+      await appContainer.apiv3.put('/bookmarks', { pageId, bool });
+      this.setState({ isBookmarked: bool });
     }
     catch (err) {
       toastError(err);

+ 6 - 6
src/server/routes/apiv3/bookmarks.js

@@ -51,7 +51,7 @@ module.exports = (crowi) => {
   const validator = {
     bookmarks: [
       body('pageId').isString(),
-      body('isBookmarked').isBoolean(),
+      body('bool').isBoolean(),
     ],
   };
   /**
@@ -145,8 +145,8 @@ module.exports = (crowi) => {
    *          500:
    *            $ref: '#/components/responses/500'
    */
-  router.put('/bookmarks', accessTokenParser, loginRequired, csrf, validator.bookmarks, ApiV3FormValidator, async(req, res) => {
-    const { pageId, isBookmarked } = req.body;
+  router.put('/', accessTokenParser, loginRequired, csrf, validator.bookmarks, ApiV3FormValidator, async(req, res) => {
+    const { pageId, bool } = req.body;
 
     let bookmark;
     try {
@@ -154,11 +154,11 @@ module.exports = (crowi) => {
       if (page == null) {
         return res.apiv3Err(`Page '${pageId}' is not found or forbidden`);
       }
-      if (isBookmarked) {
-        bookmark = await Bookmark.removeBookmark(page, req.user);
+      if (bool) {
+        bookmark = await Bookmark.add(page, req.user);
       }
       else {
-        bookmark = await Bookmark.add(page, req.user);
+        bookmark = await Bookmark.removeBookmark(page, req.user);
       }
     }
     catch (err) {