settings-overall-theme.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. export default function SettingsOverallTheme() {
  10. const { t } = useTranslation()
  11. const overallThemes = getMeta('ol-overallThemes') as
  12. | OverallThemeMeta[]
  13. | undefined
  14. const { loadingStyleSheet } = useLayoutContext()
  15. const { overallTheme, setOverallTheme } = useProjectSettingsContext()
  16. const options: Array<Option<OverallTheme>> = useMemo(
  17. () =>
  18. overallThemes?.map(({ name, val }) => ({
  19. value: val,
  20. label: name,
  21. })) ?? [],
  22. [overallThemes]
  23. )
  24. const brandVariation = getMeta('ol-brandVariation')
  25. const { ieeeBrandId } = getMeta('ol-ExposedSettings')
  26. const isIEEEBranded = brandVariation?.brand_id === ieeeBrandId
  27. if (!overallThemes || isIEEEBranded) {
  28. return null
  29. }
  30. return (
  31. <SettingsMenuSelect<OverallTheme>
  32. onChange={setOverallTheme}
  33. value={overallTheme}
  34. options={options}
  35. loading={loadingStyleSheet}
  36. label={t('overall_theme')}
  37. name="overallTheme"
  38. />
  39. )
  40. }