2020-06-29 17:51:40 +00:00
|
|
|
import React from 'react';
|
2020-06-18 19:29:46 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2020-06-19 00:08:53 +00:00
|
|
|
import { bindActionCreators } from 'redux';
|
2020-06-18 19:29:46 +00:00
|
|
|
import { connect } from 'react-redux';
|
2020-06-18 18:49:31 +00:00
|
|
|
import styled from 'styled-components';
|
2020-06-18 18:39:55 +00:00
|
|
|
import Header from '../../components/mobile/Header';
|
2020-06-29 22:54:48 +00:00
|
|
|
import IconButton from '../../components/mobile/IconButton';
|
2020-06-18 19:29:46 +00:00
|
|
|
import PreviewFrame from '../IDE/components/PreviewFrame';
|
2020-06-18 18:39:55 +00:00
|
|
|
import Screen from '../../components/mobile/MobileScreen';
|
2020-07-15 20:44:47 +00:00
|
|
|
import Console from '../IDE/components/Console';
|
2020-06-19 00:08:53 +00:00
|
|
|
import * as ProjectActions from '../IDE/actions/project';
|
2020-06-19 01:00:24 +00:00
|
|
|
import * as IDEActions from '../IDE/actions/ide';
|
2020-06-19 01:52:25 +00:00
|
|
|
import * as PreferencesActions from '../IDE/actions/preferences';
|
|
|
|
import * as ConsoleActions from '../IDE/actions/console';
|
|
|
|
import * as FilesActions from '../IDE/actions/files';
|
2020-06-19 01:00:24 +00:00
|
|
|
|
2020-06-19 01:52:25 +00:00
|
|
|
import { getHTMLFile } from '../IDE/reducers/files';
|
2020-06-18 19:01:13 +00:00
|
|
|
|
2020-06-19 00:08:53 +00:00
|
|
|
|
2020-06-19 01:52:25 +00:00
|
|
|
import { ExitIcon } from '../../common/icons';
|
2020-06-18 19:01:13 +00:00
|
|
|
import { remSize } from '../../theme';
|
2020-07-15 20:44:47 +00:00
|
|
|
import Footer from '../../components/mobile/Footer';
|
2020-06-18 19:01:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
const Content = styled.div`
|
|
|
|
z-index: 0;
|
2020-06-19 18:55:37 +00:00
|
|
|
margin-top: ${remSize(68)};
|
2020-06-18 19:01:13 +00:00
|
|
|
`;
|
2020-06-18 18:49:31 +00:00
|
|
|
|
2020-06-18 18:39:55 +00:00
|
|
|
const MobileSketchView = (props) => {
|
2020-06-18 19:29:46 +00:00
|
|
|
// TODO: useSelector requires react-redux ^7.1.0
|
|
|
|
// const htmlFile = useSelector(state => getHTMLFile(state.files));
|
|
|
|
// const jsFiles = useSelector(state => getJSFiles(state.files));
|
|
|
|
// const cssFiles = useSelector(state => getCSSFiles(state.files));
|
|
|
|
// const files = useSelector(state => state.files);
|
|
|
|
|
|
|
|
const {
|
2020-06-19 18:55:37 +00:00
|
|
|
htmlFile, files, selectedFile, projectName
|
2020-06-18 19:29:46 +00:00
|
|
|
} = props;
|
|
|
|
|
2020-06-19 01:00:24 +00:00
|
|
|
// Actions
|
2020-06-19 01:52:25 +00:00
|
|
|
const {
|
|
|
|
setTextOutput, setGridOutput, setSoundOutput,
|
2020-07-15 21:26:34 +00:00
|
|
|
endSketchRefresh, stopSketch,
|
2020-06-19 01:52:25 +00:00
|
|
|
dispatchConsoleEvent, expandConsole, clearConsole,
|
|
|
|
setBlobUrl,
|
|
|
|
} = props;
|
|
|
|
|
|
|
|
const { preferences, ide } = props;
|
2020-06-19 01:00:24 +00:00
|
|
|
|
2020-06-18 18:39:55 +00:00
|
|
|
return (
|
2020-06-23 18:54:09 +00:00
|
|
|
<Screen fullscreen>
|
2020-06-30 22:11:48 +00:00
|
|
|
<Header
|
|
|
|
leftButton={
|
2020-07-01 19:44:19 +00:00
|
|
|
<IconButton to="/mobile" icon={ExitIcon} aria-label="Return to original editor" />
|
|
|
|
}
|
2020-06-30 22:11:48 +00:00
|
|
|
title={projectName}
|
|
|
|
/>
|
2020-06-18 19:01:13 +00:00
|
|
|
<Content>
|
2020-06-19 18:55:37 +00:00
|
|
|
<PreviewFrame
|
|
|
|
htmlFile={htmlFile}
|
|
|
|
files={files}
|
|
|
|
head={<link type="text/css" rel="stylesheet" href="/preview-styles.css" />}
|
|
|
|
|
|
|
|
content={selectedFile.content}
|
|
|
|
|
|
|
|
isPlaying
|
|
|
|
isAccessibleOutputPlaying={ide.isAccessibleOutputPlaying}
|
|
|
|
previewIsRefreshing={ide.previewIsRefreshing}
|
|
|
|
|
|
|
|
textOutput={preferences.textOutput}
|
|
|
|
gridOutput={preferences.gridOutput}
|
|
|
|
soundOutput={preferences.soundOutput}
|
|
|
|
autorefresh={preferences.autorefresh}
|
|
|
|
|
|
|
|
setTextOutput={setTextOutput}
|
|
|
|
setGridOutput={setGridOutput}
|
|
|
|
setSoundOutput={setSoundOutput}
|
|
|
|
dispatchConsoleEvent={dispatchConsoleEvent}
|
|
|
|
endSketchRefresh={endSketchRefresh}
|
|
|
|
stopSketch={stopSketch}
|
|
|
|
setBlobUrl={setBlobUrl}
|
|
|
|
expandConsole={expandConsole}
|
|
|
|
clearConsole={clearConsole}
|
|
|
|
/>
|
2020-06-18 19:01:13 +00:00
|
|
|
</Content>
|
2020-07-15 21:17:01 +00:00
|
|
|
<Footer before={<Console />} />
|
2020-06-18 18:39:55 +00:00
|
|
|
</Screen>);
|
|
|
|
};
|
2020-06-18 19:01:13 +00:00
|
|
|
|
2020-06-18 19:29:46 +00:00
|
|
|
MobileSketchView.propTypes = {
|
2020-06-19 00:08:53 +00:00
|
|
|
params: PropTypes.shape({
|
|
|
|
project_id: PropTypes.string,
|
|
|
|
username: PropTypes.string
|
|
|
|
}).isRequired,
|
2020-06-19 01:52:25 +00:00
|
|
|
|
2020-06-18 19:29:46 +00:00
|
|
|
htmlFile: PropTypes.shape({
|
|
|
|
id: PropTypes.string.isRequired,
|
|
|
|
content: PropTypes.string.isRequired,
|
|
|
|
name: PropTypes.string.isRequired
|
|
|
|
}).isRequired,
|
2020-06-19 01:52:25 +00:00
|
|
|
files: PropTypes.arrayOf(PropTypes.shape({
|
2020-06-18 19:29:46 +00:00
|
|
|
id: PropTypes.string.isRequired,
|
|
|
|
content: PropTypes.string.isRequired,
|
|
|
|
name: PropTypes.string.isRequired
|
|
|
|
})).isRequired,
|
2020-06-19 01:52:25 +00:00
|
|
|
|
|
|
|
selectedFile: PropTypes.shape({
|
2020-06-18 19:29:46 +00:00
|
|
|
id: PropTypes.string.isRequired,
|
|
|
|
content: PropTypes.string.isRequired,
|
|
|
|
name: PropTypes.string.isRequired
|
2020-06-19 01:52:25 +00:00
|
|
|
}).isRequired,
|
|
|
|
|
|
|
|
preferences: PropTypes.shape({
|
|
|
|
fontSize: PropTypes.number.isRequired,
|
|
|
|
autosave: PropTypes.bool.isRequired,
|
|
|
|
linewrap: PropTypes.bool.isRequired,
|
|
|
|
lineNumbers: PropTypes.bool.isRequired,
|
|
|
|
lintWarning: PropTypes.bool.isRequired,
|
|
|
|
textOutput: PropTypes.bool.isRequired,
|
|
|
|
gridOutput: PropTypes.bool.isRequired,
|
|
|
|
soundOutput: PropTypes.bool.isRequired,
|
|
|
|
theme: PropTypes.string.isRequired,
|
|
|
|
autorefresh: PropTypes.bool.isRequired
|
|
|
|
}).isRequired,
|
|
|
|
|
|
|
|
ide: PropTypes.shape({
|
|
|
|
isPlaying: PropTypes.bool.isRequired,
|
|
|
|
isAccessibleOutputPlaying: PropTypes.bool.isRequired,
|
|
|
|
consoleEvent: PropTypes.array,
|
|
|
|
modalIsVisible: PropTypes.bool.isRequired,
|
|
|
|
sidebarIsExpanded: PropTypes.bool.isRequired,
|
|
|
|
consoleIsExpanded: PropTypes.bool.isRequired,
|
|
|
|
preferencesIsVisible: PropTypes.bool.isRequired,
|
|
|
|
projectOptionsVisible: PropTypes.bool.isRequired,
|
|
|
|
newFolderModalVisible: PropTypes.bool.isRequired,
|
|
|
|
shareModalVisible: PropTypes.bool.isRequired,
|
|
|
|
shareModalProjectId: PropTypes.string.isRequired,
|
|
|
|
shareModalProjectName: PropTypes.string.isRequired,
|
|
|
|
shareModalProjectUsername: PropTypes.string.isRequired,
|
|
|
|
editorOptionsVisible: PropTypes.bool.isRequired,
|
|
|
|
keyboardShortcutVisible: PropTypes.bool.isRequired,
|
|
|
|
unsavedChanges: PropTypes.bool.isRequired,
|
|
|
|
infiniteLoop: PropTypes.bool.isRequired,
|
|
|
|
previewIsRefreshing: PropTypes.bool.isRequired,
|
|
|
|
infiniteLoopMessage: PropTypes.string.isRequired,
|
|
|
|
projectSavedTime: PropTypes.string,
|
|
|
|
previousPath: PropTypes.string.isRequired,
|
|
|
|
justOpenedProject: PropTypes.bool.isRequired,
|
|
|
|
errorType: PropTypes.string,
|
|
|
|
runtimeErrorWarningVisible: PropTypes.bool.isRequired,
|
|
|
|
}).isRequired,
|
|
|
|
|
2020-06-19 19:30:39 +00:00
|
|
|
projectName: PropTypes.string.isRequired,
|
2020-06-19 18:55:37 +00:00
|
|
|
|
2020-06-19 01:52:25 +00:00
|
|
|
setTextOutput: PropTypes.func.isRequired,
|
|
|
|
setGridOutput: PropTypes.func.isRequired,
|
|
|
|
setSoundOutput: PropTypes.func.isRequired,
|
|
|
|
dispatchConsoleEvent: PropTypes.func.isRequired,
|
|
|
|
endSketchRefresh: PropTypes.func.isRequired,
|
|
|
|
stopSketch: PropTypes.func.isRequired,
|
|
|
|
setBlobUrl: PropTypes.func.isRequired,
|
|
|
|
expandConsole: PropTypes.func.isRequired,
|
|
|
|
clearConsole: PropTypes.func.isRequired,
|
2020-06-18 19:29:46 +00:00
|
|
|
};
|
2020-06-18 19:01:13 +00:00
|
|
|
|
2020-06-18 19:29:46 +00:00
|
|
|
function mapStateToProps(state) {
|
|
|
|
return {
|
|
|
|
htmlFile: getHTMLFile(state.files),
|
2020-06-19 18:55:37 +00:00
|
|
|
projectName: state.project.name,
|
2020-06-19 01:52:25 +00:00
|
|
|
files: state.files,
|
|
|
|
ide: state.ide,
|
|
|
|
preferences: state.preferences,
|
|
|
|
selectedFile: state.files.find(file => file.isSelectedFile) ||
|
|
|
|
state.files.find(file => file.name === 'sketch.js') ||
|
|
|
|
state.files.find(file => file.name !== 'root'),
|
2020-06-18 19:29:46 +00:00
|
|
|
};
|
|
|
|
}
|
2020-06-18 19:01:13 +00:00
|
|
|
|
2020-06-19 00:08:53 +00:00
|
|
|
function mapDispatchToProps(dispatch) {
|
2020-06-19 01:52:25 +00:00
|
|
|
return bindActionCreators({
|
|
|
|
...ProjectActions, ...IDEActions, ...PreferencesActions, ...ConsoleActions, ...FilesActions
|
|
|
|
}, dispatch);
|
2020-06-19 00:08:53 +00:00
|
|
|
}
|
2020-06-18 19:01:13 +00:00
|
|
|
|
2020-06-19 00:08:53 +00:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(MobileSketchView);
|