2020-06-09 19:29:20 +00:00
|
|
|
import React from 'react';
|
2020-06-09 19:51:57 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2020-06-15 20:46:56 +00:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { withRouter } from 'react-router';
|
|
|
|
import { useState } from 'react';
|
2020-07-15 20:24:12 +00:00
|
|
|
import styled from 'styled-components';
|
2020-06-12 19:09:30 +00:00
|
|
|
|
2020-06-15 20:46:56 +00:00
|
|
|
// Imports to be Refactored
|
|
|
|
import { bindActionCreators } from 'redux';
|
2020-07-24 19:30:14 +00:00
|
|
|
|
2020-06-15 20:46:56 +00:00
|
|
|
import * as FileActions from '../actions/files';
|
|
|
|
import * as IDEActions from '../actions/ide';
|
|
|
|
import * as ProjectActions from '../actions/project';
|
|
|
|
import * as EditorAccessibilityActions from '../actions/editorAccessibility';
|
|
|
|
import * as PreferencesActions from '../actions/preferences';
|
|
|
|
import * as UserActions from '../../User/actions';
|
|
|
|
import * as ToastActions from '../actions/toast';
|
|
|
|
import * as ConsoleActions from '../actions/console';
|
|
|
|
import { getHTMLFile } from '../reducers/files';
|
|
|
|
|
|
|
|
// Local Imports
|
|
|
|
import Editor from '../components/Editor';
|
2020-07-24 19:30:14 +00:00
|
|
|
import { PlayIcon, ExitIcon, MoreIcon } from '../../../common/icons';
|
2020-06-15 20:46:56 +00:00
|
|
|
|
2020-06-16 20:38:43 +00:00
|
|
|
import IconButton from '../../../components/mobile/IconButton';
|
|
|
|
import Header from '../../../components/mobile/Header';
|
|
|
|
import Screen from '../../../components/mobile/MobileScreen';
|
|
|
|
import Footer from '../../../components/mobile/Footer';
|
2020-06-18 19:01:13 +00:00
|
|
|
import IDEWrapper from '../../../components/mobile/IDEWrapper';
|
2020-07-15 20:24:12 +00:00
|
|
|
import Console from '../components/Console';
|
|
|
|
import { remSize } from '../../../theme';
|
2020-07-24 19:30:14 +00:00
|
|
|
import OverlayManager from '../../../components/OverlayManager';
|
2020-07-21 15:14:58 +00:00
|
|
|
import ActionStrip from '../../../components/mobile/ActionStrip';
|
2020-06-16 20:23:49 +00:00
|
|
|
|
2020-07-24 21:11:10 +00:00
|
|
|
const isUserOwner = ({ project, user }) =>
|
|
|
|
project.owner && project.owner.id === user.id;
|
2020-07-21 15:14:58 +00:00
|
|
|
|
|
|
|
const Expander = styled.div`
|
|
|
|
height: ${props => (props.expanded ? remSize(160) : remSize(27))};
|
2020-07-20 21:51:42 +00:00
|
|
|
`;
|
|
|
|
|
2020-07-21 22:03:22 +00:00
|
|
|
|
2020-06-22 18:10:20 +00:00
|
|
|
const MobileIDEView = (props) => {
|
2020-06-15 20:59:11 +00:00
|
|
|
const {
|
2020-07-24 21:11:10 +00:00
|
|
|
preferences,
|
|
|
|
ide,
|
|
|
|
editorAccessibility,
|
|
|
|
project,
|
|
|
|
updateLintMessage,
|
|
|
|
clearLintMessage,
|
|
|
|
selectedFile,
|
|
|
|
updateFileContent,
|
|
|
|
files,
|
|
|
|
closeEditorOptions,
|
|
|
|
showEditorOptions,
|
|
|
|
showKeyboardShortcutModal,
|
|
|
|
setUnsavedChanges,
|
|
|
|
startRefreshSketch,
|
|
|
|
stopSketch,
|
|
|
|
expandSidebar,
|
|
|
|
collapseSidebar,
|
|
|
|
clearConsole,
|
|
|
|
console,
|
|
|
|
showRuntimeErrorWarning,
|
|
|
|
hideRuntimeErrorWarning,
|
|
|
|
startSketch,
|
2020-06-15 20:59:11 +00:00
|
|
|
} = props;
|
2020-06-12 19:09:30 +00:00
|
|
|
|
2020-06-29 17:45:17 +00:00
|
|
|
const [tmController, setTmController] = useState(null); // eslint-disable-line
|
2020-07-22 21:48:24 +00:00
|
|
|
const [overlayName, setOverlay] = useState(null); // eslint-disable-line
|
2020-06-16 19:25:40 +00:00
|
|
|
|
2020-07-22 21:48:24 +00:00
|
|
|
// TODO: Move this to OverlayController (?)
|
|
|
|
const hideOverlay = () => setOverlay(null);
|
2020-07-24 19:30:14 +00:00
|
|
|
// const overlayRef = useRef({});
|
2020-06-16 19:25:40 +00:00
|
|
|
|
2020-06-15 20:46:56 +00:00
|
|
|
return (
|
2020-06-23 18:54:09 +00:00
|
|
|
<Screen fullscreen>
|
2020-06-30 22:11:48 +00:00
|
|
|
<Header
|
|
|
|
title={project.name}
|
|
|
|
subtitle={selectedFile.name}
|
|
|
|
leftButton={
|
2020-07-24 21:11:10 +00:00
|
|
|
<IconButton
|
|
|
|
to="/mobile"
|
|
|
|
icon={ExitIcon}
|
|
|
|
aria-label="Return to original editor"
|
|
|
|
/>
|
2020-06-30 22:11:48 +00:00
|
|
|
}
|
|
|
|
>
|
2020-07-01 19:44:19 +00:00
|
|
|
<IconButton
|
2020-07-21 22:03:22 +00:00
|
|
|
onClick={() => setOverlay('dropdown')}
|
2020-07-21 21:33:10 +00:00
|
|
|
icon={MoreIcon}
|
2020-07-21 22:03:22 +00:00
|
|
|
aria-label="Options"
|
2020-07-01 19:44:19 +00:00
|
|
|
/>
|
2020-07-24 21:11:10 +00:00
|
|
|
<IconButton
|
|
|
|
to="/mobile/preview"
|
|
|
|
onClick={() => {
|
|
|
|
startSketch();
|
|
|
|
}}
|
|
|
|
icon={PlayIcon}
|
|
|
|
aria-label="Run sketch"
|
|
|
|
/>
|
2020-06-15 20:59:11 +00:00
|
|
|
</Header>
|
2020-06-12 19:09:30 +00:00
|
|
|
|
2020-06-18 19:01:13 +00:00
|
|
|
<IDEWrapper>
|
2020-06-15 20:59:11 +00:00
|
|
|
<Editor
|
2020-06-15 21:47:08 +00:00
|
|
|
lintWarning={preferences.lintWarning}
|
|
|
|
linewrap={preferences.linewrap}
|
|
|
|
lintMessages={editorAccessibility.lintMessages}
|
|
|
|
updateLintMessage={updateLintMessage}
|
|
|
|
clearLintMessage={clearLintMessage}
|
|
|
|
file={selectedFile}
|
|
|
|
updateFileContent={updateFileContent}
|
|
|
|
fontSize={preferences.fontSize}
|
|
|
|
lineNumbers={preferences.lineNumbers}
|
|
|
|
files={files}
|
|
|
|
editorOptionsVisible={ide.editorOptionsVisible}
|
|
|
|
showEditorOptions={showEditorOptions}
|
|
|
|
closeEditorOptions={closeEditorOptions}
|
|
|
|
showKeyboardShortcutModal={showKeyboardShortcutModal}
|
|
|
|
setUnsavedChanges={setUnsavedChanges}
|
|
|
|
isPlaying={ide.isPlaying}
|
|
|
|
theme={preferences.theme}
|
|
|
|
startRefreshSketch={startRefreshSketch}
|
|
|
|
stopSketch={stopSketch}
|
|
|
|
autorefresh={preferences.autorefresh}
|
|
|
|
unsavedChanges={ide.unsavedChanges}
|
|
|
|
projectSavedTime={project.updatedAt}
|
|
|
|
isExpanded={ide.sidebarIsExpanded}
|
|
|
|
expandSidebar={expandSidebar}
|
|
|
|
collapseSidebar={collapseSidebar}
|
2020-06-15 21:59:21 +00:00
|
|
|
isUserOwner={isUserOwner(props)}
|
2020-06-15 21:47:08 +00:00
|
|
|
clearConsole={clearConsole}
|
|
|
|
consoleEvents={console}
|
|
|
|
showRuntimeErrorWarning={showRuntimeErrorWarning}
|
|
|
|
hideRuntimeErrorWarning={hideRuntimeErrorWarning}
|
|
|
|
runtimeErrorWarningVisible={ide.runtimeErrorWarningVisible}
|
2020-06-15 20:59:11 +00:00
|
|
|
provideController={setTmController}
|
|
|
|
/>
|
2020-06-18 19:01:13 +00:00
|
|
|
</IDEWrapper>
|
2020-07-22 18:37:44 +00:00
|
|
|
|
2020-07-20 21:51:42 +00:00
|
|
|
<Footer>
|
2020-07-24 21:11:10 +00:00
|
|
|
{ide.consoleIsExpanded && (
|
|
|
|
<Expander expanded>
|
|
|
|
<Console />
|
|
|
|
</Expander>
|
|
|
|
)}
|
2020-07-21 15:14:58 +00:00
|
|
|
<ActionStrip />
|
2020-07-15 20:24:12 +00:00
|
|
|
</Footer>
|
2020-07-21 22:03:22 +00:00
|
|
|
|
2020-07-24 19:30:14 +00:00
|
|
|
<OverlayManager
|
|
|
|
// ref={overlayRef}
|
2020-07-22 21:48:24 +00:00
|
|
|
overlay={overlayName}
|
|
|
|
hideOverlay={hideOverlay}
|
2020-07-24 19:30:14 +00:00
|
|
|
/>
|
2020-06-15 20:46:56 +00:00
|
|
|
</Screen>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-06-22 18:10:20 +00:00
|
|
|
MobileIDEView.propTypes = {
|
2020-06-15 20:46:56 +00:00
|
|
|
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,
|
2020-07-24 21:11:10 +00:00
|
|
|
autorefresh: PropTypes.bool.isRequired,
|
2020-06-15 20:46:56 +00:00
|
|
|
}).isRequired,
|
|
|
|
|
|
|
|
ide: PropTypes.shape({
|
|
|
|
isPlaying: PropTypes.bool.isRequired,
|
|
|
|
isAccessibleOutputPlaying: PropTypes.bool.isRequired,
|
2020-07-28 14:17:49 +00:00
|
|
|
consoleEvent: PropTypes.array,
|
2020-06-15 20:46:56 +00:00
|
|
|
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,
|
2020-07-24 21:11:10 +00:00
|
|
|
uploadFileModalVisible: PropTypes.bool.isRequired,
|
2020-06-15 20:46:56 +00:00
|
|
|
}).isRequired,
|
|
|
|
|
|
|
|
editorAccessibility: PropTypes.shape({
|
2020-07-28 14:17:49 +00:00
|
|
|
lintMessages: PropTypes.array.isRequired,
|
2020-06-15 20:46:56 +00:00
|
|
|
}).isRequired,
|
|
|
|
|
|
|
|
project: PropTypes.shape({
|
|
|
|
id: PropTypes.string,
|
|
|
|
name: PropTypes.string.isRequired,
|
|
|
|
owner: PropTypes.shape({
|
|
|
|
username: PropTypes.string,
|
2020-07-24 21:11:10 +00:00
|
|
|
id: PropTypes.string,
|
2020-06-15 20:46:56 +00:00
|
|
|
}),
|
2020-07-24 21:11:10 +00:00
|
|
|
updatedAt: PropTypes.string,
|
2020-06-15 20:46:56 +00:00
|
|
|
}).isRequired,
|
|
|
|
|
2020-06-19 01:00:24 +00:00
|
|
|
startSketch: PropTypes.func.isRequired,
|
|
|
|
|
2020-06-15 20:46:56 +00:00
|
|
|
updateLintMessage: PropTypes.func.isRequired,
|
|
|
|
|
|
|
|
clearLintMessage: PropTypes.func.isRequired,
|
|
|
|
|
|
|
|
selectedFile: PropTypes.shape({
|
|
|
|
id: PropTypes.string.isRequired,
|
|
|
|
content: PropTypes.string.isRequired,
|
2020-07-24 21:11:10 +00:00
|
|
|
name: PropTypes.string.isRequired,
|
2020-06-15 20:46:56 +00:00
|
|
|
}).isRequired,
|
|
|
|
|
|
|
|
updateFileContent: PropTypes.func.isRequired,
|
|
|
|
|
|
|
|
files: PropTypes.arrayOf(PropTypes.shape({
|
|
|
|
id: PropTypes.string.isRequired,
|
|
|
|
name: PropTypes.string.isRequired,
|
2020-07-24 21:11:10 +00:00
|
|
|
content: PropTypes.string.isRequired,
|
2020-06-15 20:46:56 +00:00
|
|
|
})).isRequired,
|
|
|
|
|
|
|
|
closeEditorOptions: PropTypes.func.isRequired,
|
|
|
|
|
|
|
|
showEditorOptions: PropTypes.func.isRequired,
|
|
|
|
|
|
|
|
showKeyboardShortcutModal: PropTypes.func.isRequired,
|
|
|
|
|
|
|
|
setUnsavedChanges: PropTypes.func.isRequired,
|
|
|
|
|
|
|
|
startRefreshSketch: PropTypes.func.isRequired,
|
|
|
|
|
|
|
|
stopSketch: PropTypes.func.isRequired,
|
|
|
|
|
|
|
|
expandSidebar: PropTypes.func.isRequired,
|
|
|
|
|
|
|
|
collapseSidebar: PropTypes.func.isRequired,
|
|
|
|
|
|
|
|
clearConsole: PropTypes.func.isRequired,
|
|
|
|
|
|
|
|
console: PropTypes.arrayOf(PropTypes.shape({
|
|
|
|
method: PropTypes.string.isRequired,
|
2020-07-24 21:11:10 +00:00
|
|
|
args: PropTypes.arrayOf(PropTypes.string),
|
2020-06-15 20:46:56 +00:00
|
|
|
})).isRequired,
|
|
|
|
|
|
|
|
showRuntimeErrorWarning: PropTypes.func.isRequired,
|
|
|
|
|
|
|
|
hideRuntimeErrorWarning: PropTypes.func.isRequired,
|
|
|
|
|
2020-06-15 21:59:21 +00:00
|
|
|
user: PropTypes.shape({
|
|
|
|
authenticated: PropTypes.bool.isRequired,
|
|
|
|
id: PropTypes.string,
|
2020-07-24 21:11:10 +00:00
|
|
|
username: PropTypes.string,
|
2020-06-15 21:59:21 +00:00
|
|
|
}).isRequired,
|
2020-06-15 20:46:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function mapStateToProps(state) {
|
|
|
|
return {
|
|
|
|
files: state.files,
|
2020-07-24 21:11:10 +00:00
|
|
|
selectedFile:
|
|
|
|
state.files.find(file => file.isSelectedFile) ||
|
2020-06-15 20:46:56 +00:00
|
|
|
state.files.find(file => file.name === 'sketch.js') ||
|
|
|
|
state.files.find(file => file.name !== 'root'),
|
|
|
|
htmlFile: getHTMLFile(state.files),
|
|
|
|
ide: state.ide,
|
|
|
|
preferences: state.preferences,
|
|
|
|
editorAccessibility: state.editorAccessibility,
|
|
|
|
user: state.user,
|
|
|
|
project: state.project,
|
|
|
|
toast: state.toast,
|
2020-07-24 21:11:10 +00:00
|
|
|
console: state.console,
|
2020-06-15 20:46:56 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps(dispatch) {
|
|
|
|
return bindActionCreators(
|
|
|
|
Object.assign(
|
|
|
|
{},
|
|
|
|
EditorAccessibilityActions,
|
|
|
|
FileActions,
|
|
|
|
ProjectActions,
|
|
|
|
IDEActions,
|
|
|
|
PreferencesActions,
|
|
|
|
UserActions,
|
|
|
|
ToastActions,
|
|
|
|
ConsoleActions
|
|
|
|
),
|
|
|
|
dispatch
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-06-22 18:10:20 +00:00
|
|
|
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(MobileIDEView));
|