import { ChangeEvent, FC, memo, useCallback } from 'react'
import useScopeValue from '../../../shared/hooks/use-scope-value'
import Tooltip from '../../../shared/components/tooltip'
import { sendMB } from '../../../infrastructure/event-tracking'
import getMeta from '../../../utils/meta'
import isValidTeXFile from '../../../main/is-valid-tex-file'
import { useTranslation } from 'react-i18next'
import SplitTestBadge from '../../../shared/components/split-test-badge'
function Badge() {
const content = (
<>
Overleaf has upgraded the source editor.
You can still use the old editor by selecting "Source (legacy)".
Click to learn more and give feedback
>
)
return (
{content}
)
}
const showLegacySourceEditor: boolean = getMeta('ol-showLegacySourceEditor')
function EditorSwitch() {
const { t } = useTranslation()
const [newSourceEditor, setNewSourceEditor] = useScopeValue(
'editor.newSourceEditor'
)
const [visual, setVisual] = useScopeValue('editor.showVisual')
const [docName] = useScopeValue('editor.open_doc_name')
const richTextAvailable = isValidTeXFile(docName)
// TODO: rename this after legacy & toolbar split tests are complete
const richTextOrVisual = richTextAvailable && visual
const handleChange = useCallback(
event => {
const editorType = event.target.value
switch (editorType) {
case 'ace':
setVisual(false)
setNewSourceEditor(false)
break
case 'cm6':
setVisual(false)
setNewSourceEditor(true)
break
case 'rich-text':
setVisual(true)
setNewSourceEditor(true)
break
}
sendMB('editor-switch-change', { editorType })
},
[setVisual, setNewSourceEditor]
)
return (