image-name-setting.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { useProjectSettingsContext } from '@/features/editor-left-menu/context/project-settings-context'
  2. import DropdownSetting from '../dropdown-setting'
  3. import type { Option } from '../dropdown-setting'
  4. import { useTranslation } from 'react-i18next'
  5. import { usePermissionsContext } from '@/features/ide-react/context/permissions-context'
  6. import { useMemo } from 'react'
  7. import getMeta from '@/utils/meta'
  8. export default function ImageNameSetting() {
  9. const { imageName, setImageName } = useProjectSettingsContext()
  10. const { t } = useTranslation()
  11. const { write } = usePermissionsContext()
  12. const allowedImageNames = useMemo(
  13. () => getMeta('ol-allowedImageNames') || [],
  14. []
  15. )
  16. const options: Array<Option> = useMemo(
  17. () =>
  18. allowedImageNames.map(({ imageName, imageDesc }) => ({
  19. value: imageName,
  20. label: imageDesc,
  21. })),
  22. [allowedImageNames]
  23. )
  24. if (allowedImageNames.length === 0) {
  25. return null
  26. }
  27. return (
  28. <DropdownSetting
  29. id="imageName"
  30. label={t('tex_live_version')}
  31. description={t('the_version_of_tex_live_used_for_compiling')}
  32. disabled={!write}
  33. options={options}
  34. onChange={setImageName}
  35. value={imageName}
  36. translateOptions="no"
  37. />
  38. )
  39. }