1
- import React , { useState , useEffect } from 'react' ;
1
+ import React from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
3
import { Link } from 'react-router' ;
4
4
import { bindActionCreators } from 'redux' ;
@@ -9,11 +9,14 @@ import PreviewFrame from '../IDE/components/PreviewFrame';
9
9
import Screen from '../../components/mobile/MobileScreen' ;
10
10
import * as ProjectActions from '../IDE/actions/project' ;
11
11
import * as IDEActions from '../IDE/actions/ide' ;
12
+ import * as PreferencesActions from '../IDE/actions/preferences' ;
13
+ import * as ConsoleActions from '../IDE/actions/console' ;
14
+ import * as FilesActions from '../IDE/actions/files' ;
12
15
13
- import { getHTMLFile , getJSFiles , getCSSFiles } from '../IDE/reducers/files' ;
16
+ import { getHTMLFile } from '../IDE/reducers/files' ;
14
17
15
18
16
- import { ExitIcon } from '../../common/Icons ' ;
19
+ import { ExitIcon } from '../../common/icons ' ;
17
20
import { remSize } from '../../theme' ;
18
21
19
22
@@ -28,24 +31,26 @@ const IconLinkWrapper = styled(Link)`
28
31
margin-left: none;
29
32
` ;
30
33
31
- const noop = ( ) => { } ;
32
-
33
34
const MobileSketchView = ( props ) => {
34
- const [ overlay , setOverlay ] = useState ( null ) ;
35
-
36
-
37
35
// TODO: useSelector requires react-redux ^7.1.0
38
36
// const htmlFile = useSelector(state => getHTMLFile(state.files));
39
37
// const jsFiles = useSelector(state => getJSFiles(state.files));
40
38
// const cssFiles = useSelector(state => getCSSFiles(state.files));
41
39
// const files = useSelector(state => state.files);
42
40
43
41
const {
44
- htmlFile, jsFiles , cssFiles , files, params
42
+ htmlFile, files, selectedFile
45
43
} = props ;
46
44
47
45
// Actions
48
- const { getProject, startSketch } = props ;
46
+ const {
47
+ setTextOutput, setGridOutput, setSoundOutput,
48
+ endSketchRefresh, stopSketch,
49
+ dispatchConsoleEvent, expandConsole, clearConsole,
50
+ setBlobUrl,
51
+ } = props ;
52
+
53
+ const { preferences, ide } = props ;
49
54
50
55
// useEffect(() => {
51
56
// console.log(params);
@@ -65,30 +70,35 @@ const MobileSketchView = (props) => {
65
70
</ Header >
66
71
< Content >
67
72
< h1 > Hello</ h1 >
68
- < main className = "preview-frame-holder" >
73
+ < section className = "preview-frame-holder" >
69
74
70
75
< PreviewFrame
71
- fullView
72
- isPlaying
73
76
htmlFile = { htmlFile }
74
- jsFiles = { jsFiles }
75
- cssFiles = { cssFiles }
76
77
files = { files }
77
- head = { < link type = "text/css" rel = "stylesheet" href = "/preview-styles.css" /> }
78
- isAccessibleOutputPlaying = { false }
79
- textOutput = { false }
80
- gridOutput = { false }
81
- soundOutput = { false }
82
- previewIsRefreshing = { false }
83
-
84
- dispatchConsoleEvent = { noop }
85
- endSketchRefresh = { noop }
86
- setBlobUrl = { noop }
87
- stopSketch = { noop }
88
- expandConsole = { noop }
89
- clearConsole = { noop }
78
+ fullView
79
+
80
+ content = { selectedFile . content }
81
+
82
+ isPlaying = { ide . isPlaying }
83
+ isAccessibleOutputPlaying = { ide . isAccessibleOutputPlaying }
84
+ previewIsRefreshing = { ide . previewIsRefreshing }
85
+
86
+ textOutput = { preferences . textOutput }
87
+ gridOutput = { preferences . gridOutput }
88
+ soundOutput = { preferences . soundOutput }
89
+ autorefresh = { preferences . autorefresh }
90
+
91
+ setTextOutput = { setTextOutput }
92
+ setGridOutput = { setGridOutput }
93
+ setSoundOutput = { setSoundOutput }
94
+ dispatchConsoleEvent = { dispatchConsoleEvent }
95
+ endSketchRefresh = { endSketchRefresh }
96
+ stopSketch = { stopSketch }
97
+ setBlobUrl = { setBlobUrl }
98
+ expandConsole = { expandConsole }
99
+ clearConsole = { clearConsole }
90
100
/>
91
- </ main >
101
+ </ section >
92
102
</ Content >
93
103
</ Screen > ) ;
94
104
} ;
@@ -98,42 +108,93 @@ MobileSketchView.propTypes = {
98
108
project_id : PropTypes . string ,
99
109
username : PropTypes . string
100
110
} ) . isRequired ,
111
+
101
112
htmlFile : PropTypes . shape ( {
102
113
id : PropTypes . string . isRequired ,
103
114
content : PropTypes . string . isRequired ,
104
115
name : PropTypes . string . isRequired
105
116
} ) . isRequired ,
106
- jsFiles : PropTypes . arrayOf ( PropTypes . shape ( {
107
- id : PropTypes . string . isRequired ,
108
- content : PropTypes . string . isRequired ,
109
- name : PropTypes . string . isRequired
110
- } ) ) . isRequired ,
111
- cssFiles : PropTypes . arrayOf ( PropTypes . shape ( {
117
+ files : PropTypes . arrayOf ( PropTypes . shape ( {
112
118
id : PropTypes . string . isRequired ,
113
119
content : PropTypes . string . isRequired ,
114
120
name : PropTypes . string . isRequired
115
121
} ) ) . isRequired ,
116
- files : PropTypes . arrayOf ( PropTypes . shape ( {
122
+
123
+ selectedFile : PropTypes . shape ( {
117
124
id : PropTypes . string . isRequired ,
118
125
content : PropTypes . string . isRequired ,
119
126
name : PropTypes . string . isRequired
120
- } ) ) . isRequired ,
121
- getProject : PropTypes . func . isRequired ,
122
- startSketch : PropTypes . func . isRequired ,
127
+ } ) . isRequired ,
128
+
129
+ preferences : PropTypes . shape ( {
130
+ fontSize : PropTypes . number . isRequired ,
131
+ autosave : PropTypes . bool . isRequired ,
132
+ linewrap : PropTypes . bool . isRequired ,
133
+ lineNumbers : PropTypes . bool . isRequired ,
134
+ lintWarning : PropTypes . bool . isRequired ,
135
+ textOutput : PropTypes . bool . isRequired ,
136
+ gridOutput : PropTypes . bool . isRequired ,
137
+ soundOutput : PropTypes . bool . isRequired ,
138
+ theme : PropTypes . string . isRequired ,
139
+ autorefresh : PropTypes . bool . isRequired
140
+ } ) . isRequired ,
141
+
142
+ ide : PropTypes . shape ( {
143
+ isPlaying : PropTypes . bool . isRequired ,
144
+ isAccessibleOutputPlaying : PropTypes . bool . isRequired ,
145
+ consoleEvent : PropTypes . array ,
146
+ modalIsVisible : PropTypes . bool . isRequired ,
147
+ sidebarIsExpanded : PropTypes . bool . isRequired ,
148
+ consoleIsExpanded : PropTypes . bool . isRequired ,
149
+ preferencesIsVisible : PropTypes . bool . isRequired ,
150
+ projectOptionsVisible : PropTypes . bool . isRequired ,
151
+ newFolderModalVisible : PropTypes . bool . isRequired ,
152
+ shareModalVisible : PropTypes . bool . isRequired ,
153
+ shareModalProjectId : PropTypes . string . isRequired ,
154
+ shareModalProjectName : PropTypes . string . isRequired ,
155
+ shareModalProjectUsername : PropTypes . string . isRequired ,
156
+ editorOptionsVisible : PropTypes . bool . isRequired ,
157
+ keyboardShortcutVisible : PropTypes . bool . isRequired ,
158
+ unsavedChanges : PropTypes . bool . isRequired ,
159
+ infiniteLoop : PropTypes . bool . isRequired ,
160
+ previewIsRefreshing : PropTypes . bool . isRequired ,
161
+ infiniteLoopMessage : PropTypes . string . isRequired ,
162
+ projectSavedTime : PropTypes . string ,
163
+ previousPath : PropTypes . string . isRequired ,
164
+ justOpenedProject : PropTypes . bool . isRequired ,
165
+ errorType : PropTypes . string ,
166
+ runtimeErrorWarningVisible : PropTypes . bool . isRequired ,
167
+ uploadFileModalVisible : PropTypes . bool . isRequired
168
+ } ) . isRequired ,
169
+
170
+ setTextOutput : PropTypes . func . isRequired ,
171
+ setGridOutput : PropTypes . func . isRequired ,
172
+ setSoundOutput : PropTypes . func . isRequired ,
173
+ dispatchConsoleEvent : PropTypes . func . isRequired ,
174
+ endSketchRefresh : PropTypes . func . isRequired ,
175
+ stopSketch : PropTypes . func . isRequired ,
176
+ setBlobUrl : PropTypes . func . isRequired ,
177
+ expandConsole : PropTypes . func . isRequired ,
178
+ clearConsole : PropTypes . func . isRequired ,
123
179
} ;
124
180
125
181
function mapStateToProps ( state ) {
126
182
return {
127
183
htmlFile : getHTMLFile ( state . files ) ,
128
- jsFiles : getJSFiles ( state . files ) ,
129
- cssFiles : getCSSFiles ( state . files ) ,
130
184
project : state . project ,
131
- files : state . files
185
+ files : state . files ,
186
+ ide : state . ide ,
187
+ preferences : state . preferences ,
188
+ selectedFile : state . files . find ( file => file . isSelectedFile ) ||
189
+ state . files . find ( file => file . name === 'sketch.js' ) ||
190
+ state . files . find ( file => file . name !== 'root' ) ,
132
191
} ;
133
192
}
134
193
135
194
function mapDispatchToProps ( dispatch ) {
136
- return bindActionCreators ( { ...ProjectActions , ...IDEActions } , dispatch ) ;
195
+ return bindActionCreators ( {
196
+ ...ProjectActions , ...IDEActions , ...PreferencesActions , ...ConsoleActions , ...FilesActions
197
+ } , dispatch ) ;
137
198
}
138
199
139
200
export default connect ( mapStateToProps , mapDispatchToProps ) ( MobileSketchView ) ;
0 commit comments