1- import { FSModule } from 'browserfs/dist/node/core/FS' ;
1+ import type { FSModule } from 'browserfs/dist/node/core/FS' ;
22import { Chapter } from 'js-slang/dist/types' ;
33import { compressToEncodedURIComponent } from 'lz-string' ;
44import qs from 'query-string' ;
5- import { SagaIterator } from 'redux-saga' ;
65import { call , delay , put , race , select } from 'redux-saga/effects' ;
76import CseMachine from 'src/features/cseMachine/CseMachine' ;
87import { CseMachine as JavaCseMachine } from 'src/features/cseMachine/java/CseMachine' ;
@@ -14,21 +13,20 @@ import {
1413 type OverallState
1514} from '../application/ApplicationTypes' ;
1615import { retrieveFilesInWorkspaceAsRecord } from '../fileSystem/utils' ;
16+ import { combineSagaHandlers } from '../redux/utils' ;
1717import { visitSideContent } from '../sideContent/SideContentActions' ;
1818import { SideContentType } from '../sideContent/SideContentTypes' ;
1919import Constants from '../utils/Constants' ;
2020import { showSuccessMessage , showWarningMessage } from '../utils/notifications/NotificationsHelper' ;
2121import WorkspaceActions from '../workspace/WorkspaceActions' ;
22- import { safeTakeEvery as takeEvery , selectWorkspace } from './SafeEffects' ;
22+ import { selectWorkspace } from './SafeEffects' ;
2323
24- export default function * PlaygroundSaga ( ) : SagaIterator {
25- yield takeEvery ( PlaygroundActions . generateLzString . type , updateQueryString ) ;
26-
27- yield takeEvery (
28- PlaygroundActions . shortenURL . type ,
29- function * ( action : ReturnType < typeof PlaygroundActions . shortenURL > ) : any {
24+ const PlaygroundSaga = combineSagaHandlers (
25+ PlaygroundActions ,
26+ {
27+ generateLzString : updateQueryString ,
28+ shortenURL : function * ( { payload : keyword } ) {
3029 const queryString = yield select ( ( state : OverallState ) => state . playground . queryString ) ;
31- const keyword = action . payload ;
3230 const errorMsg = 'ERROR' ;
3331
3432 let resp , timeout ;
@@ -59,72 +57,76 @@ export default function* PlaygroundSaga(): SagaIterator {
5957 }
6058 yield put ( PlaygroundActions . updateShortURL ( Constants . urlShortenerBase + resp . url . keyword ) ) ;
6159 }
62- ) ;
63-
64- yield takeEvery (
65- visitSideContent . type ,
66- function * ( {
67- payload : { newId, prevId, workspaceLocation }
68- } : ReturnType < typeof visitSideContent > ) {
69- if ( workspaceLocation !== 'playground' || newId === prevId ) return ;
60+ } ,
61+ function * ( takeEvery ) {
62+ yield takeEvery (
63+ visitSideContent ,
64+ function * ( { payload : { newId, prevId, workspaceLocation } } ) {
65+ if ( workspaceLocation !== 'playground' || newId === prevId ) return ;
66+
67+ // Do nothing when clicking the mobile 'Run' tab while on the stepper tab.
68+ if (
69+ prevId === SideContentType . substVisualizer &&
70+ newId === SideContentType . mobileEditorRun
71+ ) {
72+ return ;
73+ }
7074
71- // Do nothing when clicking the mobile 'Run' tab while on the stepper tab.
72- if ( prevId === SideContentType . substVisualizer && newId === SideContentType . mobileEditorRun ) {
73- return ;
74- }
75+ const {
76+ context : { chapter : playgroundSourceChapter } ,
77+ editorTabs
78+ } = yield * selectWorkspace ( 'playground' ) ;
7579
76- const {
77- context : { chapter : playgroundSourceChapter } ,
78- editorTabs
79- } = yield * selectWorkspace ( 'playground' ) ;
80+ if ( prevId === SideContentType . substVisualizer ) {
81+ if ( newId === SideContentType . mobileEditorRun ) return ;
82+ const hasBreakpoints = editorTabs . find ( ( { breakpoints } ) => breakpoints . find ( x => ! ! x ) ) ;
8083
81- if ( prevId === SideContentType . substVisualizer ) {
82- if ( newId === SideContentType . mobileEditorRun ) return ;
83- const hasBreakpoints = editorTabs . find ( ( { breakpoints } ) => breakpoints . find ( x => ! ! x ) ) ;
84+ if ( ! hasBreakpoints ) {
85+ yield put ( WorkspaceActions . toggleUsingSubst ( false , workspaceLocation ) ) ;
86+ yield put ( WorkspaceActions . clearReplOutput ( workspaceLocation ) ) ;
87+ }
88+ }
8489
85- if ( ! hasBreakpoints ) {
86- yield put ( WorkspaceActions . toggleUsingSubst ( false , workspaceLocation ) ) ;
87- yield put ( WorkspaceActions . clearReplOutput ( workspaceLocation ) ) ;
90+ if ( newId !== SideContentType . cseMachine ) {
91+ yield put ( WorkspaceActions . toggleUsingCse ( false , workspaceLocation ) ) ;
92+ yield call ( [ CseMachine , CseMachine . clearCse ] ) ;
93+ yield call ( [ JavaCseMachine , JavaCseMachine . clearCse ] ) ;
94+ yield put ( WorkspaceActions . updateCurrentStep ( - 1 , workspaceLocation ) ) ;
95+ yield put ( WorkspaceActions . updateStepsTotal ( 0 , workspaceLocation ) ) ;
96+ yield put ( WorkspaceActions . toggleUpdateCse ( true , workspaceLocation ) ) ;
97+ yield put ( WorkspaceActions . setEditorHighlightedLines ( workspaceLocation , 0 , [ ] ) ) ;
8898 }
89- }
9099
91- if ( newId !== SideContentType . cseMachine ) {
92- yield put ( WorkspaceActions . toggleUsingCse ( false , workspaceLocation ) ) ;
93- yield call ( [ CseMachine , CseMachine . clearCse ] ) ;
94- yield call ( [ JavaCseMachine , JavaCseMachine . clearCse ] ) ;
95- yield put ( WorkspaceActions . updateCurrentStep ( - 1 , workspaceLocation ) ) ;
96- yield put ( WorkspaceActions . updateStepsTotal ( 0 , workspaceLocation ) ) ;
97- yield put ( WorkspaceActions . toggleUpdateCse ( true , workspaceLocation ) ) ;
98- yield put ( WorkspaceActions . setEditorHighlightedLines ( workspaceLocation , 0 , [ ] ) ) ;
99- }
100+ if ( playgroundSourceChapter === Chapter . FULL_JAVA && newId === SideContentType . cseMachine ) {
101+ yield put ( WorkspaceActions . toggleUsingCse ( true , workspaceLocation ) ) ;
102+ }
100103
101- if ( playgroundSourceChapter === Chapter . FULL_JAVA && newId === SideContentType . cseMachine ) {
102- yield put ( WorkspaceActions . toggleUsingCse ( true , workspaceLocation ) ) ;
103- }
104+ if (
105+ isSourceLanguage ( playgroundSourceChapter ) &&
106+ ( newId === SideContentType . substVisualizer || newId === SideContentType . cseMachine )
107+ ) {
108+ if ( playgroundSourceChapter <= Chapter . SOURCE_2 ) {
109+ yield put ( WorkspaceActions . toggleUsingSubst ( true , workspaceLocation ) ) ;
110+ } else {
111+ yield put ( WorkspaceActions . toggleUsingCse ( true , workspaceLocation ) ) ;
112+ }
113+ }
104114
105- if (
106- isSourceLanguage ( playgroundSourceChapter ) &&
107- ( newId === SideContentType . substVisualizer || newId === SideContentType . cseMachine )
108- ) {
109- if ( playgroundSourceChapter <= Chapter . SOURCE_2 ) {
110- yield put ( WorkspaceActions . toggleUsingSubst ( true , workspaceLocation ) ) ;
115+ if ( newId === SideContentType . upload ) {
116+ yield put ( WorkspaceActions . toggleUsingUpload ( true , workspaceLocation ) ) ;
111117 } else {
112- yield put ( WorkspaceActions . toggleUsingCse ( true , workspaceLocation ) ) ;
118+ yield put ( WorkspaceActions . toggleUsingUpload ( false , workspaceLocation ) ) ;
113119 }
114- }
115120
116- if ( newId === SideContentType . upload ) {
117- yield put ( WorkspaceActions . toggleUsingUpload ( true , workspaceLocation ) ) ;
118- } else {
119- yield put ( WorkspaceActions . toggleUsingUpload ( false , workspaceLocation ) ) ;
121+ if ( isSchemeLanguage ( playgroundSourceChapter ) && newId === SideContentType . cseMachine ) {
122+ yield put ( WorkspaceActions . toggleUsingCse ( true , workspaceLocation ) ) ;
123+ }
120124 }
125+ ) ;
126+ }
127+ ) ;
121128
122- if ( isSchemeLanguage ( playgroundSourceChapter ) && newId === SideContentType . cseMachine ) {
123- yield put ( WorkspaceActions . toggleUsingCse ( true , workspaceLocation ) ) ;
124- }
125- }
126- ) ;
127- }
129+ export default PlaygroundSaga ;
128130
129131function * updateQueryString ( ) {
130132 const fileSystem : FSModule = yield select (
0 commit comments