1
- import React , { useRef , useEffect } from 'react' ;
1
+ import React , { useRef } from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
3
import { withTranslation } from 'react-i18next' ;
4
4
@@ -23,58 +23,40 @@ import debugContrastUrl from '../../../images/console-debug-contrast.svg?byUrl';
23
23
import infoLightUrl from '../../../images/console-info-light.svg?byUrl' ;
24
24
import infoDarkUrl from '../../../images/console-info-dark.svg?byUrl' ;
25
25
import infoContrastUrl from '../../../images/console-info-contrast.svg?byUrl' ;
26
- import ConsoleInput from './ConsoleInput' ;
27
-
28
- import commandLightUrl from '../../../images/console-command-light.svg?byUrl' ;
29
- import resultLightUrl from '../../../images/console-result-light.svg?byUrl' ;
30
- import commandDarkUrl from '../../../images/console-command-dark.svg?byUrl' ;
31
- import resultDarkUrl from '../../../images/console-result-dark.svg?byUrl' ;
32
- import commandContrastUrl from '../../../images/console-command-contrast.svg?byUrl' ;
33
- import resultContrastUrl from '../../../images/console-result-contrast.svg?byUrl' ;
34
26
35
27
import UpArrowIcon from '../../../images/up-arrow.svg' ;
36
28
import DownArrowIcon from '../../../images/down-arrow.svg' ;
37
29
38
30
import * as IDEActions from '../../IDE/actions/ide' ;
39
31
import * as ConsoleActions from '../../IDE/actions/console' ;
40
- import { useDidUpdate } from '../hooks/custom-hooks' ;
41
- import useHandleMessageEvent from '../hooks/useHandleMessageEvent' ;
42
- import { listen } from '../../../utils/dispatcher' ;
32
+ import { useDidUpdate } from '../../../utils/custom-hooks' ;
43
33
44
34
const getConsoleFeedStyle = ( theme , times , fontSize ) => {
45
- const style = {
46
- BASE_FONT_FAMILY : 'Inconsolata, monospace' ,
47
- } ;
35
+ const style = { } ;
48
36
const CONSOLE_FEED_LIGHT_ICONS = {
49
37
LOG_WARN_ICON : `url(${ warnLightUrl } )` ,
50
38
LOG_ERROR_ICON : `url(${ errorLightUrl } )` ,
51
39
LOG_DEBUG_ICON : `url(${ debugLightUrl } )` ,
52
- LOG_INFO_ICON : `url(${ infoLightUrl } )` ,
53
- LOG_COMMAND_ICON : `url(${ commandLightUrl } )` ,
54
- LOG_RESULT_ICON : `url(${ resultLightUrl } )`
40
+ LOG_INFO_ICON : `url(${ infoLightUrl } )`
55
41
} ;
56
42
const CONSOLE_FEED_DARK_ICONS = {
57
43
LOG_WARN_ICON : `url(${ warnDarkUrl } )` ,
58
44
LOG_ERROR_ICON : `url(${ errorDarkUrl } )` ,
59
45
LOG_DEBUG_ICON : `url(${ debugDarkUrl } )` ,
60
- LOG_INFO_ICON : `url(${ infoDarkUrl } )` ,
61
- LOG_COMMAND_ICON : `url(${ commandDarkUrl } )` ,
62
- LOG_RESULT_ICON : `url(${ resultDarkUrl } )`
46
+ LOG_INFO_ICON : `url(${ infoDarkUrl } )`
63
47
} ;
64
48
const CONSOLE_FEED_CONTRAST_ICONS = {
65
49
LOG_WARN_ICON : `url(${ warnContrastUrl } )` ,
66
50
LOG_ERROR_ICON : `url(${ errorContrastUrl } )` ,
67
51
LOG_DEBUG_ICON : `url(${ debugContrastUrl } )` ,
68
- LOG_INFO_ICON : `url(${ infoContrastUrl } )` ,
69
- LOG_COMMAND_ICON : `url(${ commandContrastUrl } )` ,
70
- LOG_RESULT_ICON : `url(${ resultContrastUrl } )`
52
+ LOG_INFO_ICON : `url(${ infoContrastUrl } )`
71
53
} ;
72
54
const CONSOLE_FEED_SIZES = {
73
55
TREENODE_LINE_HEIGHT : 1.2 ,
74
56
BASE_FONT_SIZE : fontSize ,
75
57
ARROW_FONT_SIZE : fontSize ,
76
58
LOG_ICON_WIDTH : fontSize ,
77
- LOG_ICON_HEIGHT : 1.45 * fontSize
59
+ LOG_ICON_HEIGHT : 1.45 * fontSize ,
78
60
} ;
79
61
80
62
if ( times > 1 ) {
@@ -95,25 +77,21 @@ const getConsoleFeedStyle = (theme, times, fontSize) => {
95
77
const Console = ( { t } ) => {
96
78
const consoleEvents = useSelector ( state => state . console ) ;
97
79
const isExpanded = useSelector ( state => state . ide . consoleIsExpanded ) ;
98
- const isPlaying = useSelector ( state => state . ide . isPlaying ) ;
99
80
const { theme, fontSize } = useSelector ( state => state . preferences ) ;
100
81
101
82
const {
102
83
collapseConsole, expandConsole, clearConsole, dispatchConsoleEvent
103
84
} = bindActionCreators ( { ...IDEActions , ...ConsoleActions } , useDispatch ( ) ) ;
104
85
86
+ useDidUpdate ( ( ) => {
87
+ clearConsole ( ) ;
88
+ dispatchConsoleEvent ( consoleEvents ) ;
89
+ } , [ theme , fontSize ] ) ;
90
+
105
91
const cm = useRef ( { } ) ;
106
92
107
93
useDidUpdate ( ( ) => { cm . current . scrollTop = cm . current . scrollHeight ; } ) ;
108
94
109
- const handleMessageEvent = useHandleMessageEvent ( ) ;
110
- useEffect ( ( ) => {
111
- const unsubscribe = listen ( handleMessageEvent ) ;
112
- return function cleanup ( ) {
113
- unsubscribe ( ) ;
114
- } ;
115
- } ) ;
116
-
117
95
const consoleClass = classNames ( {
118
96
'preview-console' : true ,
119
97
'preview-console--collapsed' : ! isExpanded
@@ -139,36 +117,26 @@ const Console = ({ t }) => {
139
117
</ button >
140
118
</ div >
141
119
</ header >
142
- < div className = "preview-console__body" >
143
- < div ref = { cm } className = "preview-console__messages" >
144
- { consoleEvents . map ( ( consoleEvent ) => {
145
- const { method, times } = consoleEvent ;
146
- return (
147
- < div key = { consoleEvent . id } className = { `preview-console__message preview-console__message--${ method } ` } >
148
- { times > 1 &&
149
- < div
150
- className = "preview-console__logged-times"
151
- style = { { fontSize, borderRadius : fontSize / 2 } }
152
- >
153
- { times }
154
- </ div >
155
- }
156
- < ConsoleFeed
157
- styles = { getConsoleFeedStyle ( theme , times , fontSize ) }
158
- logs = { [ consoleEvent ] }
159
- key = { `${ consoleEvent . id } -${ theme } -${ fontSize } ` }
160
- />
120
+ < div ref = { cm } className = "preview-console__messages" >
121
+ { consoleEvents . map ( ( consoleEvent ) => {
122
+ const { method, times } = consoleEvent ;
123
+ return (
124
+ < div key = { consoleEvent . id } className = { `preview-console__message preview-console__message--${ method } ` } >
125
+ { times > 1 &&
126
+ < div
127
+ className = "preview-console__logged-times"
128
+ style = { { fontSize, borderRadius : fontSize / 2 } }
129
+ >
130
+ { times }
161
131
</ div >
162
- ) ;
163
- } ) }
164
- </ div >
165
- { isExpanded && isPlaying &&
166
- < ConsoleInput
167
- theme = { theme }
168
- dispatchConsoleEvent = { dispatchConsoleEvent }
169
- fontSize = { fontSize }
170
- />
171
- }
132
+ }
133
+ < ConsoleFeed
134
+ styles = { getConsoleFeedStyle ( theme , times , fontSize ) }
135
+ logs = { [ consoleEvent ] }
136
+ />
137
+ </ div >
138
+ ) ;
139
+ } ) }
172
140
</ div >
173
141
</ section >
174
142
) ;
0 commit comments