1
- import { Provider } from "react-redux" ;
1
+ import { Provider , useSelector } from "react-redux" ;
2
2
import React from "react" ;
3
3
import ReactDOM from "react-dom" ;
4
4
import window , { document } from "libs/window" ;
5
5
import rootSaga from "oxalis/model/sagas/root_saga" ;
6
- import UnthrottledStore , { startSagas } from "oxalis/store" ;
6
+ import UnthrottledStore , { OxalisState , startSagas } from "oxalis/store" ;
7
7
import { message , App , ConfigProvider , theme } from "antd" ;
8
8
9
9
import { getActiveUser , checkAnyOrganizationExists , getOrganization } from "admin/admin_rest_api" ;
@@ -27,6 +27,10 @@ import Model from "oxalis/model";
27
27
import { setupApi } from "oxalis/api/internal_api" ;
28
28
import { setActiveOrganizationAction } from "oxalis/model/actions/organization_actions" ;
29
29
import checkBrowserFeatures from "libs/browser_feature_check" ;
30
+ import { APIUserTheme } from "types/api_flow_types" ;
31
+ import { getSystemColorTheme } from "libs/utils" ;
32
+
33
+ import "../stylesheets/main.less" ;
30
34
31
35
// Suppress warning emitted by Olvy because it tries to eagerly initialize
32
36
window . OlvyConfig = null ;
@@ -88,6 +92,31 @@ async function loadOrganization() {
88
92
}
89
93
}
90
94
95
+ function getTheme ( userTheme : APIUserTheme ) {
96
+ if ( userTheme === "auto" ) {
97
+ userTheme = getSystemColorTheme ( ) ;
98
+ }
99
+
100
+ if ( userTheme === "dark" ) {
101
+ return theme . darkAlgorithm ;
102
+ }
103
+
104
+ return theme . defaultAlgorithm ;
105
+ }
106
+
107
+ function GlobalThemeProvider ( ) {
108
+ const activeUser = useSelector ( ( state : OxalisState ) => state . activeUser ) ;
109
+ const antdTheme = activeUser == null ? getTheme ( "auto" ) : getTheme ( activeUser . selectedTheme ) ;
110
+
111
+ return (
112
+ < ConfigProvider theme = { { algorithm : antdTheme , cssVar : { key : "antd-app-theme" } } } >
113
+ < App className = { antdTheme === theme . darkAlgorithm ? "dark-theme" : undefined } >
114
+ < Router />
115
+ </ App >
116
+ </ ConfigProvider >
117
+ ) ;
118
+ }
119
+
91
120
document . addEventListener ( "DOMContentLoaded" , async ( ) => {
92
121
ErrorHandling . initialize ( {
93
122
throwAssertions : false ,
@@ -110,13 +139,7 @@ document.addEventListener("DOMContentLoaded", async () => {
110
139
The fix is inspired by:
111
140
https://github.com/frontend-collective/react-sortable-tree/blob/9aeaf3d38b500d58e2bcc1d9b6febce12f8cc7b4/stories/barebones-no-context.js */ }
112
141
< DndProvider backend = { HTML5Backend } >
113
- < ConfigProvider
114
- theme = { { algorithm : theme . defaultAlgorithm , cssVar : { key : "antd-app-theme" } } }
115
- >
116
- < App >
117
- < Router />
118
- </ App >
119
- </ ConfigProvider >
142
+ < GlobalThemeProvider />
120
143
</ DndProvider >
121
144
</ QueryClientProvider >
122
145
</ Provider >
0 commit comments