IdenticalPathPage.tsx 2.3 KB

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