IdenticalPathPage.tsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import type { FC, JSX } from 'react';
  2. import React from 'react';
  3. import { DevidedPagePath } from '@growi/core/dist/models';
  4. import { useTranslation } from 'next-i18next';
  5. import { useCurrentPathname } from '~/states/global';
  6. import {
  7. useSWRxPageInfoForList,
  8. useSWRxPagesByPath,
  9. } from '~/stores/page-listing';
  10. import { PageListItemL } from './PageList/PageListItemL';
  11. import styles from './IdenticalPathPage.module.scss';
  12. type IdenticalPathAlertProps = {
  13. path?: string | null;
  14. };
  15. const IdenticalPathAlert: FC<IdenticalPathAlertProps> = (
  16. props: IdenticalPathAlertProps,
  17. ) => {
  18. const { path } = props;
  19. const { t } = useTranslation();
  20. let _path = '――';
  21. let _pageName = '――';
  22. if (path != null) {
  23. const devidedPath = new DevidedPagePath(path);
  24. _path = devidedPath.isFormerRoot ? '/' : devidedPath.former;
  25. _pageName = devidedPath.latter;
  26. }
  27. return (
  28. <div className="alert alert-warning py-3">
  29. <h5 className="fw-bold mt-1">
  30. {t('duplicated_page_alert.same_page_name_exists', {
  31. pageName: _pageName,
  32. })}
  33. </h5>
  34. <p>
  35. {t('duplicated_page_alert.same_page_name_exists_at_path', {
  36. path: _path,
  37. pageName: _pageName,
  38. })}
  39. <br />
  40. <span
  41. // biome-ignore lint/security/noDangerouslySetInnerHtml: translation contains HTML link
  42. dangerouslySetInnerHTML={{
  43. __html: t('See_more_detail_on_new_schema', {
  44. title: t('GROWI.5.0_new_schema'),
  45. }),
  46. }}
  47. />
  48. </p>
  49. <p className="mb-1">{t('duplicated_page_alert.select_page_to_see')}</p>
  50. </div>
  51. );
  52. };
  53. export const IdenticalPathPage = (): JSX.Element => {
  54. const currentPath = useCurrentPathname();
  55. const { data: pages } = useSWRxPagesByPath(currentPath);
  56. const { injectTo } = useSWRxPageInfoForList(null, currentPath, true, true);
  57. if (pages == null) {
  58. return <></>;
  59. }
  60. const injectedPages = injectTo(pages);
  61. return (
  62. <>
  63. <IdenticalPathAlert path={currentPath} />
  64. <div className={`page-list ${styles['page-list']}`}>
  65. <ul className="page-list-ul list-group list-group-flush">
  66. {injectedPages.map((pageWithMeta) => {
  67. const pageId = pageWithMeta.data._id;
  68. return (
  69. <PageListItemL
  70. key={pageId}
  71. page={pageWithMeta}
  72. isSelected={false}
  73. isEnableActions
  74. isReadOnlyUser={false}
  75. showPageUpdatedTime
  76. />
  77. );
  78. })}
  79. </ul>
  80. </div>
  81. </>
  82. );
  83. };