settings-overall-theme.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { useMemo } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import { useLayoutContext } from '../../../../shared/context/layout-context'
  4. import getMeta from '../../../../utils/meta'
  5. import SettingsMenuSelect, { Option } from './settings-menu-select'
  6. import { useProjectSettingsContext } from '../../context/project-settings-context'
  7. import type { OverallThemeMeta } from '../../../../../../types/project-settings'
  8. import type { OverallTheme } from '../../../source-editor/extensions/theme'
  9. import { ExposedSettings } from '../../../../../../types/exposed-settings'
  10. export default function SettingsOverallTheme() {
  11. const { t } = useTranslation()
  12. const overallThemes = getMeta('ol-overallThemes') as
  13. | OverallThemeMeta[]
  14. | undefined
  15. const { loadingStyleSheet } = useLayoutContext()
  16. const { overallTheme, setOverallTheme } = useProjectSettingsContext()
  17. const options: Array<Option<OverallTheme>> = useMemo(
  18. () =>
  19. overallThemes?.map(({ name, val }) => ({
  20. value: val,
  21. label: name,
  22. })) ?? [],
  23. [overallThemes]
  24. )
  25. const brandVariation = getMeta('ol-brandVariation') as any
  26. const { ieeeBrandId } = getMeta('ol-ExposedSettings') as ExposedSettings
  27. const isIEEEBranded = brandVariation?.brand_id === ieeeBrandId
  28. if (!overallThemes || isIEEEBranded) {
  29. return null
  30. }
  31. return (
  32. <SettingsMenuSelect<OverallTheme>
  33. onChange={setOverallTheme}
  34. value={overallTheme}
  35. options={options}
  36. loading={loadingStyleSheet}
  37. label={t('overall_theme')}
  38. name="overallTheme"
  39. />
  40. )
  41. }