1
1
import React from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
3
import { bindActionCreators } from 'redux' ;
4
- import { connect } from 'react-redux' ;
4
+ import { connect , useSelector , useDispatch } from 'react-redux' ;
5
5
import styled from 'styled-components' ;
6
6
import Header from '../../components/mobile/Header' ;
7
7
import IconButton from '../../components/mobile/IconButton' ;
@@ -15,43 +15,34 @@ import * as FilesActions from '../IDE/actions/files';
15
15
16
16
import { getHTMLFile } from '../IDE/reducers/files' ;
17
17
18
-
19
18
import { ExitIcon } from '../../common/icons' ;
20
19
import { remSize } from '../../theme' ;
21
20
22
-
23
21
const Content = styled . div `
24
22
z-index: 0;
25
23
margin-top: ${ remSize ( 68 ) } ;
26
24
` ;
27
25
28
26
const MobileSketchView = ( props ) => {
29
- // TODO: useSelector requires react-redux ^7.1.0
30
- // const htmlFile = useSelector(state => getHTMLFile(state.files));
31
- // const jsFiles = useSelector(state => getJSFiles(state.files));
32
- // const cssFiles = useSelector(state => getCSSFiles(state.files));
33
- // const files = useSelector(state => state.files);
27
+ const { files, ide, preferences } = useSelector ( state => state ) ;
34
28
35
- const {
36
- htmlFile, files, selectedFile, projectName
37
- } = props ;
29
+ const htmlFile = useSelector ( state => getHTMLFile ( state . files ) ) ;
30
+ const projectName = useSelector ( state => state . project . name ) ;
31
+ const selectedFile = useSelector ( state => state . files . find ( file => file . isSelectedFile ) ||
32
+ state . files . find ( file => file . name === 'sketch.js' ) ||
33
+ state . files . find ( file => file . name !== 'root' ) ) ;
38
34
39
- // Actions
40
35
const {
41
- setTextOutput, setGridOutput, setSoundOutput,
42
- endSketchRefresh, stopSketch,
43
- dispatchConsoleEvent, expandConsole, clearConsole,
44
- setBlobUrl,
45
- } = props ;
46
-
47
- const { preferences, ide } = props ;
36
+ setTextOutput, setGridOutput, setSoundOutput, dispatchConsoleEvent,
37
+ endSketchRefresh, stopSketch, setBlobUrl, expandConsole, clearConsole
38
+ } = bindActionCreators ( {
39
+ ...ProjectActions , ...IDEActions , ...PreferencesActions , ...ConsoleActions , ...FilesActions
40
+ } , useDispatch ( ) ) ;
48
41
49
42
return (
50
43
< Screen fullscreen >
51
44
< Header
52
- leftButton = {
53
- < IconButton to = "/mobile" icon = { ExitIcon } aria-label = "Return to original editor" />
54
- }
45
+ leftButton = { < IconButton to = "/mobile" icon = { ExitIcon } aria-label = "Return to original editor" /> }
55
46
title = { projectName }
56
47
/>
57
48
< Content >
@@ -85,100 +76,4 @@ const MobileSketchView = (props) => {
85
76
</ Screen > ) ;
86
77
} ;
87
78
88
- MobileSketchView . propTypes = {
89
- params : PropTypes . shape ( {
90
- project_id : PropTypes . string ,
91
- username : PropTypes . string
92
- } ) . isRequired ,
93
-
94
- htmlFile : PropTypes . shape ( {
95
- id : PropTypes . string . isRequired ,
96
- content : PropTypes . string . isRequired ,
97
- name : PropTypes . string . isRequired
98
- } ) . isRequired ,
99
- files : PropTypes . arrayOf ( PropTypes . shape ( {
100
- id : PropTypes . string . isRequired ,
101
- content : PropTypes . string . isRequired ,
102
- name : PropTypes . string . isRequired
103
- } ) ) . isRequired ,
104
-
105
- selectedFile : PropTypes . shape ( {
106
- id : PropTypes . string . isRequired ,
107
- content : PropTypes . string . isRequired ,
108
- name : PropTypes . string . isRequired
109
- } ) . isRequired ,
110
-
111
- preferences : PropTypes . shape ( {
112
- fontSize : PropTypes . number . isRequired ,
113
- autosave : PropTypes . bool . isRequired ,
114
- linewrap : PropTypes . bool . isRequired ,
115
- lineNumbers : PropTypes . bool . isRequired ,
116
- lintWarning : PropTypes . bool . isRequired ,
117
- textOutput : PropTypes . bool . isRequired ,
118
- gridOutput : PropTypes . bool . isRequired ,
119
- soundOutput : PropTypes . bool . isRequired ,
120
- theme : PropTypes . string . isRequired ,
121
- autorefresh : PropTypes . bool . isRequired
122
- } ) . isRequired ,
123
-
124
- ide : PropTypes . shape ( {
125
- isPlaying : PropTypes . bool . isRequired ,
126
- isAccessibleOutputPlaying : PropTypes . bool . isRequired ,
127
- consoleEvent : PropTypes . array ,
128
- modalIsVisible : PropTypes . bool . isRequired ,
129
- sidebarIsExpanded : PropTypes . bool . isRequired ,
130
- consoleIsExpanded : PropTypes . bool . isRequired ,
131
- preferencesIsVisible : PropTypes . bool . isRequired ,
132
- projectOptionsVisible : PropTypes . bool . isRequired ,
133
- newFolderModalVisible : PropTypes . bool . isRequired ,
134
- shareModalVisible : PropTypes . bool . isRequired ,
135
- shareModalProjectId : PropTypes . string . isRequired ,
136
- shareModalProjectName : PropTypes . string . isRequired ,
137
- shareModalProjectUsername : PropTypes . string . isRequired ,
138
- editorOptionsVisible : PropTypes . bool . isRequired ,
139
- keyboardShortcutVisible : PropTypes . bool . isRequired ,
140
- unsavedChanges : PropTypes . bool . isRequired ,
141
- infiniteLoop : PropTypes . bool . isRequired ,
142
- previewIsRefreshing : PropTypes . bool . isRequired ,
143
- infiniteLoopMessage : PropTypes . string . isRequired ,
144
- projectSavedTime : PropTypes . string ,
145
- previousPath : PropTypes . string . isRequired ,
146
- justOpenedProject : PropTypes . bool . isRequired ,
147
- errorType : PropTypes . string ,
148
- runtimeErrorWarningVisible : PropTypes . bool . isRequired ,
149
- uploadFileModalVisible : PropTypes . bool . isRequired
150
- } ) . isRequired ,
151
-
152
- projectName : PropTypes . string . isRequired ,
153
-
154
- setTextOutput : PropTypes . func . isRequired ,
155
- setGridOutput : PropTypes . func . isRequired ,
156
- setSoundOutput : PropTypes . func . isRequired ,
157
- dispatchConsoleEvent : PropTypes . func . isRequired ,
158
- endSketchRefresh : PropTypes . func . isRequired ,
159
- stopSketch : PropTypes . func . isRequired ,
160
- setBlobUrl : PropTypes . func . isRequired ,
161
- expandConsole : PropTypes . func . isRequired ,
162
- clearConsole : PropTypes . func . isRequired ,
163
- } ;
164
-
165
- function mapStateToProps ( state ) {
166
- return {
167
- htmlFile : getHTMLFile ( state . files ) ,
168
- projectName : state . project . name ,
169
- files : state . files ,
170
- ide : state . ide ,
171
- preferences : state . preferences ,
172
- selectedFile : state . files . find ( file => file . isSelectedFile ) ||
173
- state . files . find ( file => file . name === 'sketch.js' ) ||
174
- state . files . find ( file => file . name !== 'root' ) ,
175
- } ;
176
- }
177
-
178
- function mapDispatchToProps ( dispatch ) {
179
- return bindActionCreators ( {
180
- ...ProjectActions , ...IDEActions , ...PreferencesActions , ...ConsoleActions , ...FilesActions
181
- } , dispatch ) ;
182
- }
183
-
184
- export default connect ( mapStateToProps , mapDispatchToProps ) ( MobileSketchView ) ;
79
+ export default MobileSketchView ;
0 commit comments