فهرست منبع

Modified the code based off the 2nd FB

Shunm634-source 3 سال پیش
والد
کامیت
dd8ff04e3a
1فایلهای تغییر یافته به همراه11 افزوده شده و 6 حذف شده
  1. 11 6
      packages/app/src/stores/ui.tsx

+ 11 - 6
packages/app/src/stores/ui.tsx

@@ -23,6 +23,7 @@ import {
 } from './context';
 } from './context';
 import { localStorageMiddleware } from './middlewares/sync-to-storage';
 import { localStorageMiddleware } from './middlewares/sync-to-storage';
 import { useStaticSWR } from './use-static-swr';
 import { useStaticSWR } from './use-static-swr';
+import { constants } from 'zlib';
 
 
 const { isSharedPage } = pagePathUtils;
 const { isSharedPage } = pagePathUtils;
 
 
@@ -70,21 +71,25 @@ export const useIsMobile = (): SWRResponse<boolean, Error> => {
 };
 };
 
 
 const updateBodyClassesByEditorMode = (newEditorMode: EditorMode, isSidebar = false) => {
 const updateBodyClassesByEditorMode = (newEditorMode: EditorMode, isSidebar = false) => {
+  const bodyElement = document.getElementsByTagName('body')[0];
+  if (bodyElement == null) {
+    logger.warn('The body tag was not successfully obtained');
+  }
   switch (newEditorMode) {
   switch (newEditorMode) {
     case EditorMode.View:
     case EditorMode.View:
-      document.getElementsByTagName('body')[0].classList.remove('on-edit', 'builtin-editor', 'hackmd', 'editing-sidebar');
+      bodyElement.classList.remove('on-edit', 'builtin-editor', 'hackmd', 'editing-sidebar');
       break;
       break;
     case EditorMode.Editor:
     case EditorMode.Editor:
-      document.getElementsByTagName('body')[0].classList.add('on-edit', 'builtin-editor');
-      document.getElementsByTagName('body')[0].classList.remove('hackmd');
+      bodyElement.classList.add('on-edit', 'builtin-editor');
+      bodyElement.classList.remove('hackmd');
       // editing /Sidebar
       // editing /Sidebar
       if (isSidebar) {
       if (isSidebar) {
-        document.getElementsByTagName('body')[0].classList.add('editing-sidebar');
+        bodyElement.classList.add('editing-sidebar');
       }
       }
       break;
       break;
     case EditorMode.HackMD:
     case EditorMode.HackMD:
-      document.getElementsByTagName('body')[0].classList.add('on-edit', 'hackmd');
-      document.getElementsByTagName('body')[0].classList.remove('builtin-editor', 'editing-sidebar');
+      bodyElement.classList.add('on-edit', 'hackmd');
+      bodyElement.classList.remove('builtin-editor', 'editing-sidebar');
       break;
       break;
   }
   }
 };
 };