draft-setting.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { useTranslation } from 'react-i18next'
  2. import { useDetachCompileContext as useCompileContext } from '@/shared/context/detach-compile-context'
  3. import { useCallback, useMemo } from 'react'
  4. import * as eventTracking from '../../../../../infrastructure/event-tracking'
  5. import DropdownSetting from '../dropdown-setting'
  6. export default function DraftSetting() {
  7. const { draft, setDraft } = useCompileContext()
  8. const { t } = useTranslation()
  9. const sendEventAndSet = useCallback(
  10. (value: boolean) => {
  11. eventTracking.sendMB('recompile-setting-changed', {
  12. setting: 'compile-mode',
  13. settingVal: value,
  14. })
  15. setDraft(value)
  16. },
  17. [setDraft]
  18. )
  19. const options = useMemo(
  20. () => [
  21. { label: t('normal'), value: false },
  22. {
  23. label: t('fast_draft'),
  24. value: true,
  25. },
  26. ],
  27. [t]
  28. )
  29. return (
  30. <DropdownSetting
  31. id="draft"
  32. label={t('compile_mode')}
  33. options={options}
  34. description={t('switch_compile_mode_for_faster_draft_compilation')}
  35. value={draft}
  36. onChange={sendEventAndSet}
  37. />
  38. )
  39. }