Bläddra i källkod

Modified the code based off the 2nd FB

Shunm634-source 3 år sedan
förälder
incheckning
dd8ff04e3a
1 ändrade filer med 11 tillägg och 6 borttagningar
  1. 11 6
      packages/app/src/stores/ui.tsx

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

@@ -23,6 +23,7 @@ import {
 } from './context';
 import { localStorageMiddleware } from './middlewares/sync-to-storage';
 import { useStaticSWR } from './use-static-swr';
+import { constants } from 'zlib';
 
 const { isSharedPage } = pagePathUtils;
 
@@ -70,21 +71,25 @@ export const useIsMobile = (): SWRResponse<boolean, Error> => {
 };
 
 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) {
     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;
     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
       if (isSidebar) {
-        document.getElementsByTagName('body')[0].classList.add('editing-sidebar');
+        bodyElement.classList.add('editing-sidebar');
       }
       break;
     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;
   }
 };