Explorar o código

fix biome errors

Yuki Takei hai 6 meses
pai
achega
623dbcf4be

+ 19 - 19
apps/app/src/features/page-bulk-export/client/components/PageBulkExportSelectModal.tsx

@@ -27,22 +27,25 @@ const PageBulkExportSelectModalSubstance = (): JSX.Element => {
     { createdAt: string } | undefined
   >(undefined);
 
-  const startBulkExport = useCallback(async (format: PageBulkExportFormat) => {
-    try {
-      setFormatMemoForRestart(format);
-      await apiv3Post('/page-bulk-export', { path: currentPagePath, format });
-      toastSuccess(t('page_export.bulk_export_started'));
-    } catch (e) {
-      const errorCode = e?.[0].code ?? 'page_export.failed_to_export';
-      if (errorCode === 'page_export.duplicate_bulk_export_job_error') {
-        setDuplicateJobInfo(e[0].args.duplicateJob);
-        setIsRestartModalOpened(true);
-      } else {
-        toastError(t(errorCode));
+  const startBulkExport = useCallback(
+    async (format: PageBulkExportFormat) => {
+      try {
+        setFormatMemoForRestart(format);
+        await apiv3Post('/page-bulk-export', { path: currentPagePath, format });
+        toastSuccess(t('page_export.bulk_export_started'));
+      } catch (e) {
+        const errorCode = e?.[0].code ?? 'page_export.failed_to_export';
+        if (errorCode === 'page_export.duplicate_bulk_export_job_error') {
+          setDuplicateJobInfo(e[0].args.duplicateJob);
+          setIsRestartModalOpened(true);
+        } else {
+          toastError(t(errorCode));
+        }
       }
-    }
-    close();
-  }, [close, currentPagePath, t]);
+      close();
+    },
+    [close, currentPagePath, t],
+  );
 
   const restartBulkExport = useCallback(async () => {
     if (formatMemoForRestart != null) {
@@ -116,10 +119,7 @@ const PageBulkExportSelectModalSubstance = (): JSX.Element => {
         </div>
       </ModalBody>
 
-      <Modal
-        isOpen={isRestartModalOpened}
-        toggle={handleCloseRestartModal}
-      >
+      <Modal isOpen={isRestartModalOpened} toggle={handleCloseRestartModal}>
         <ModalHeader tag="h4" toggle={handleCloseRestartModal}>
           {t('page_export.export_in_progress')}
         </ModalHeader>

+ 11 - 12
apps/app/src/features/search/client/components/SearchModal.tsx

@@ -76,21 +76,22 @@ const SearchModalSubstance = (): JSX.Element => {
   }, [searchKeyword]);
 
   // Memoize AI mention removal to prevent recalculation on every render
-  const searchKeywordWithoutAi = useMemo(() =>
-    removeAiMenthion(searchKeyword),
-    [searchKeyword]
+  const searchKeywordWithoutAi = useMemo(
+    () => removeAiMenthion(searchKeyword),
+    [searchKeyword],
   );
 
   // Memoize icon selection to prevent recalculation
-  const searchIcon = useMemo(() =>
-    isMenthionedToAi ? 'psychology' : 'search',
-    [isMenthionedToAi]
+  const searchIcon = useMemo(
+    () => (isMenthionedToAi ? 'psychology' : 'search'),
+    [isMenthionedToAi],
   );
 
   // Memoize icon class to prevent string concatenation on every render
-  const iconClassName = useMemo(() =>
-    `material-symbols-outlined fs-4 me-3 ${isMenthionedToAi ? 'text-primary' : ''}`,
-    [isMenthionedToAi]
+  const iconClassName = useMemo(
+    () =>
+      `material-symbols-outlined fs-4 me-3 ${isMenthionedToAi ? 'text-primary' : ''}`,
+    [isMenthionedToAi],
   );
 
   return (
@@ -109,9 +110,7 @@ const SearchModalSubstance = (): JSX.Element => {
         }) => (
           <div {...getRootProps({}, { suppressRefError: true })}>
             <div className="text-muted d-flex justify-content-center align-items-center p-1">
-              <span className={iconClassName}>
-                {searchIcon}
-              </span>
+              <span className={iconClassName}>{searchIcon}</span>
               <SearchForm
                 searchKeyword={searchKeyword}
                 onChange={changeSearchTextHandler}

+ 1 - 1
apps/app/src/states/page/index.ts

@@ -5,8 +5,8 @@
  * hiding internal implementation details while exposing only the necessary hooks.
  */
 
-export { _atomsForDerivedAbilities } from './internal-atoms';
 export * from './hooks';
+export { _atomsForDerivedAbilities } from './internal-atoms';
 export { useCurrentPageLoading } from './use-current-page-loading';
 // Data fetching hooks
 export { useFetchCurrentPage } from './use-fetch-current-page';

+ 1 - 1
apps/app/src/states/page/internal-atoms.ts

@@ -58,7 +58,7 @@ export const isUntitledPageAtom = atom(
     if (currentPageId != null) {
       set(untitledPageStateAtom, newValue);
     }
-  }
+  },
 );
 
 // Remote revision data atoms (migrated from useSWRStatic)

+ 6 - 5
apps/app/src/states/ui/device.ts

@@ -84,18 +84,19 @@ export const useIsMobile = () => {
   useEffect(() => {
     // Ref: https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent#mobile_device_detection
     let hasTouchScreen = false;
-    hasTouchScreen = ('maxTouchPoints' in navigator) ? navigator?.maxTouchPoints > 0 : false;
+    hasTouchScreen =
+      'maxTouchPoints' in navigator ? navigator?.maxTouchPoints > 0 : false;
 
     if (!hasTouchScreen) {
       const mQ = matchMedia?.('(pointer:coarse)');
       if (mQ?.media === '(pointer:coarse)') {
         hasTouchScreen = !!mQ.matches;
-      }
-      else {
+      } else {
         // Only as a last resort, fall back to user agent sniffing
         const UA = navigator.userAgent;
-        hasTouchScreen = /\b(BlackBerry|webOS|iPhone|IEMobile)\b/i.test(UA)
-          || /\b(Android|Windows Phone|iPad|iPod)\b/i.test(UA);
+        hasTouchScreen =
+          /\b(BlackBerry|webOS|iPhone|IEMobile)\b/i.test(UA) ||
+          /\b(Android|Windows Phone|iPad|iPod)\b/i.test(UA);
       }
     }
 

+ 5 - 1
apps/app/src/states/ui/editor/index.ts

@@ -1,6 +1,10 @@
 // Export only the essential public API
 
-export { editingMarkdownAtom, selectedGrantAtom, _atomsForDerivedAbilities } from './atoms';
+export {
+  _atomsForDerivedAbilities,
+  editingMarkdownAtom,
+  selectedGrantAtom,
+} from './atoms';
 export {
   useEditingMarkdown,
   useEditorMode,

+ 4 - 3
apps/app/src/states/ui/editor/types.ts

@@ -2,16 +2,17 @@ export const EditorMode = {
   View: 'view',
   Editor: 'editor',
 } as const;
-export type EditorMode = typeof EditorMode[keyof typeof EditorMode];
+export type EditorMode = (typeof EditorMode)[keyof typeof EditorMode];
 
 export const EditorModeHash = {
   View: '',
   Edit: '#edit',
 } as const;
-export type EditorModeHash = typeof EditorModeHash[keyof typeof EditorModeHash];
+export type EditorModeHash =
+  (typeof EditorModeHash)[keyof typeof EditorModeHash];
 
 export type UseEditorModeReturn = {
   editorMode: EditorMode;
   setEditorMode: (mode: EditorMode) => void;
   getClassNamesByEditorMode: () => string[];
-}
+};

+ 9 - 7
apps/app/src/states/ui/modal/page-status-alert.ts

@@ -1,12 +1,11 @@
-import { useCallback } from 'react';
-
 import { atom, useAtomValue, useSetAtom } from 'jotai';
+import { useCallback } from 'react';
 
 import type { EditorMode } from '../editor';
 
 /*
-* PageStatusAlert
-*/
+ * PageStatusAlert
+ */
 type OpenPageStatusAlertOptions = {
   hideEditorMode?: EditorMode;
   onRefleshPage?: () => void;
@@ -39,9 +38,12 @@ export const usePageStatusAlertStatus = (): PageStatusAlertStatus => {
 export const usePageStatusAlertActions = (): PageStatusAlertActions => {
   const setStatus = useSetAtom(pageStatusAlertAtom);
 
-  const open = useCallback((options: OpenPageStatusAlertOptions) => {
-    setStatus({ isOpen: true, ...options });
-  }, [setStatus]);
+  const open = useCallback(
+    (options: OpenPageStatusAlertOptions) => {
+      setStatus({ isOpen: true, ...options });
+    },
+    [setStatus],
+  );
 
   const close = useCallback(() => {
     setStatus({ isOpen: false });

+ 48 - 21
apps/app/src/states/ui/page-abilities.ts

@@ -1,17 +1,22 @@
 import { pagePathUtils } from '@growi/core/dist/utils';
 import { atom, useAtomValue } from 'jotai';
-
-import { EditorMode } from '~/states/ui/editor';
-import { useIsSharedUser } from '~/states/context';
 import {
-  useIsEditable, usePageNotFound, useCurrentPagePath, useCurrentPageId,
-} from '~/states/page';
-
-// Import internal atoms with special naming
-import { _atomsForDerivedAbilities as pageAtoms } from '~/states/page';
-import { _atomsForDerivedAbilities as editorAtoms } from '~/states/ui/editor';
+  _atomsForDerivedAbilities as contextAtoms,
+  useIsSharedUser,
+} from '~/states/context';
 import { _atomsForDerivedAbilities as globalAtoms } from '~/states/global';
-import { _atomsForDerivedAbilities as contextAtoms } from '~/states/context';
+// Import internal atoms with special naming
+import {
+  _atomsForDerivedAbilities as pageAtoms,
+  useCurrentPageId,
+  useCurrentPagePath,
+  useIsEditable,
+  usePageNotFound,
+} from '~/states/page';
+import {
+  EditorMode,
+  _atomsForDerivedAbilities as editorAtoms,
+} from '~/states/ui/editor';
 
 const { isTrashTopPage, isUsersTopPage } = pagePathUtils;
 
@@ -24,15 +29,24 @@ const isAbleToShowTagLabelAtom = atom((get) => {
   const editorMode = get(editorAtoms.editorModeAtom);
 
   // Return false if any dependency is undefined
-  if ([currentPagePath, isIdenticalPath, isNotFound, editorMode].some(v => v === undefined)) {
+  if (
+    [currentPagePath, isIdenticalPath, isNotFound, editorMode].some(
+      (v) => v === undefined,
+    )
+  ) {
     return false;
   }
 
   const isViewMode = editorMode === EditorMode.View;
 
   // "/trash" page does not exist on page collection and unable to add tags
-  return !isUsersTopPage(currentPagePath!) && !isTrashTopPage(currentPagePath!)
-    && shareLinkId == null && !isIdenticalPath && !(isViewMode && isNotFound);
+  return (
+    !isUsersTopPage(currentPagePath!) &&
+    !isTrashTopPage(currentPagePath!) &&
+    shareLinkId == null &&
+    !isIdenticalPath &&
+    !(isViewMode && isNotFound)
+  );
 });
 
 /**
@@ -51,7 +65,11 @@ const isAbleToShowTrashPageManagementButtonsAtom = atom((get) => {
   const isReadOnlyUser = get(contextAtoms.isReadOnlyUserAtom);
 
   // Return false if any dependency is undefined
-  if ([currentUser, currentPageId, isNotFound, isReadOnlyUser, isTrashPage].some(v => v === undefined)) {
+  if (
+    [currentUser, currentPageId, isNotFound, isReadOnlyUser, isTrashPage].some(
+      (v) => v === undefined,
+    )
+  ) {
     return false;
   }
 
@@ -80,16 +98,21 @@ const isAbleToShowPageManagementAtom = atom((get) => {
   const pageId = currentPageId;
 
   // Return false if any dependency is undefined
-  if ([pageId, isTrashPage, isSharedUser, isNotFound].some(v => v === undefined)) {
+  if (
+    [pageId, isTrashPage, isSharedUser, isNotFound].some((v) => v === undefined)
+  ) {
     return false;
   }
 
-  const isPageExist = (pageId != null) && isNotFound === false;
-  const isEmptyPage = (pageId != null) && isNotFound === true;
+  const isPageExist = pageId != null && isNotFound === false;
+  const isEmptyPage = pageId != null && isNotFound === true;
   const isTrashPageCondition = isPageExist && isTrashPage === true;
   const isSharedUserCondition = isPageExist && isSharedUser === true;
 
-  return (isPageExist && !isTrashPageCondition && !isSharedUserCondition) || isEmptyPage;
+  return (
+    (isPageExist && !isTrashPageCondition && !isSharedUserCondition) ||
+    isEmptyPage
+  );
 });
 
 /**
@@ -106,7 +129,9 @@ export const useIsAbleToChangeEditorMode = (): boolean => {
   const isEditable = useIsEditable();
   const isSharedUser = useIsSharedUser();
 
-  const includesUndefined = [isEditable, isSharedUser].some(v => v === undefined);
+  const includesUndefined = [isEditable, isSharedUser].some(
+    (v) => v === undefined,
+  );
   if (includesUndefined) return false;
 
   return !!isEditable && !isSharedUser;
@@ -120,10 +145,12 @@ export const useIsAbleToShowPageAuthors = (): boolean => {
   const isNotFound = usePageNotFound();
   const pagePath = useCurrentPagePath();
 
-  const includesUndefined = [pageId, pagePath, isNotFound].some(v => v === undefined);
+  const includesUndefined = [pageId, pagePath, isNotFound].some(
+    (v) => v === undefined,
+  );
   if (includesUndefined) return false;
 
-  const isPageExist = (pageId != null) && !isNotFound;
+  const isPageExist = pageId != null && !isNotFound;
   const isUsersTopPagePath = pagePath != null && isUsersTopPage(pagePath);
 
   return isPageExist && !isUsersTopPagePath;

+ 22 - 17
apps/app/src/states/ui/page-tree-desc-count-map.ts

@@ -1,6 +1,5 @@
-import { useCallback } from 'react';
-
 import { atom, useAtomValue, useSetAtom } from 'jotai';
+import { useCallback } from 'react';
 
 // Type definitions
 export type UpdateDescCountData = Map<string, number>;
@@ -19,23 +18,29 @@ const pageTreeDescCountMapAtom = atom<UpdateDescCountData>(new Map());
 export const usePageTreeDescCountMap = (): PageTreeDescCountMapGetter => {
   const data = useAtomValue(pageTreeDescCountMapAtom);
 
-  const getDescCount = useCallback((pageId?: string) => {
-    return pageId != null ? data.get(pageId) ?? null : null;
-  }, [data]);
+  const getDescCount = useCallback(
+    (pageId?: string) => {
+      return pageId != null ? (data.get(pageId) ?? null) : null;
+    },
+    [data],
+  );
 
   return { getDescCount };
 };
 
-
 // Actions hook (write-only with callbacks)
-export const usePageTreeDescCountMapAction = (): PageTreeDescCountMapActions => {
-  const setDescCountMap = useSetAtom(pageTreeDescCountMapAtom);
-
-  const update = useCallback((newData: UpdateDescCountData) => {
-    setDescCountMap((current) => {
-      return new Map([...current, ...newData]);
-    });
-  }, [setDescCountMap]);
-
-  return { update };
-};
+export const usePageTreeDescCountMapAction =
+  (): PageTreeDescCountMapActions => {
+    const setDescCountMap = useSetAtom(pageTreeDescCountMapAtom);
+
+    const update = useCallback(
+      (newData: UpdateDescCountData) => {
+        setDescCountMap((current) => {
+          return new Map([...current, ...newData]);
+        });
+      },
+      [setDescCountMap],
+    );
+
+    return { update };
+  };

+ 10 - 5
apps/app/src/states/ui/sidebar/sidebar.ts

@@ -1,5 +1,5 @@
 import { atom, useAtom, useAtomValue, useSetAtom } from 'jotai';
-import { useCallback, useMemo, type RefObject } from 'react';
+import { type RefObject, useCallback, useMemo } from 'react';
 
 import { scheduleToPut } from '~/client/services/user-ui-settings';
 import { SidebarContentsType, SidebarMode } from '~/interfaces/ui';
@@ -122,7 +122,9 @@ export const useSidebarMode = (): {
 };
 
 // Sidebar scroller ref atom and hooks
-const sidebarScrollerRefAtom = atom<RefObject<HTMLDivElement | null> | null>(null);
+const sidebarScrollerRefAtom = atom<RefObject<HTMLDivElement | null> | null>(
+  null,
+);
 
 /**
  * Hook to get the sidebar scroller ref
@@ -140,9 +142,12 @@ export const useSidebarScrollerElem = (): HTMLDivElement | null => {
 export const useSetSidebarScrollerRef = () => {
   const setSidebarScrollerRef = useSetAtom(sidebarScrollerRefAtom);
 
-  const mutate = useCallback((newRef: RefObject<HTMLDivElement | null>) => {
-    setSidebarScrollerRef(newRef);
-  }, [setSidebarScrollerRef]);
+  const mutate = useCallback(
+    (newRef: RefObject<HTMLDivElement | null>) => {
+      setSidebarScrollerRef(newRef);
+    },
+    [setSidebarScrollerRef],
+  );
 
   return mutate;
 };

+ 34 - 15
apps/app/src/states/ui/toc.ts

@@ -1,15 +1,13 @@
 import { atom, useAtomValue, useSetAtom } from 'jotai';
-import { useCallback, useEffect, useState, type RefObject } from 'react';
+import { type RefObject, useCallback, useEffect, useState } from 'react';
 import type { HtmlElementNode } from 'rehype-toc';
-
+import type { generateTocOptions } from '~/client/services/renderer/renderer';
 import type { RendererOptions } from '~/interfaces/renderer-options';
 import type { RendererConfigExt } from '~/interfaces/services/renderer';
 import { useCurrentPagePath } from '~/states/page';
 import { useRendererConfig } from '~/states/server-configurations';
 import { useNextThemes } from '~/stores-universal/use-next-themes';
 
-import type { generateTocOptions } from '~/client/services/renderer/renderer';
-
 // ============================================================================
 // INTERNAL ATOMS (Implementation details, not exported)
 // ============================================================================
@@ -69,11 +67,14 @@ export const useTocNode = (): HtmlElementNode | null => {
 export const useSetTocNode = () => {
   const setTocNodeRef = useSetAtom(tocNodeRefAtom);
 
-  const setTocNode = useCallback((newNode: HtmlElementNode) => {
-    // Create a RefObject wrapper for the HtmlElementNode
-    const nodeRef: RefObject<HtmlElementNode> = { current: newNode };
-    setTocNodeRef(nodeRef);
-  }, [setTocNodeRef]);
+  const setTocNode = useCallback(
+    (newNode: HtmlElementNode) => {
+      // Create a RefObject wrapper for the HtmlElementNode
+      const nodeRef: RefObject<HtmlElementNode> = { current: newNode };
+      setTocNodeRef(nodeRef);
+    },
+    [setTocNodeRef],
+  );
 
   return setTocNode;
 };
@@ -88,8 +89,14 @@ export const useTocOptions = () => {
   const { isDarkMode } = useNextThemes();
   const tocNode = useAtomValue(tocNodeAtom);
 
-  const [state, setState] = useState<{ data?: RendererOptions; isLoading: boolean; error?: Error }>({
-    data: undefined, isLoading: false, error: undefined
+  const [state, setState] = useState<{
+    data?: RendererOptions;
+    isLoading: boolean;
+    error?: Error;
+  }>({
+    data: undefined,
+    isLoading: false,
+    error: undefined,
   });
 
   useEffect(() => {
@@ -103,19 +110,31 @@ export const useTocOptions = () => {
       return;
     }
 
-    setState(prev => ({ ...prev, isLoading: true, error: undefined }));
+    setState((prev) => ({ ...prev, isLoading: true, error: undefined }));
 
     (async () => {
       try {
         if (!generateTocOptionsCache) {
-          const { generateTocOptions } = await import('~/client/services/renderer/renderer');
+          const { generateTocOptions } = await import(
+            '~/client/services/renderer/renderer'
+          );
           generateTocOptionsCache = generateTocOptions;
         }
 
-        const data = generateTocOptionsCache({ ...rendererConfig, isDarkMode }, tocNode);
+        const data = generateTocOptionsCache(
+          { ...rendererConfig, isDarkMode },
+          tocNode,
+        );
         setState({ data, isLoading: false, error: undefined });
       } catch (err) {
-        setState({ data: undefined, isLoading: false, error: err instanceof Error ? err : new Error('TOC options generation failed') });
+        setState({
+          data: undefined,
+          isLoading: false,
+          error:
+            err instanceof Error
+              ? err
+              : new Error('TOC options generation failed'),
+        });
       }
     })();
   }, [currentPagePath, rendererConfig, isDarkMode, tocNode]);

+ 26 - 21
apps/app/src/states/ui/unsaved-warning.ts

@@ -1,7 +1,6 @@
-import { useCallback, useLayoutEffect } from 'react';
-import { useRouter } from 'next/router';
-
 import { atom, useAtomValue, useSetAtom } from 'jotai';
+import { useRouter } from 'next/router';
+import { useCallback, useLayoutEffect } from 'react';
 
 // Type definitions
 type CommentEditorDirtyMapData = Map<string, boolean>;
@@ -39,25 +38,31 @@ export const useUnsavedWarning = () => {
 export const useCommentEditorsDirtyMap = () => {
   const setDirtyMap = useSetAtom(commentEditorDirtyMapAtom);
 
-  const markDirty = useCallback((editorKey: string, content: string) => {
-    setDirtyMap((current) => {
-      const newMap = new Map(current);
-      if (content.length === 0) {
-        newMap.delete(editorKey);
-      } else {
-        newMap.set(editorKey, true);
-      }
-      return newMap;
-    });
-  }, [setDirtyMap]);
+  const markDirty = useCallback(
+    (editorKey: string, content: string) => {
+      setDirtyMap((current) => {
+        const newMap = new Map(current);
+        if (content.length === 0) {
+          newMap.delete(editorKey);
+        } else {
+          newMap.set(editorKey, true);
+        }
+        return newMap;
+      });
+    },
+    [setDirtyMap],
+  );
 
-  const markClean = useCallback((editorKey: string) => {
-    setDirtyMap((current) => {
-      const newMap = new Map(current);
-      newMap.delete(editorKey);
-      return newMap;
-    });
-  }, [setDirtyMap]);
+  const markClean = useCallback(
+    (editorKey: string) => {
+      setDirtyMap((current) => {
+        const newMap = new Map(current);
+        newMap.delete(editorKey);
+        return newMap;
+      });
+    },
+    [setDirtyMap],
+  );
 
   return { markDirty, markClean };
 };