11import { FocusStyleManager } from '@blueprintjs/core' ;
22import { IconNames } from '@blueprintjs/icons' ;
33import { Ace } from 'ace-builds' ;
4- import React from 'react' ;
4+ import React , { useCallback , useEffect , useState } from 'react' ;
55import { DraggableEvent } from 'react-draggable' ;
66import { useMediaQuery } from 'react-responsive' ;
77
@@ -30,16 +30,16 @@ export type MobileWorkspaceProps = {
3030const MobileWorkspace : React . FC < MobileWorkspaceProps > = props => {
3131 const isAndroid = / A n d r o i d / . test ( navigator . userAgent ) ;
3232 const isPortrait = useMediaQuery ( { orientation : 'portrait' } ) ;
33- const [ draggableReplPosition , setDraggableReplPosition ] = React . useState ( { x : 0 , y : 0 } ) ;
33+ const [ draggableReplPosition , setDraggableReplPosition ] = useState ( { x : 0 , y : 0 } ) ;
3434
3535 // For disabling draggable Repl when in stepper tab
36- const [ isDraggableReplDisabled , setIsDraggableReplDisabled ] = React . useState ( false ) ;
36+ const [ isDraggableReplDisabled , setIsDraggableReplDisabled ] = useState ( false ) ;
3737
3838 // Get rid of the focus border on blueprint components
3939 FocusStyleManager . onlyShowFocusOnTabs ( ) ;
4040
4141 // Handles the panel height when the mobile top controlbar is rendered in the Assessment Workspace
42- React . useEffect ( ( ) => {
42+ useEffect ( ( ) => {
4343 if ( props . mobileSideContentProps . workspaceLocation === 'assessment' ) {
4444 document . documentElement . style . setProperty (
4545 '--mobile-panel-height' ,
@@ -59,7 +59,7 @@ const MobileWorkspace: React.FC<MobileWorkspaceProps> = props => {
5959 * soft keyboard on Android devices. This is due to the viewport height changing when the soft
6060 * keyboard is up on Android devices. IOS devices are not affected.
6161 */
62- React . useEffect ( ( ) => {
62+ useEffect ( ( ) => {
6363 if ( isPortrait && isAndroid ) {
6464 document . documentElement . style . setProperty ( 'overflow' , 'auto' ) ;
6565 const metaViewport = document . querySelector ( 'meta[name=viewport]' ) ;
@@ -83,50 +83,38 @@ const MobileWorkspace: React.FC<MobileWorkspaceProps> = props => {
8383 } ;
8484 } , [ isPortrait , isAndroid ] ) ;
8585
86- const [ targetKeyboardInput , setTargetKeyboardInput ] = React . useState < Ace . Editor | null > ( null ) ;
86+ const [ targetKeyboardInput , setTargetKeyboardInput ] = useState < Ace . Editor | null > ( null ) ;
8787
8888 const clearTargetKeyboardInput = ( ) => setTargetKeyboardInput ( null ) ;
8989
9090 const enableMobileKeyboardForEditor = ( props : EditorContainerProps ) : EditorContainerProps => {
91- const onFocus = ( event : any , editor ?: Ace . Editor ) => {
92- if ( props . onFocus ) {
93- props . onFocus ( event , editor ) ;
94- }
95- if ( ! editor ) {
96- return ;
97- }
98- setTargetKeyboardInput ( editor ) ;
99- } ;
100- const onBlur = ( event : any , editor ?: Ace . Editor ) => {
101- if ( props . onBlur ) {
102- props . onBlur ( event , editor ) ;
103- }
104- clearTargetKeyboardInput ( ) ;
105- } ;
10691 return {
10792 ...props ,
108- onFocus,
109- onBlur
93+ onFocus : ( event , editor ?) => {
94+ props . onFocus ?.( event , editor ) ;
95+ if ( ! editor ) {
96+ return ;
97+ }
98+ setTargetKeyboardInput ( editor ) ;
99+ } ,
100+ onBlur : ( event , editor ?) => {
101+ props . onBlur ?.( event , editor ) ;
102+ clearTargetKeyboardInput ( ) ;
103+ }
110104 } ;
111105 } ;
112106
113107 const enableMobileKeyboardForRepl = ( props : ReplProps ) : ReplProps => {
114- const onFocus = ( editor : Ace . Editor ) => {
115- if ( props . onFocus ) {
116- props . onFocus ( editor ) ;
117- }
118- setTargetKeyboardInput ( editor ) ;
119- } ;
120- const onBlur = ( ) => {
121- if ( props . onBlur ) {
122- props . onBlur ( ) ;
123- }
124- clearTargetKeyboardInput ( ) ;
125- } ;
126108 return {
127109 ...props ,
128- onFocus,
129- onBlur
110+ onFocus : editor => {
111+ props . onFocus ?.( editor ) ;
112+ setTargetKeyboardInput ( editor ) ;
113+ } ,
114+ onBlur : ( ) => {
115+ props . onBlur ?.( ) ;
116+ clearTargetKeyboardInput ( ) ;
117+ }
130118 } ;
131119 } ;
132120
@@ -184,13 +172,11 @@ const MobileWorkspace: React.FC<MobileWorkspaceProps> = props => {
184172 } ;
185173
186174 const handleEditorEval = props . editorContainerProps ?. handleEditorEval ;
187- const handleTabChangeForRepl = React . useCallback (
175+ const handleTabChangeForRepl = useCallback (
188176 ( newTabId : SideContentType , prevTabId : SideContentType ) => {
189177 // Evaluate program upon pressing the run tab.
190178 if ( newTabId === SideContentType . mobileEditorRun ) {
191- if ( handleEditorEval ) {
192- handleEditorEval ( ) ;
193- }
179+ handleEditorEval ?.( ) ;
194180 }
195181
196182 // Show the REPL upon pressing the run tab if the previous tab is not listed below.
@@ -226,7 +212,7 @@ const MobileWorkspace: React.FC<MobileWorkspaceProps> = props => {
226212 ) ;
227213
228214 const onChange = props . mobileSideContentProps . onChange ;
229- const onSideContentTabChange = React . useCallback (
215+ const onSideContentTabChange = useCallback (
230216 (
231217 newTabId : SideContentType ,
232218 prevTabId : SideContentType ,
@@ -241,27 +227,7 @@ const MobileWorkspace: React.FC<MobileWorkspaceProps> = props => {
241227 // Convert sidebar tabs with a side content tab ID into side content tabs.
242228 const sideBarTabs : SideContentTab [ ] = props . sideBarProps . tabs . filter ( tab => tab . id !== undefined ) ;
243229
244- const mobileEditorTab : SideContentTab = React . useMemo (
245- ( ) => ( {
246- label : 'Editor' ,
247- iconName : IconNames . EDIT ,
248- body : null ,
249- id : SideContentType . mobileEditor
250- } ) ,
251- [ ]
252- ) ;
253-
254- const mobileRunTab : SideContentTab = React . useMemo (
255- ( ) => ( {
256- label : 'Run' ,
257- iconName : IconNames . PLAY ,
258- body : null ,
259- id : SideContentType . mobileEditorRun
260- } ) ,
261- [ ]
262- ) ;
263-
264- const updatedMobileSideContentProps = React . useCallback ( ( ) => {
230+ const updatedMobileSideContentProps = useCallback ( ( ) => {
265231 return {
266232 ...props . mobileSideContentProps ,
267233 onChange : onSideContentTabChange ,
@@ -277,13 +243,7 @@ const MobileWorkspace: React.FC<MobileWorkspaceProps> = props => {
277243 ]
278244 }
279245 } ;
280- } , [
281- onSideContentTabChange ,
282- mobileEditorTab ,
283- mobileRunTab ,
284- props . mobileSideContentProps ,
285- sideBarTabs
286- ] ) ;
246+ } , [ onSideContentTabChange , props . mobileSideContentProps , sideBarTabs ] ) ;
287247
288248 const inAssessmentWorkspace = props . mobileSideContentProps . workspaceLocation === 'assessment' ;
289249
@@ -318,3 +278,17 @@ const MobileWorkspace: React.FC<MobileWorkspaceProps> = props => {
318278} ;
319279
320280export default MobileWorkspace ;
281+
282+ const mobileEditorTab : SideContentTab = {
283+ label : 'Editor' ,
284+ iconName : IconNames . EDIT ,
285+ body : null ,
286+ id : SideContentType . mobileEditor
287+ } ;
288+
289+ const mobileRunTab : SideContentTab = {
290+ label : 'Run' ,
291+ iconName : IconNames . PLAY ,
292+ body : null ,
293+ id : SideContentType . mobileEditorRun
294+ } ;
0 commit comments