MarkupTools.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import React, { useEffect } from 'react';
  2. import { useRouter } from 'next/router';
  3. import { useTranslation } from 'react-i18next';
  4. // import Button from '../components/Button';
  5. // import ExpansionPanel from '../components/ExpansionPanel';
  6. // import Icon from '../components/Icon';
  7. import HighlightTools from './HighlightTools';
  8. import FreehandTools from './FreehandTools';
  9. import TextTools from './FreeTextTools';
  10. import StickyNoteTools from './StickyNoteTools';
  11. import ShapeTools from './ShapeTools';
  12. import WatermarkTool from './WatermarkTool';
  13. import useActions from '../actions';
  14. import useStore from '../store';
  15. const MarkupTools: React.FC = () => {
  16. const { t } = useTranslation('sidebar');
  17. const [{ sidebarState }, dispatch] = useStore();
  18. const { setSidebar } = useActions(dispatch);
  19. const router = useRouter();
  20. // const onClickSidebar = (state: string): void => {
  21. // if (state === sidebarState) {
  22. // setSidebar('');
  23. // } else {
  24. // setSidebar(state);
  25. // }
  26. // };
  27. const onClickTool = (state: string): void => {
  28. if (state === sidebarState) {
  29. setSidebar('');
  30. } else {
  31. setSidebar(state);
  32. }
  33. };
  34. // useEffect(() => {
  35. // if (sidebarState !== 'markup-tools') {
  36. // setSidebar('');
  37. // }
  38. // }, []);
  39. // const Label = (
  40. // <Button
  41. // shouldFitContainer
  42. // align="left"
  43. // onClick={(): void => {
  44. // onClickSidebar('markup-tools');
  45. // }}
  46. // >
  47. // <Icon glyph="markup-tools" style={{ marginRight: '10px' }} />
  48. // {t('markupTool')}
  49. // </Button>
  50. // );
  51. useEffect(() => {
  52. if (router.query.tool === 'shape') {
  53. setSidebar('shape');
  54. } else {
  55. setSidebar('highlight');
  56. }
  57. }, [router]);
  58. return (
  59. <>
  60. <HighlightTools
  61. title={t('annotate')}
  62. isActive={sidebarState === 'highlight'}
  63. onClick={(): void => {
  64. onClickTool('highlight');
  65. }}
  66. />
  67. <FreehandTools
  68. title={t('freehand')}
  69. isActive={sidebarState === 'freehand'}
  70. onClick={(): void => {
  71. onClickTool('freehand');
  72. }}
  73. />
  74. <TextTools
  75. title={t('textBox')}
  76. isActive={sidebarState === 'text'}
  77. onClick={(): void => {
  78. onClickTool('text');
  79. }}
  80. />
  81. <StickyNoteTools
  82. title={t('stickyNote')}
  83. isActive={sidebarState === 'sticky'}
  84. onClick={(): void => {
  85. onClickTool('sticky');
  86. }}
  87. />
  88. <ShapeTools
  89. title={t('shape')}
  90. isActive={sidebarState === 'shape'}
  91. onClick={(): void => {
  92. onClickTool('shape');
  93. }}
  94. />
  95. <WatermarkTool />
  96. </>
  97. );
  98. };
  99. export default MarkupTools;