Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions redisinsight/ui/src/components/theme/ThemeComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import React, { useContext, useEffect } from 'react'
import React, { useEffect } from 'react'
import {
BrowserStorageItem,
Theme,
THEME_MATCH_MEDIA_DARK,
} from 'uiSrc/constants'
import { localStorageService } from 'uiSrc/services'
import { ThemeContext } from 'uiSrc/contexts/themeContext'
import { useThemeContext } from 'uiSrc/contexts/themeContext'

const ThemeComponent = () => {
const themeContext = useContext(ThemeContext)
const themeContext = useThemeContext()
useEffect(() => {
const handler = (event) => {
const handler = () => {
let theme = localStorageService.get(BrowserStorageItem.theme)
if (theme === Theme.System) {
if (theme === Theme.System && themeContext.usingSystemTheme) {

Check warning on line 15 in redisinsight/ui/src/components/theme/ThemeComponent.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 15 in redisinsight/ui/src/components/theme/ThemeComponent.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
themeContext.changeTheme(theme)
}

Check warning on line 17 in redisinsight/ui/src/components/theme/ThemeComponent.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 17 in redisinsight/ui/src/components/theme/ThemeComponent.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
}
Expand Down
10 changes: 9 additions & 1 deletion redisinsight/ui/src/contexts/themeContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useContext } from 'react'
import { ThemeProvider as StyledThemeProvider } from 'styled-components'
import {
theme as redisUiOldTheme,
Expand Down Expand Up @@ -121,4 +121,12 @@
}
}

export const useThemeContext = () => {
const context = useContext(ThemeContext)
if (context === undefined) {
throw new Error('useThemeContext must be used within a ThemeProvider')

Check warning on line 127 in redisinsight/ui/src/contexts/themeContext.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 128 in redisinsight/ui/src/contexts/themeContext.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
return context
}

export default ThemeProvider
Loading