IdenticalPathPage.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import React, { FC } from 'react';
  2. import { DevidedPagePath } from '@growi/core';
  3. import { useTranslation } from 'next-i18next';
  4. import { useCurrentPagePath, useIsSharedUser } from '~/stores/context';
  5. import { useDescendantsPageListModal } from '~/stores/modal';
  6. import { useSWRxPageInfoForList, useSWRxPagesByPath } from '~/stores/page-listing';
  7. import PageListIcon from './Icons/PageListIcon';
  8. import { PageListItemL } from './PageList/PageListItemL';
  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="font-weight-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', { url: 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 = (): JSX.Element => {
  38. const { t } = useTranslation();
  39. const { data: currentPath } = useCurrentPagePath();
  40. const { data: isSharedUser } = useIsSharedUser();
  41. const { data: pages } = useSWRxPagesByPath(currentPath);
  42. const { injectTo } = useSWRxPageInfoForList(null, currentPath, true, true);
  43. const { open: openDescendantPageListModal } = useDescendantsPageListModal();
  44. if (pages == null) {
  45. return <></>;
  46. }
  47. const injectedPages = injectTo(pages);
  48. return (
  49. <div className="d-flex flex-column flex-lg-row-reverse">
  50. <div className="grw-side-contents-container">
  51. <div className="grw-page-accessories-control pb-1">
  52. { currentPath != null && !isSharedUser && (
  53. <button
  54. type="button"
  55. className="btn btn-block btn-outline-secondary grw-btn-page-accessories rounded-pill d-flex justify-content-between"
  56. onClick={() => openDescendantPageListModal(currentPath)}
  57. >
  58. <PageListIcon />
  59. {t('page_list')}
  60. <span></span> {/* for a count badge */}
  61. </button>
  62. ) }
  63. </div>
  64. </div>
  65. <div className="flex-grow-1 flex-basis-0 mw-0">
  66. <IdenticalPathAlert path={currentPath} />
  67. <div className="page-list">
  68. <ul className="page-list-ul list-group list-group-flush">
  69. {injectedPages.map((pageWithMeta) => {
  70. const pageId = pageWithMeta.data._id;
  71. return (
  72. <PageListItemL
  73. key={pageId}
  74. page={pageWithMeta}
  75. isSelected={false}
  76. isEnableActions
  77. showPageUpdatedTime
  78. />
  79. );
  80. })}
  81. </ul>
  82. </div>
  83. </div>
  84. </div>
  85. );
  86. };