2020-06-09 21:29:20 +02:00
|
|
|
import React from 'react';
|
2020-06-09 21:51:57 +02:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import styled from 'styled-components';
|
2020-06-16 21:52:35 +02:00
|
|
|
import { Link } from 'react-router';
|
2020-06-15 22:46:56 +02:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { withRouter } from 'react-router';
|
|
|
|
import { useState } from 'react';
|
2020-06-12 21:09:30 +02:00
|
|
|
|
2020-06-15 22:46:56 +02:00
|
|
|
// Imports to be Refactored
|
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
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-06-09 22:35:06 +02:00
|
|
|
import { prop, remSize } from '../../../theme';
|
2020-06-18 21:34:28 +02:00
|
|
|
import { ExitIcon } from '../../../common/icons';
|
2020-06-15 22:46:56 +02:00
|
|
|
|
2020-06-09 22:35:06 +02:00
|
|
|
const background = prop('Button.default.background');
|
|
|
|
const textColor = prop('primaryTextColor');
|
2020-06-09 21:29:20 +02:00
|
|
|
|
2020-06-15 23:34:04 +02:00
|
|
|
|
2020-06-09 21:51:57 +02:00
|
|
|
const Header = styled.div`
|
2020-06-15 22:46:56 +02:00
|
|
|
position: fixed;
|
2020-06-09 21:51:57 +02:00
|
|
|
width: 100%;
|
2020-06-15 23:34:04 +02:00
|
|
|
background: ${background};
|
2020-06-09 22:35:06 +02:00
|
|
|
color: ${textColor};
|
2020-06-15 22:59:11 +02:00
|
|
|
padding: ${remSize(12)};
|
2020-06-09 22:35:06 +02:00
|
|
|
padding-left: ${remSize(32)};
|
2020-06-15 23:34:04 +02:00
|
|
|
padding-right: ${remSize(32)};
|
2020-06-15 22:59:11 +02:00
|
|
|
z-index: 1;
|
2020-06-15 23:34:04 +02:00
|
|
|
|
|
|
|
display: flex;
|
|
|
|
flex: 1;
|
|
|
|
flex-direction: row;
|
2020-06-16 21:52:35 +02:00
|
|
|
justify-content: flex-start;
|
2020-06-15 23:34:04 +02:00
|
|
|
align-items: center;
|
2020-06-09 21:51:57 +02:00
|
|
|
`;
|
|
|
|
|
|
|
|
const Footer = styled.div`
|
2020-06-15 22:46:56 +02:00
|
|
|
position: fixed;
|
2020-06-15 23:34:04 +02:00
|
|
|
width: 100%;
|
2020-06-09 22:35:06 +02:00
|
|
|
background: ${background};
|
|
|
|
color: ${textColor};
|
2020-06-15 23:34:04 +02:00
|
|
|
padding: ${remSize(12)};
|
2020-06-09 22:35:06 +02:00
|
|
|
padding-left: ${remSize(32)};
|
2020-06-15 23:34:04 +02:00
|
|
|
z-index: 1;
|
|
|
|
|
|
|
|
bottom: 0;
|
2020-06-09 21:51:57 +02:00
|
|
|
`;
|
|
|
|
|
2020-06-15 22:46:56 +02:00
|
|
|
const Content = styled.div`
|
2020-06-15 22:59:11 +02:00
|
|
|
z-index: 0;
|
|
|
|
margin-top: ${remSize(16)};
|
2020-06-15 22:46:56 +02:00
|
|
|
`;
|
|
|
|
|
2020-06-15 23:34:04 +02:00
|
|
|
const Icon = styled.a`
|
|
|
|
> svg {
|
|
|
|
fill: ${textColor};
|
|
|
|
color: ${textColor};
|
2020-06-15 23:52:40 +02:00
|
|
|
margin-left: ${remSize(16)};
|
2020-06-15 23:34:04 +02:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2020-06-18 19:21:09 +02:00
|
|
|
const IconLinkWrapper = styled(Link)`
|
2020-06-18 19:16:28 +02:00
|
|
|
width: 3rem;
|
|
|
|
margin-right: 1.25rem;
|
|
|
|
margin-left: none;
|
|
|
|
`;
|
|
|
|
|
2020-06-15 22:46:56 +02:00
|
|
|
|
2020-06-09 21:51:57 +02:00
|
|
|
const Screen = ({ children }) => (
|
|
|
|
<div className="fullscreen-preview">
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
Screen.propTypes = {
|
2020-06-09 22:08:14 +02:00
|
|
|
children: PropTypes.node.isRequired
|
2020-06-09 21:51:57 +02:00
|
|
|
};
|
|
|
|
|
2020-06-15 23:59:21 +02:00
|
|
|
const isUserOwner = ({ project, user }) => (project.owner && project.owner.id === user.id);
|
|
|
|
|
2020-06-15 22:46:56 +02:00
|
|
|
const IDEViewMobile = (props) => {
|
2020-06-15 22:59:11 +02:00
|
|
|
const {
|
|
|
|
preferences, ide, editorAccessibility, project, updateLintMessage, clearLintMessage, selectedFile, updateFileContent, files, closeEditorOptions, showEditorOptions, showKeyboardShortcutModal, setUnsavedChanges, startRefreshSketch, stopSketch, expandSidebar, collapseSidebar, clearConsole, console, showRuntimeErrorWarning, hideRuntimeErrorWarning
|
|
|
|
} = props;
|
2020-06-12 21:09:30 +02:00
|
|
|
|
2020-06-15 22:46:56 +02:00
|
|
|
const [tmController, setTmController] = useState(null);
|
2020-06-12 21:09:30 +02:00
|
|
|
|
2020-06-15 22:46:56 +02:00
|
|
|
return (
|
|
|
|
<Screen>
|
2020-06-15 22:59:11 +02:00
|
|
|
<Header>
|
2020-06-18 19:21:09 +02:00
|
|
|
<IconLinkWrapper to="/" aria-label="Return to original editor">
|
2020-06-18 21:34:28 +02:00
|
|
|
<ExitIcon />
|
2020-06-18 19:21:09 +02:00
|
|
|
</IconLinkWrapper>
|
2020-06-15 23:34:04 +02:00
|
|
|
<div>
|
|
|
|
<h2>{project.name}</h2>
|
|
|
|
<h3>{selectedFile.name}</h3>
|
|
|
|
</div>
|
2020-06-15 22:59:11 +02:00
|
|
|
</Header>
|
2020-06-12 21:09:30 +02:00
|
|
|
|
2020-06-15 22:59:11 +02:00
|
|
|
<Content>
|
|
|
|
<Editor
|
2020-06-15 23:47:08 +02: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 23:59:21 +02:00
|
|
|
isUserOwner={isUserOwner(props)}
|
2020-06-15 23:47:08 +02:00
|
|
|
clearConsole={clearConsole}
|
|
|
|
consoleEvents={console}
|
|
|
|
showRuntimeErrorWarning={showRuntimeErrorWarning}
|
|
|
|
hideRuntimeErrorWarning={hideRuntimeErrorWarning}
|
|
|
|
runtimeErrorWarningVisible={ide.runtimeErrorWarningVisible}
|
2020-06-15 22:59:11 +02:00
|
|
|
provideController={setTmController}
|
|
|
|
/>
|
|
|
|
</Content>
|
2020-06-15 23:34:04 +02:00
|
|
|
<Footer><h2>Bottom Bar</h2></Footer>
|
2020-06-15 22:46:56 +02:00
|
|
|
</Screen>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
IDEViewMobile.propTypes = {
|
|
|
|
|
|
|
|
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,
|
|
|
|
uploadFileModalVisible: PropTypes.bool.isRequired
|
|
|
|
}).isRequired,
|
|
|
|
|
|
|
|
editorAccessibility: PropTypes.shape({
|
|
|
|
lintMessages: PropTypes.array.isRequired,
|
|
|
|
}).isRequired,
|
|
|
|
|
|
|
|
project: PropTypes.shape({
|
|
|
|
id: PropTypes.string,
|
|
|
|
name: PropTypes.string.isRequired,
|
|
|
|
owner: PropTypes.shape({
|
|
|
|
username: PropTypes.string,
|
|
|
|
id: PropTypes.string
|
|
|
|
}),
|
|
|
|
updatedAt: PropTypes.string
|
|
|
|
}).isRequired,
|
|
|
|
|
|
|
|
updateLintMessage: PropTypes.func.isRequired,
|
|
|
|
|
|
|
|
clearLintMessage: PropTypes.func.isRequired,
|
|
|
|
|
|
|
|
selectedFile: PropTypes.shape({
|
|
|
|
id: PropTypes.string.isRequired,
|
|
|
|
content: PropTypes.string.isRequired,
|
|
|
|
name: PropTypes.string.isRequired
|
|
|
|
}).isRequired,
|
|
|
|
|
|
|
|
updateFileContent: PropTypes.func.isRequired,
|
|
|
|
|
|
|
|
files: PropTypes.arrayOf(PropTypes.shape({
|
|
|
|
id: PropTypes.string.isRequired,
|
|
|
|
name: PropTypes.string.isRequired,
|
|
|
|
content: PropTypes.string.isRequired
|
|
|
|
})).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,
|
|
|
|
args: PropTypes.arrayOf(PropTypes.string)
|
|
|
|
})).isRequired,
|
|
|
|
|
|
|
|
showRuntimeErrorWarning: PropTypes.func.isRequired,
|
|
|
|
|
|
|
|
hideRuntimeErrorWarning: PropTypes.func.isRequired,
|
|
|
|
|
2020-06-15 23:59:21 +02:00
|
|
|
user: PropTypes.shape({
|
|
|
|
authenticated: PropTypes.bool.isRequired,
|
|
|
|
id: PropTypes.string,
|
|
|
|
username: PropTypes.string
|
|
|
|
}).isRequired,
|
2020-06-15 22:46:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function mapStateToProps(state) {
|
|
|
|
return {
|
|
|
|
files: state.files,
|
|
|
|
selectedFile: state.files.find(file => file.isSelectedFile) ||
|
|
|
|
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,
|
|
|
|
console: state.console
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps(dispatch) {
|
|
|
|
return bindActionCreators(
|
|
|
|
Object.assign(
|
|
|
|
{},
|
|
|
|
EditorAccessibilityActions,
|
|
|
|
FileActions,
|
|
|
|
ProjectActions,
|
|
|
|
IDEActions,
|
|
|
|
PreferencesActions,
|
|
|
|
UserActions,
|
|
|
|
ToastActions,
|
|
|
|
ConsoleActions
|
|
|
|
),
|
|
|
|
dispatch
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(IDEViewMobile));
|