aboutsummaryrefslogtreecommitdiff
path: root/modern/src/AppThemeProvider.jsx
blob: 109d25c41b9e9b2f197332f33ad0f8a602d00f60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import React from 'react';
import { useSelector } from 'react-redux';
import { ThemeProvider, useMediaQuery } from '@mui/material';
import theme from './common/theme';

const AppThemeProvider = ({ children }) => {
  const server = useSelector((state) => state.session.server);

  const serverDarkMode = server?.attributes?.darkMode;
  const preferDarkMode = useMediaQuery('(prefers-color-scheme: dark)');
  const darkMode = serverDarkMode !== undefined ? serverDarkMode : preferDarkMode;

  const themeInstance = theme(server, darkMode);

  return (
    <ThemeProvider theme={themeInstance}>
      {children}
    </ThemeProvider>
  );
};

export default AppThemeProvider;