Browse Source

fix: refactor LinkedPagePath class structure and update import statements

Yuki Takei 1 month ago
parent
commit
db26b1c05f

+ 1 - 1
apps/app/src/client/components/PageHeader/PagePathHeader.tsx

@@ -13,7 +13,7 @@ import {
   ValidationTarget,
 } from '~/client/util/use-input-validator';
 import type { IPageForItem } from '~/interfaces/page';
-import LinkedPagePath from '~/models/linked-page-path';
+import { LinkedPagePath } from '~/models/linked-page-path';
 import { usePageSelectModalActions } from '~/states/ui/modal/page-select';
 
 import { PagePathHierarchicalLink } from '../../../components/Common/PagePathHierarchicalLink';

+ 1 - 1
apps/app/src/client/components/PageList/PageListItemL.tsx

@@ -34,7 +34,7 @@ import type {
   OnPutBackedFunction,
   OnRenamedFunction,
 } from '~/interfaces/ui';
-import LinkedPagePath from '~/models/linked-page-path';
+import { LinkedPagePath } from '~/models/linked-page-path';
 import { useDeviceLargerThanLg } from '~/states/ui/device';
 import { usePageDeleteModalActions } from '~/states/ui/modal/page-delete';
 import { usePageDuplicateModalActions } from '~/states/ui/modal/page-duplicate';

+ 1 - 1
apps/app/src/client/components/PagePathNavSticky/CollapsedParentsDropdown.tsx

@@ -7,7 +7,7 @@ import {
   UncontrolledDropdown,
 } from 'reactstrap';
 
-import type LinkedPagePath from '~/models/linked-page-path';
+import type { LinkedPagePath } from '~/models/linked-page-path';
 
 import styles from './CollapsedParentsDropdown.module.scss';
 

+ 1 - 1
apps/app/src/client/components/PagePathNavSticky/PagePathNavSticky.tsx

@@ -4,7 +4,7 @@ import { pagePathUtils } from '@growi/core/dist/utils';
 import Sticky from 'react-stickynode';
 
 import { usePrintMode } from '~/client/services/use-print-mode';
-import LinkedPagePath from '~/models/linked-page-path';
+import { LinkedPagePath } from '~/models/linked-page-path';
 import { usePageControlsX } from '~/states/ui/page';
 import { useCurrentProductNavWidth, useSidebarMode } from '~/states/ui/sidebar';
 

+ 1 - 1
apps/app/src/client/components/Sidebar/RecentChanges/RecentChangesSubstance.tsx

@@ -7,7 +7,7 @@ import { useTranslation } from 'react-i18next';
 import FormattedDistanceDate from '~/client/components/FormattedDistanceDate';
 import InfiniteScroll from '~/client/components/InfiniteScroll';
 import { PagePathHierarchicalLink } from '~/components/Common/PagePathHierarchicalLink';
-import LinkedPagePath from '~/models/linked-page-path';
+import { LinkedPagePath } from '~/models/linked-page-path';
 import { useSetSearchKeyword } from '~/states/search';
 import { useSWRINFxRecentlyUpdated } from '~/stores/page-listing';
 import loggerFactory from '~/utils/logger';

+ 1 - 1
apps/app/src/components/Common/PagePathHierarchicalLink/PagePathHierarchicalLink.tsx

@@ -2,7 +2,7 @@ import { type FC, type JSX, memo, useCallback } from 'react';
 import Link from 'next/link';
 import urljoin from 'url-join';
 
-import type LinkedPagePath from '~/models/linked-page-path';
+import type { LinkedPagePath } from '~/models/linked-page-path';
 
 import styles from './PagePathHierarchicalLink.module.scss';
 

+ 1 - 1
apps/app/src/components/Common/PagePathNav/PagePathNav.tsx

@@ -2,7 +2,7 @@ import { type JSX, useMemo } from 'react';
 import { DevidedPagePath } from '@growi/core/dist/models';
 import { pagePathUtils } from '@growi/core/dist/utils';
 
-import LinkedPagePath from '~/models/linked-page-path';
+import { LinkedPagePath } from '~/models/linked-page-path';
 
 import { PagePathHierarchicalLink } from '../PagePathHierarchicalLink';
 import { Separator } from '.';

+ 18 - 9
apps/app/src/models/linked-page-path.ts

@@ -6,27 +6,36 @@ const { isTrashPage } = pagePathUtils;
 /**
  * Linked Array Structured PagePath Model
  */
-export default class LinkedPagePath {
-  constructor(path) {
+export class LinkedPagePath {
+  readonly path: string;
+
+  readonly pathName: string;
+
+  readonly parent?: LinkedPagePath;
+
+  constructor(path: string) {
     const pagePath = new DevidedPagePath(path);
 
     this.path = path;
     this.pathName = pagePath.latter;
-    this.isRoot = pagePath.isRoot;
     this.parent = pagePath.isRoot
-      ? null
-      : new LinkedPagePath(pagePath.former, true);
+      ? undefined
+      : new LinkedPagePath(pagePath.former);
+  }
+
+  get isRoot(): boolean {
+    return this.parent == null;
   }
 
-  get href() {
-    if (this.isRoot) {
-      return '';
+  get href(): string {
+    if (this.parent == null) {
+      return '/';
     }
 
     return pathUtils.normalizePath(`${this.parent.href}/${this.pathName}`);
   }
 
-  get isInTrash() {
+  get isInTrash(): boolean {
     return isTrashPage(this.path);
   }
 }