Ver Fonte

Refactor toggleContentWidth & Set default value to PageModel.isContainerFluid

Taichi Masuyama há 3 anos atrás
pai
commit
08f7ce2c77

+ 1 - 6
packages/app/src/client/services/page-operation.ts

@@ -38,12 +38,7 @@ export const toggleBookmark = async(pageId: string, currentValue?: boolean): Pro
 };
 
 export const toggleContentWidth = async(pageId: string, currentValue: boolean): Promise<void> => {
-  try {
-    await apiv3Put(`/page/${pageId}/content-width`, { isContainerFluid: !currentValue });
-  }
-  catch (err) {
-    toastError(err);
-  }
+  await apiv3Put(`/page/${pageId}/content-width`, { isContainerFluid: !currentValue });
 };
 
 export const bookmark = async(pageId: string): Promise<void> => {

+ 8 - 2
packages/app/src/components/Navbar/SubNavButtons.tsx

@@ -3,6 +3,7 @@ import React, { useCallback } from 'react';
 import {
   toggleBookmark, toggleLike, toggleSubscribe, toggleContentWidth,
 } from '~/client/services/page-operation';
+import { toastError } from '~/client/util/apiNotification';
 import {
   IPageInfoAll, IPageToDeleteWithMeta, IPageToRenameWithMeta, isIPageInfoForEntity, isIPageInfoForOperation,
 } from '~/interfaces/page';
@@ -149,8 +150,13 @@ const SubNavButtonsSubstance = (props: SubNavButtonsSubstanceProps): JSX.Element
     if (!isIPageInfoForOperation(pageInfo)) {
       return;
     }
-    await toggleContentWidth(pageId, pageInfo.isContainerFluid);
-    mutatePageInfo();
+    try {
+      await toggleContentWidth(pageId, pageInfo.isContainerFluid);
+      mutatePageInfo();
+    }
+    catch (err) {
+      toastError(err);
+    }
   }, [isGuestUser, mutatePageInfo, pageId, pageInfo]);
 
   if (!isIPageInfoForOperation(pageInfo)) {

+ 7 - 1
packages/app/src/components/PageList/PageListItemL.tsx

@@ -31,6 +31,7 @@ import { useIsDeviceSmallerThanLg } from '~/stores/ui';
 import { useSWRxPageInfo } from '../../stores/page';
 import { ForceHideMenuItems, PageItemControl } from '../Common/Dropdown/PageItemControl';
 import PagePathHierarchicalLink from '../PagePathHierarchicalLink';
+import { toastError } from '~/client/util/apiNotification';
 
 type Props = {
   page: IPageWithMeta<IPageInfoForEntity> | IPageWithMeta<IPageSearchMeta> | IPageWithMeta<IPageInfoForListing & IPageSearchMeta>,
@@ -125,7 +126,12 @@ const PageListItemLSubstance: ForwardRefRenderFunction<ISelectable, Props> = (pr
   };
 
   const switchContentWidthMenuItemClickHandler = async(_pageId: string, _isContainerFluid: boolean): Promise<void> => {
-    await toggleContentWidth(_pageId, _isContainerFluid);
+    try {
+      await toggleContentWidth(_pageId, _isContainerFluid);
+    }
+    catch (err) {
+      toastError(err);
+    }
   };
 
   const duplicateMenuItemClickHandler = useCallback(() => {

+ 1 - 1
packages/app/src/server/models/page.ts

@@ -102,7 +102,7 @@ const schema = new Schema<PageDocument, PageModel>({
   pageIdOnHackmd: { type: String },
   revisionHackmdSynced: { type: ObjectId, ref: 'Revision' }, // the revision that is synced to HackMD
   hasDraftOnHackmd: { type: Boolean }, // set true if revision and revisionHackmdSynced are same but HackMD document has modified
-  isContainerFluid: { type: Boolean },
+  isContainerFluid: { type: Boolean, default: false },
   updatedAt: { type: Date, default: Date.now }, // Do not use timetamps for updatedAt because it breaks 'updateMetadata: false' option
   deleteUser: { type: ObjectId, ref: 'User' },
   deletedAt: { type: Date },