import React, { useCallback } from 'react'; import { useTranslation } from 'next-i18next'; import PropTypes from 'prop-types'; import { UncontrolledTooltip } from 'reactstrap'; import { useIsAdmin, useHackmdUri } from '~/stores/context'; import { EditorMode, useIsDeviceSmallerThanMd } from '~/stores/ui'; import styles from './PageEditorModeManager.module.scss'; /* eslint-disable react/prop-types */ const PageEditorModeButtonWrapper = React.memo(({ editorMode, isBtnDisabled, onClick, targetMode, icon, label, id, }) => { const classNames = [`btn btn-outline-primary ${targetMode}-button px-1`]; if (editorMode === targetMode) { classNames.push('active'); } if (isBtnDisabled) { classNames.push('disabled'); } return ( ); }); /* eslint-enable react/prop-types */ PageEditorModeButtonWrapper.displayName = 'PageEditorModeButtonWrapper'; function PageEditorModeManager(props) { const { editorMode, onPageEditorModeButtonClicked, isBtnDisabled, } = props; const { t } = useTranslation(); const { data: isDeviceSmallerThanMd } = useIsDeviceSmallerThanMd(); const { data: hackmdUri } = useHackmdUri(); const { data: isAdmin } = useIsAdmin(); const isHackmdEnabled = hackmdUri != null; const showHackmdBtn = isHackmdEnabled || isAdmin; const pageEditorModeButtonClickedHandler = useCallback((viewType) => { if (isBtnDisabled) { return; } if (onPageEditorModeButtonClicked != null) { onPageEditorModeButtonClicked(viewType); } }, [isBtnDisabled, onPageEditorModeButtonClicked]); return ( <>