Skip to content

Commit 52c3c36

Browse files
committed
Revert "Converted app to class for consistency"
This reverts commit 2e30fb4.
1 parent 2e30fb4 commit 52c3c36

File tree

1 file changed

+47
-54
lines changed

1 file changed

+47
-54
lines changed

src/App.tsx

+47-54
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { App as AntdApp, ConfigProvider, theme } from 'antd'
2-
import React from 'react'
2+
import { useState } from 'react'
33
import { Provider } from 'react-redux'
44
import { HashRouter, Route, Switch } from 'react-router-dom'
55
import { applyMiddleware, createStore } from 'redux'
@@ -10,72 +10,65 @@ import DarkModeContext from './contexts/DarkModeContext'
1010
import reducers from './redux/reducers'
1111
import './styles/style.css'
1212
import CrashReporter from './utils/CrashReporter'
13-
import { getCurrentLanguageOption, LanguageOption } from './utils/Language'
13+
import { getCurrentLanguageOption } from './utils/Language'
1414
import StorageHelper from './utils/StorageHelper'
1515

1616
CrashReporter.getInstance().init()
1717

1818
const createStoreWithMiddleware = applyMiddleware(thunk)(createStore)
1919
const store = createStoreWithMiddleware(reducers)
2020

21-
class App extends React.Component<
22-
any,
23-
{ isDarkMode: boolean; currentLanguageOption: LanguageOption }
24-
> {
25-
constructor(props: any) {
26-
super(props)
27-
this.state = {
28-
isDarkMode: StorageHelper.getDarkModeFromLocalStorage(),
29-
currentLanguageOption: getCurrentLanguageOption(),
30-
}
31-
}
21+
const MainComponent = () => {
22+
return (
23+
<AntdApp className="full-screen">
24+
<HashRouter>
25+
<Switch>
26+
<Route path="/login/" component={Login} />
27+
<Route path="/" component={PageRoot} />
28+
</Switch>
29+
</HashRouter>
30+
</AntdApp>
31+
)
32+
}
3233

33-
render() {
34-
const { defaultAlgorithm, darkAlgorithm } = theme
35-
const currentLanguageOption = this.state.currentLanguageOption
34+
function App() {
35+
const { defaultAlgorithm, darkAlgorithm } = theme
36+
const [isDarkMode, setIsDarkMode] = useState(
37+
StorageHelper.getDarkModeFromLocalStorage()
38+
)
3639

37-
const self = this
40+
const currentLanguageOption = getCurrentLanguageOption()
3841

39-
return (
40-
<ConfigProvider
41-
direction={currentLanguageOption.rtl ? 'rtl' : 'ltr'}
42-
theme={{
43-
algorithm: this.state.isDarkMode
44-
? darkAlgorithm
45-
: defaultAlgorithm,
46-
token: {
47-
colorPrimary: '#1b8ad3',
48-
colorLink: '#1b8ad3',
49-
fontFamily: `QuickSand, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
50-
'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji',
51-
'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'`,
42+
return (
43+
<ConfigProvider
44+
direction={currentLanguageOption.rtl ? 'rtl' : 'ltr'}
45+
theme={{
46+
algorithm: isDarkMode ? darkAlgorithm : defaultAlgorithm,
47+
token: {
48+
colorPrimary: '#1b8ad3',
49+
colorLink: '#1b8ad3',
50+
fontFamily: `QuickSand, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
51+
'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji',
52+
'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'`,
53+
},
54+
}}
55+
locale={currentLanguageOption.antdLocale}
56+
>
57+
<DarkModeContext.Provider
58+
value={{
59+
isDarkMode,
60+
setIsDarkMode: (value) => {
61+
setIsDarkMode(value)
62+
StorageHelper.setDarkModeInLocalStorage(value)
5263
},
5364
}}
54-
locale={currentLanguageOption.antdLocale}
5565
>
56-
<DarkModeContext.Provider
57-
value={{
58-
isDarkMode: this.state.isDarkMode,
59-
setIsDarkMode: (value: boolean) => {
60-
self.setState({ isDarkMode: value })
61-
StorageHelper.setDarkModeInLocalStorage(value)
62-
},
63-
}}
64-
>
65-
<Provider store={store}>
66-
<AntdApp className="full-screen">
67-
<HashRouter>
68-
<Switch>
69-
<Route path="/login/" component={Login} />
70-
<Route path="/" component={PageRoot} />
71-
</Switch>
72-
</HashRouter>
73-
</AntdApp>
74-
</Provider>
75-
</DarkModeContext.Provider>
76-
</ConfigProvider>
77-
)
78-
}
66+
<Provider store={store}>
67+
<MainComponent />
68+
</Provider>
69+
</DarkModeContext.Provider>
70+
</ConfigProvider>
71+
)
7972
}
8073

8174
export default App

0 commit comments

Comments
 (0)