Skip to content

Commit 4ce0022

Browse files
authored
RI-7754: improve system theme handling (#5248)
* remove ThemeComponent.tsx, because its functionality is redundant
1 parent dee9d34 commit 4ce0022

File tree

4 files changed

+10
-48
lines changed

4 files changed

+10
-48
lines changed

redisinsight/ui/src/App.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
} from './components'
2020
import { ThemeProvider } from './contexts/themeContext'
2121
import MainComponent from './components/main/MainComponent'
22-
import ThemeComponent from './components/theme/ThemeComponent'
2322
import MonacoEnvironmentInitializer from './components/MonacoEnvironmentInitializer/MonacoEnvironmentInitializer'
2423
import GlobalDialogs from './components/global-dialogs'
2524
import NotFoundErrorPage from './pages/not-found-error/NotFoundErrorPage'
@@ -51,7 +50,6 @@ const App = ({ children }: { children?: ReactElement[] }) => {
5150
}, [serverLoading])
5251
return (
5352
<div className="main-container">
54-
<ThemeComponent />
5553
<MonacoEnvironmentInitializer />
5654
<Switch>
5755
<Route exact path={Pages.notFound} component={NotFoundErrorPage} />

redisinsight/ui/src/components/theme/ThemeComponent.spec.tsx

Lines changed: 0 additions & 10 deletions
This file was deleted.

redisinsight/ui/src/components/theme/ThemeComponent.tsx

Lines changed: 0 additions & 34 deletions
This file was deleted.

redisinsight/ui/src/contexts/themeContext.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react'
1+
import React, { useContext } from 'react'
22
import { ThemeProvider as StyledThemeProvider } from 'styled-components'
33
import {
44
theme as redisUiOldTheme,
@@ -44,6 +44,10 @@ export const defaultState = {
4444
},
4545
}
4646

47+
export const isValidTheme = (theme: unknown): theme is Theme => {
48+
return typeof theme === 'string' && THEME_NAMES.includes(theme as Theme)
49+
}
50+
4751
export const ThemeContext = React.createContext(defaultState)
4852

4953
export class ThemeProvider extends React.Component<Props> {
@@ -57,7 +61,7 @@ export class ThemeProvider extends React.Component<Props> {
5761

5862
if (queryTheme) {
5963
theme = queryTheme
60-
} else if (storedThemeValue && THEME_NAMES.includes(storedThemeValue)) {
64+
} else if (storedThemeValue && isValidTheme(storedThemeValue)) {
6165
theme = storedThemeValue
6266
}
6367

@@ -120,5 +124,9 @@ export class ThemeProvider extends React.Component<Props> {
120124
)
121125
}
122126
}
127+
128+
export const useThemeContext = () => {
129+
return useContext(ThemeContext)
130+
}
123131

124132
export default ThemeProvider

0 commit comments

Comments
 (0)