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