1- import React , { useRef , useEffect } from 'react' ;
1+ import React , { useRef } from 'react' ;
22import PropTypes from 'prop-types' ;
33import { withTranslation } from 'react-i18next' ;
44
@@ -23,58 +23,40 @@ import debugContrastUrl from '../../../images/console-debug-contrast.svg?byUrl';
2323import infoLightUrl from '../../../images/console-info-light.svg?byUrl' ;
2424import infoDarkUrl from '../../../images/console-info-dark.svg?byUrl' ;
2525import 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' ;
3426
3527import UpArrowIcon from '../../../images/up-arrow.svg' ;
3628import DownArrowIcon from '../../../images/down-arrow.svg' ;
3729
3830import * as IDEActions from '../../IDE/actions/ide' ;
3931import * 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' ;
4333
4434const getConsoleFeedStyle = ( theme , times , fontSize ) => {
45- const style = {
46- BASE_FONT_FAMILY : 'Inconsolata, monospace' ,
47- } ;
35+ const style = { } ;
4836 const CONSOLE_FEED_LIGHT_ICONS = {
4937 LOG_WARN_ICON : `url(${ warnLightUrl } )` ,
5038 LOG_ERROR_ICON : `url(${ errorLightUrl } )` ,
5139 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 } )`
5541 } ;
5642 const CONSOLE_FEED_DARK_ICONS = {
5743 LOG_WARN_ICON : `url(${ warnDarkUrl } )` ,
5844 LOG_ERROR_ICON : `url(${ errorDarkUrl } )` ,
5945 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 } )`
6347 } ;
6448 const CONSOLE_FEED_CONTRAST_ICONS = {
6549 LOG_WARN_ICON : `url(${ warnContrastUrl } )` ,
6650 LOG_ERROR_ICON : `url(${ errorContrastUrl } )` ,
6751 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 } )`
7153 } ;
7254 const CONSOLE_FEED_SIZES = {
7355 TREENODE_LINE_HEIGHT : 1.2 ,
7456 BASE_FONT_SIZE : fontSize ,
7557 ARROW_FONT_SIZE : fontSize ,
7658 LOG_ICON_WIDTH : fontSize ,
77- LOG_ICON_HEIGHT : 1.45 * fontSize
59+ LOG_ICON_HEIGHT : 1.45 * fontSize ,
7860 } ;
7961
8062 if ( times > 1 ) {
@@ -95,25 +77,21 @@ const getConsoleFeedStyle = (theme, times, fontSize) => {
9577const Console = ( { t } ) => {
9678 const consoleEvents = useSelector ( state => state . console ) ;
9779 const isExpanded = useSelector ( state => state . ide . consoleIsExpanded ) ;
98- const isPlaying = useSelector ( state => state . ide . isPlaying ) ;
9980 const { theme, fontSize } = useSelector ( state => state . preferences ) ;
10081
10182 const {
10283 collapseConsole, expandConsole, clearConsole, dispatchConsoleEvent
10384 } = bindActionCreators ( { ...IDEActions , ...ConsoleActions } , useDispatch ( ) ) ;
10485
86+ useDidUpdate ( ( ) => {
87+ clearConsole ( ) ;
88+ dispatchConsoleEvent ( consoleEvents ) ;
89+ } , [ theme , fontSize ] ) ;
90+
10591 const cm = useRef ( { } ) ;
10692
10793 useDidUpdate ( ( ) => { cm . current . scrollTop = cm . current . scrollHeight ; } ) ;
10894
109- const handleMessageEvent = useHandleMessageEvent ( ) ;
110- useEffect ( ( ) => {
111- const unsubscribe = listen ( handleMessageEvent ) ;
112- return function cleanup ( ) {
113- unsubscribe ( ) ;
114- } ;
115- } ) ;
116-
11795 const consoleClass = classNames ( {
11896 'preview-console' : true ,
11997 'preview-console--collapsed' : ! isExpanded
@@ -139,36 +117,26 @@ const Console = ({ t }) => {
139117 </ button >
140118 </ div >
141119 </ 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 }
161131 </ 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+ } ) }
172140 </ div >
173141 </ section >
174142 ) ;
0 commit comments