PagePathHeader.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { FC, useCallback, useState } from 'react';
  2. import type { IPagePopulatedToShowRevision } from '@growi/core';
  3. import { usePageSelectModal } from '~/stores/modal';
  4. import { EditorMode, useEditorMode } from '~/stores/ui';
  5. import { PagePathNav } from '../Common/PagePathNav';
  6. import { PageSelectModal } from '../PageSelectModal/PageSelectModal';
  7. import { TextInputForPageTitleAndPath } from './TextInputForPageTitleAndPath';
  8. import { usePagePathSubmitHandler } from './page-header-utils';
  9. type Props = {
  10. currentPagePath: string
  11. currentPage: IPagePopulatedToShowRevision
  12. }
  13. export const PagePathHeader: FC<Props> = (props) => {
  14. const { currentPagePath, currentPage } = props;
  15. const [isRenameInputShown, setRenameInputShown] = useState(false);
  16. const [isButtonsShown, setButtonShown] = useState(false);
  17. const [inputText, setInputText] = useState('');
  18. const { data: editorMode } = useEditorMode();
  19. const { data: PageSelectModalData, open: openPageSelectModal } = usePageSelectModal();
  20. const pagePathSubmitHandler = usePagePathSubmitHandler(currentPage, currentPagePath, setRenameInputShown);
  21. const stateHandler = { isRenameInputShown, setRenameInputShown };
  22. const isOpened = PageSelectModalData?.isOpened ?? false;
  23. const isViewMode = editorMode === EditorMode.View;
  24. const isEditorMode = !isViewMode;
  25. const PagePath = useCallback(() => {
  26. return (
  27. <>
  28. { currentPagePath != null && (
  29. <PagePathNav
  30. pageId={currentPage._id}
  31. pagePath={currentPagePath}
  32. isSingleLineMode={isEditorMode}
  33. />
  34. )}
  35. </>
  36. );
  37. }, [currentPage._id, currentPagePath, isEditorMode]);
  38. const handleInputChange = (inputText: string) => {
  39. setInputText(inputText);
  40. };
  41. console.log(inputText);
  42. return (
  43. <>
  44. <div onMouseLeave={() => setButtonShown(false)}>
  45. <div
  46. className="row"
  47. >
  48. <div
  49. className="col-4"
  50. onMouseEnter={() => setButtonShown(true)}
  51. >
  52. <TextInputForPageTitleAndPath
  53. currentPagePath={currentPagePath}
  54. currentPage={currentPage}
  55. stateHandler={stateHandler}
  56. inputValue={currentPagePath}
  57. CustomComponent={PagePath}
  58. handleInputChange={handleInputChange}
  59. />
  60. </div>
  61. { isButtonsShown
  62. && (
  63. <>
  64. <div className="col-4">
  65. {
  66. isRenameInputShown
  67. ? <button type="button" onClick={() => console.log('完了!')}>完了ボタン</button>
  68. : <button type="button" onClick={() => setRenameInputShown(true)}>編集ボタン</button>
  69. }
  70. </div>
  71. <div className="col-4">
  72. <button type="button" onClick={openPageSelectModal}>ページツリーボタン</button>
  73. </div>
  74. </>
  75. )}
  76. { isOpened
  77. && (
  78. <PageSelectModal />
  79. )}
  80. </div>
  81. </div>
  82. </>
  83. );
  84. };