try-new-editor-button.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { useCallback, useState } from 'react'
  2. import OLButton from '../../shared/components/ol/ol-button'
  3. import { useTranslation } from 'react-i18next'
  4. import { useSwitchEnableNewEditorState } from '../ide-redesign/hooks/use-switch-enable-new-editor-state'
  5. import MaterialIcon from '@/shared/components/material-icon'
  6. import { useEditorAnalytics } from '@/shared/hooks/use-editor-analytics'
  7. import OldEditorWarningTooltip from '../ide-redesign/components/old-editor-warning-tooltip'
  8. const TryNewEditorButton = () => {
  9. const { t } = useTranslation()
  10. const { loading, setEditorRedesignStatus } = useSwitchEnableNewEditorState()
  11. const { sendEvent } = useEditorAnalytics()
  12. const [buttonElt, setButtonElt] = useState<HTMLButtonElement | null>(null)
  13. const buttonRef = useCallback((node: HTMLButtonElement) => {
  14. if (node !== null) {
  15. setButtonElt(node)
  16. }
  17. }, [])
  18. const onClick = useCallback(() => {
  19. sendEvent('switch-to-new-editor', {
  20. location: 'toolbar',
  21. })
  22. setEditorRedesignStatus(true)
  23. }, [setEditorRedesignStatus, sendEvent])
  24. return (
  25. <div className="d-flex align-items-center">
  26. <OLButton
  27. className="toolbar-experiment-button try-new-editor-button"
  28. onClick={onClick}
  29. size="sm"
  30. variant="secondary"
  31. isLoading={loading}
  32. ref={buttonRef}
  33. >
  34. <MaterialIcon type="fiber_new" />
  35. {t('switch_to_new_look')}
  36. </OLButton>
  37. <OldEditorWarningTooltip target={buttonElt} />
  38. </div>
  39. )
  40. }
  41. export default TryNewEditorButton