Skip to content

Commit

Permalink
feat: TryQuiet#1502 get light/dark from native theme and access it th…
Browse files Browse the repository at this point in the history
…rough DRY function
  • Loading branch information
mike-kiss committed May 13, 2024
1 parent 17c1c67 commit 4d80746
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/desktop/src/renderer/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import SentryWarning from './containers/widgets/sentryWarning/sentryWarning'
import SettingsModal from './components/Settings/Settings'
import UpdateModal from './containers/widgets/update/UpdateModal'
import QuitAppDialog from './containers/ui/QuitAppDialog'
import { lightTheme, darkTheme } from './theme'
import { getTheme } from './theme'
import CreateCommunity from './components/CreateJoinCommunity/CreateCommunity/CreateCommunity'
import JoinCommunity from './components/CreateJoinCommunity/JoinCommunity/JoinCommunity'
import CreateChannel from './components/Channel/CreateChannel/CreateChannel'
Expand Down Expand Up @@ -43,7 +43,7 @@ export const persistor = persistStore(store)
export default () => {
return (
<StyledEngineProvider injectFirst>
<ThemeProvider theme={darkTheme}>
<ThemeProvider theme={getTheme()}>
<DndProvider backend={HTML5Backend}>
<HashRouter>
<Provider store={store}>
Expand Down
3 changes: 2 additions & 1 deletion packages/desktop/src/renderer/components/Titlebar.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { useTheme } from '@mui/material'
import { Titlebar, Color } from 'custom-electron-titlebar'

import { lightTheme as theme } from '../theme'
import { getTheme } from '../theme'

export const addTitlebar = () => {
const theme = getTheme()
setTimeout(() => {
// eslint-disable-next-line
const titlebar = new Titlebar({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React from 'react'
import { lightTheme as theme } from '../../../theme'
import { getTheme } from '../../../theme'
import { ThemeProvider, StyledEngineProvider } from '@mui/material/styles'
import { WelcomeMessage } from './WelcomeMessage'
import { renderComponent } from '../../../testUtils/renderComponent'

describe('WelcomeMessage', () => {
it('renders component', () => {
const theme = getTheme()

const result = renderComponent(
<StyledEngineProvider injectFirst>
<ThemeProvider theme={theme}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React from 'react'
import { lightTheme as theme } from '../../../theme'
import { getTheme } from '../../../theme'
import { ThemeProvider } from '@mui/material/styles'
import { renderComponent } from '../../../testUtils/renderComponent'
import PossibleImpersonationAttackModalComponent from './PossibleImpersonationAttackModal.component'

describe('PossibleImpersonationAttackModal', () => {
it('renderComponent', () => {
const theme = getTheme()

const result = renderComponent(
<ThemeProvider theme={theme}>
<PossibleImpersonationAttackModalComponent handleClose={() => {}} open={true} communityName={'devteam'} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import { ComponentStory, ComponentMeta } from '@storybook/react'
import UpdateModal, { UpdateModalProps } from './UpdateModalComponent'

import { withTheme } from '../../../storybook/decorators'
import { lightTheme as theme } from '../../../theme'
import { getTheme } from '../../../theme'

import Button from '@mui/material/Button'

const theme = getTheme()

const Template: ComponentStory<typeof UpdateModal> = args => {
return <UpdateModal {...args} />
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React from 'react'
import { lightTheme as theme } from '../../../theme'
import { getTheme } from '../../../theme'
import { ThemeProvider } from '@mui/material/styles'
import { renderComponent } from '../../../testUtils/renderComponent'
import UserLabel from './UserLabel.component'
import { payloadDuplicated, payloadUnregistered, UserLabelType } from './UserLabel.types'

const theme = getTheme()

describe('UserLabel', () => {
it('duplicate', () => {
const result = renderComponent(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react'
import { lightTheme as theme } from '../../../../theme'
import { getTheme } from '../../../../theme'
import { ThemeProvider } from '@mui/material/styles'
import { renderComponent } from '../../../../testUtils/renderComponent'
import DuplicateModalComponent from './DuplicateModal.component'

const theme = getTheme()

describe('DuplicateModalComponent', () => {
it('renderComponent', () => {
const result = renderComponent(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react'
import { lightTheme as theme } from '../../../../theme'
import { getTheme } from '../../../../theme'
import { ThemeProvider } from '@mui/material/styles'
import { renderComponent } from '../../../../testUtils/renderComponent'
import UnregisteredModalComponent from './UnregisteredModal.component'

const theme = getTheme()

describe('UnregisteredModalComponent', () => {
it('renderComponent', () => {
const result = renderComponent(
Expand Down
4 changes: 3 additions & 1 deletion packages/desktop/src/renderer/storybook/decorators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import React from 'react'
import { Provider } from 'react-redux'
import { ThemeProvider, StyledEngineProvider } from '@mui/material/styles'

import { lightTheme as theme } from '../theme'
import { getTheme } from '../theme'
import { Store } from '../sagas/store.types'

const theme = getTheme()

export const withStore = (store: Store) => (Story: React.FC) => (
<Provider store={store}>
<Story />
Expand Down
4 changes: 3 additions & 1 deletion packages/desktop/src/renderer/testUtils/renderComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { Provider } from 'react-redux'

import { render } from '@testing-library/react'

import { lightTheme as theme } from '../theme'
import { getTheme } from '../theme'
import store from '../store'
import { Store } from 'redux'
import { DndProvider } from 'react-dnd'
import { HTML5Backend } from 'react-dnd-html5-backend'

const theme = getTheme()

interface Props {
children?: React.ReactNode
}
Expand Down
9 changes: 7 additions & 2 deletions packages/desktop/src/renderer/theme.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createTheme } from '@mui/material/styles'
import { nativeTheme } from '@electron/remote'
import { createTheme, type Theme } from '@mui/material/styles'

const font = "'Rubik', sans-serif"
const fontLogs = 'Menlo Regular'
Expand Down Expand Up @@ -386,4 +387,8 @@ const darkTheme = createTheme({
},
})

export { lightTheme, darkTheme }
const getTheme = (): Theme => {
return nativeTheme?.shouldUseDarkColors ? darkTheme : lightTheme
}

export { lightTheme, darkTheme, getTheme }

0 comments on commit 4d80746

Please sign in to comment.