Просмотр исходного кода

add regex / replace isUserPage with isUserNamePage

yohei0125 4 лет назад
Родитель
Сommit
cfff7b3b1a

+ 2 - 2
packages/app/src/components/Sidebar/PageTree/Item.tsx

@@ -16,7 +16,7 @@ import { IPageForPageDeleteModal } from '~/components/PageDeleteModal';
 
 
 import TriangleIcon from '~/components/Icons/TriangleIcon';
 import TriangleIcon from '~/components/Icons/TriangleIcon';
 
 
-const { isTopPage, isUserPage } = pagePathUtils;
+const { isTopPage, isUserNamePage } = pagePathUtils;
 
 
 
 
 interface ItemProps {
 interface ItemProps {
@@ -132,7 +132,7 @@ const Item: FC<ItemProps> = (props: ItemProps) => {
 
 
   const hasDescendants = (page.descendantCount != null && page?.descendantCount > 0);
   const hasDescendants = (page.descendantCount != null && page?.descendantCount > 0);
 
 
-  const isDeletable = !page.isEmpty && !isTopPage(page.path as string) && !isUserPage(page.path as string);
+  const isDeletable = !page.isEmpty && !isTopPage(page.path as string) && !isUserNamePage(page.path as string);
 
 
   const [{ isDragging }, drag] = useDrag(() => ({
   const [{ isDragging }, drag] = useDrag(() => ({
     type: 'PAGE_TREE',
     type: 'PAGE_TREE',

+ 1 - 0
packages/app/src/server/service/page.js

@@ -33,6 +33,7 @@ class PageService {
 
 
     // init
     // init
     this.initPageEvent();
     this.initPageEvent();
+    this.updateDescendantCountOfSelfAndDescendants();
   }
   }
 
 
   initPageEvent() {
   initPageEvent() {

+ 13 - 0
packages/core/src/utils/page-path-utils.ts

@@ -36,6 +36,19 @@ export const isUserPage = (path: string): boolean => {
   return false;
   return false;
 };
 };
 
 
+/**
+ * Whether path is right under the path '/user'
+ * @param path
+ */
+export const isUserNamePage = (path: string): boolean => {
+  // https://regex101.com/r/GUZntH/1
+  if (path.match(/^\/user\/[^/]+$/)) {
+    return true;
+  }
+
+  return false;
+};
+
 /**
 /**
  * Whether path belongs to the shared page
  * Whether path belongs to the shared page
  * @param path
  * @param path