IdenticalPathPage.tsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import type { FC } 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 '~/stores-universal/context';
  6. import { useSWRxPageInfoForList, useSWRxPagesByPath } from '~/stores/page-listing';
  7. import { PageListItemL } from './PageList/PageListItemL';
  8. import styles from './IdenticalPathPage.module.scss';
  9. type IdenticalPathAlertProps = {
  10. path? : string | null,
  11. }
  12. const IdenticalPathAlert : FC<IdenticalPathAlertProps> = (props: IdenticalPathAlertProps) => {
  13. const { path } = props;
  14. const { t } = useTranslation();
  15. let _path = '――';
  16. let _pageName = '――';
  17. if (path != null) {
  18. const devidedPath = new DevidedPagePath(path);
  19. _path = devidedPath.isFormerRoot ? '/' : devidedPath.former;
  20. _pageName = devidedPath.latter;
  21. }
  22. return (
  23. <div className="alert alert-warning py-3">
  24. <h5 className="fw-bold mt-1">{t('duplicated_page_alert.same_page_name_exists', { pageName: _pageName })}</h5>
  25. <p>
  26. {t('duplicated_page_alert.same_page_name_exists_at_path',
  27. { path: _path, pageName: _pageName })}<br />
  28. <span
  29. // eslint-disable-next-line react/no-danger
  30. dangerouslySetInnerHTML={{ __html: t('See_more_detail_on_new_schema', { title: t('GROWI.5.0_new_schema') }) }}
  31. />
  32. </p>
  33. <p className="mb-1">{t('duplicated_page_alert.select_page_to_see')}</p>
  34. </div>
  35. );
  36. };
  37. export const IdenticalPathPage = (): React.ReactElement => {
  38. const { data: currentPath } = useCurrentPathname();
  39. const { data: pages } = useSWRxPagesByPath(currentPath);
  40. const { injectTo } = useSWRxPageInfoForList(null, currentPath, true, true);
  41. if (pages == null) {
  42. return <></>;
  43. }
  44. const injectedPages = injectTo(pages);
  45. return (
  46. <>
  47. <IdenticalPathAlert path={currentPath} />
  48. <div className={`page-list ${styles['page-list']}`}>
  49. <ul className="page-list-ul list-group list-group-flush">
  50. {injectedPages.map((pageWithMeta) => {
  51. const pageId = pageWithMeta.data._id;
  52. return (
  53. <PageListItemL
  54. key={pageId}
  55. page={pageWithMeta}
  56. isSelected={false}
  57. isEnableActions
  58. isReadOnlyUser={false}
  59. showPageUpdatedTime
  60. />
  61. );
  62. })}
  63. </ul>
  64. </div>
  65. </>
  66. );
  67. };