compiler-setting.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { useState } from 'react'
  2. import { useProjectSettingsContext } from '@/features/editor-left-menu/context/project-settings-context'
  3. import DropdownSetting from '../dropdown-setting'
  4. import type { Option } from '../dropdown-setting'
  5. import { useTranslation } from 'react-i18next'
  6. import { usePermissionsContext } from '@/features/ide-react/context/permissions-context'
  7. import { ProjectCompiler } from '@ol-types/project-settings'
  8. import { useSetCompilationSettingWithEvent } from '@/features/editor-left-menu/hooks/use-set-compilation-setting'
  9. import getMeta from '@/utils/meta'
  10. import _ from 'lodash'
  11. function getCompilerOptions(): Option<ProjectCompiler>[] {
  12. const compilerOptions = ['pdfLaTeX', 'LaTeX', 'XeLaTeX', 'LuaLaTeX']
  13. const defaultCompiler = getMeta('ol-defaultLatexCompiler') as ProjectCompiler
  14. const sortedOptions = _.sortBy(
  15. compilerOptions,
  16. option => option.toLowerCase() !== defaultCompiler.toLowerCase()
  17. )
  18. return sortedOptions.map(option => ({
  19. value: option.toLowerCase() as ProjectCompiler,
  20. label: option,
  21. }))
  22. }
  23. export default function CompilerSetting() {
  24. const { compiler, setCompiler } = useProjectSettingsContext()
  25. const [compilerOptions] = useState(() => getCompilerOptions())
  26. const { t } = useTranslation()
  27. const { write } = usePermissionsContext()
  28. const changeCompiler = useSetCompilationSettingWithEvent(
  29. 'compiler',
  30. setCompiler
  31. )
  32. return (
  33. <DropdownSetting
  34. id="compiler"
  35. label={t('compiler')}
  36. description={t('the_latex_engine_used_for_compiling')}
  37. disabled={!write}
  38. options={compilerOptions}
  39. onChange={changeCompiler}
  40. value={compiler}
  41. translateOptions="no"
  42. />
  43. )
  44. }