settings-image-name.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { useMemo } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import getMeta from '../../../../utils/meta'
  4. import SettingsMenuSelect from './settings-menu-select'
  5. import type { Option } from './settings-menu-select'
  6. import { useProjectSettingsContext } from '../../context/project-settings-context'
  7. import type { AllowedImageName } from '../../../../../../types/project-settings'
  8. export default function SettingsImageName() {
  9. const { t } = useTranslation()
  10. const { imageName, setImageName } = useProjectSettingsContext()
  11. const allowedImageNames = getMeta('ol-allowedImageNames') as
  12. | AllowedImageName[]
  13. | undefined
  14. const options: Array<Option> = useMemo(
  15. () =>
  16. allowedImageNames?.map(({ imageName, imageDesc }) => ({
  17. value: imageName,
  18. label: imageDesc,
  19. })) ?? [],
  20. [allowedImageNames]
  21. )
  22. if ((allowedImageNames?.length ?? 0) === 0) {
  23. return null
  24. }
  25. return (
  26. <SettingsMenuSelect
  27. onChange={setImageName}
  28. value={imageName}
  29. options={options}
  30. label={t('tex_live_version')}
  31. name="imageName"
  32. />
  33. )
  34. }