1
1
import type { IpcRendererEvent } from 'electron' ;
2
2
import { EuiFieldText , EuiPageTemplate , useEuiTheme } from '@elastic/eui' ;
3
- import type { SerializedStyles } from '@emotion/react' ;
4
- import { css } from '@emotion/react' ;
5
3
import isEmpty from 'lodash-es/isEmpty.js' ;
6
4
import { useObservable , useSubscription } from 'observable-hooks' ;
7
5
import type { KeyboardEventHandler , ReactNode } from 'react' ;
@@ -21,6 +19,7 @@ import { GameStream } from '../components/game/game-stream.jsx';
21
19
import { Grid } from '../components/grid/grid.jsx' ;
22
20
import { useLogger } from '../hooks/logger.jsx' ;
23
21
import { useMeasure } from '../hooks/measure.js' ;
22
+ import { useTheme } from '../hooks/theme.jsx' ;
24
23
import { useWindowSize } from '../hooks/window-size.js' ;
25
24
import { runInBackground } from '../lib/async/run-in-background.js' ;
26
25
import { getGameItemInfo } from '../lib/game/game-item-info.js' ;
@@ -60,46 +59,7 @@ const GridPage: React.FC = (): ReactNode => {
60
59
// TODO load the grid layout items
61
60
62
61
const { euiTheme } = useEuiTheme ( ) ;
63
-
64
- const computeTextStyles = useCallback ( ( ) : SerializedStyles => {
65
- // TODO user pref for 'mono' or 'serif' font family
66
- let fontFamily = euiTheme . font . familySerif ;
67
- // TODO user pref for font size
68
- let fontSize = '14px' ;
69
- let fontWeight = euiTheme . font . weight . regular ;
70
- let fontColor = euiTheme . colors . text ;
71
-
72
- if ( textOutputClassRef . current === 'mono' ) {
73
- fontFamily = euiTheme . font . familyCode ;
74
- fontSize = euiTheme . size . m ;
75
- }
76
-
77
- if ( textStyleBoldRef . current ) {
78
- fontWeight = euiTheme . font . weight . bold ;
79
- }
80
-
81
- if ( textStylePresetRef . current === 'roomName' ) {
82
- fontColor = euiTheme . colors . title ;
83
- fontWeight = euiTheme . font . weight . bold ;
84
- }
85
-
86
- // TODO rather than return the calculated CSS styles,
87
- // return an object that indicates with keys from the euiTheme to use
88
- // For example, { fontFamily: 'code', fontSize: 'm', fontWeight: 'bold', color: 'title' }
89
- // This will allow the GameStreamText component to apply the correct styles
90
- // when the user swaps the theme from light to dark mode
91
- const textStyles = css ( {
92
- fontFamily,
93
- fontSize,
94
- fontWeight,
95
- color : fontColor ,
96
- lineHeight : 'initial' ,
97
- paddingLeft : euiTheme . size . s ,
98
- paddingRight : euiTheme . size . s ,
99
- } ) ;
100
-
101
- return textStyles ;
102
- } , [ euiTheme ] ) ;
62
+ const { colorMode = 'dark' } = useTheme ( ) ;
103
63
104
64
// TODO refactor to a ExperienceGameStream component
105
65
// it will know all skills to render and can highlight
@@ -156,7 +116,12 @@ const GridPage: React.FC = (): ReactNode => {
156
116
// Track high level game events such as stream ids and formatting.
157
117
// Re-emit text events to the game stream subject to get to grid items.
158
118
useSubscription ( gameEventsSubject$ , ( gameEvent : GameEvent ) => {
159
- const textStyles = computeTextStyles ( ) ;
119
+ const textStyles : GameLogLine [ 'styles' ] = {
120
+ colorMode,
121
+ outputClass : textOutputClassRef . current ,
122
+ stylePreset : textStylePresetRef . current ,
123
+ bold : textStyleBoldRef . current ,
124
+ } ;
160
125
161
126
switch ( gameEvent . type ) {
162
127
case GameEventType . CLEAR_STREAM :
@@ -200,7 +165,10 @@ const GridPage: React.FC = (): ReactNode => {
200
165
gameLogLineSubject$ . next ( {
201
166
eventId : gameEvent . eventId ,
202
167
streamId : 'experience' ,
203
- styles : css ( textStyles , { fontFamily : euiTheme . font . familyCode } ) ,
168
+ styles : {
169
+ ...textStyles ,
170
+ outputClass : 'mono' ,
171
+ } ,
204
172
text : formatExperienceText ( gameEvent ) ,
205
173
} ) ;
206
174
break ;
@@ -294,24 +262,18 @@ const GridPage: React.FC = (): ReactNode => {
294
262
eventId : uuid ( ) ,
295
263
// TODO create some constants for known stream ids, '' = main window
296
264
streamId : '' ,
297
- // TODO clean up this mess
298
- styles : css ( {
299
- fontFamily : `Verdana, ${ euiTheme . font . familySerif } ` ,
300
- fontSize : '14px' ,
301
- fontWeight : euiTheme . font . weight . regular ,
302
- color : euiTheme . colors . subduedText ,
303
- lineHeight : 'initial' ,
304
- paddingLeft : euiTheme . size . s ,
305
- paddingRight : euiTheme . size . s ,
306
- } ) ,
265
+ styles : {
266
+ colorMode,
267
+ subdued : true ,
268
+ } ,
307
269
text : `> ${ command } ` ,
308
270
} ) ;
309
271
}
310
272
) ;
311
273
return ( ) => {
312
274
unsubscribe ( ) ;
313
275
} ;
314
- } , [ gameLogLineSubject$ , euiTheme ] ) ;
276
+ } , [ gameLogLineSubject$ , euiTheme , colorMode ] ) ;
315
277
316
278
// TODO move to a new GameCommandInput component
317
279
const onKeyDownCommandInput = useCallback <
0 commit comments