Skip to content

Commit b8fb51d

Browse files
committed
Fix merge conflict for cherry-picking 0b8e78d
1 parent 36d2028 commit b8fb51d

File tree

8 files changed

+138
-35
lines changed

8 files changed

+138
-35
lines changed

client/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ export const SHOW_NEW_FOLDER_MODAL = 'SHOW_NEW_FOLDER_MODAL';
8080
export const CLOSE_NEW_FOLDER_MODAL = 'CLOSE_NEW_FOLDER_MODAL';
8181
export const SHOW_FOLDER_CHILDREN = 'SHOW_FOLDER_CHILDREN';
8282
export const HIDE_FOLDER_CHILDREN = 'HIDE_FOLDER_CHILDREN';
83+
export const OPEN_UPLOAD_FILE_MODAL = 'OPEN_UPLOAD_FILE_MODAL';
84+
export const CLOSE_UPLOAD_FILE_MODAL = 'CLOSE_UPLOAD_FILE_MODAL';
8385

8486
export const SHOW_SHARE_MODAL = 'SHOW_SHARE_MODAL';
8587
export const CLOSE_SHARE_MODAL = 'CLOSE_SHARE_MODAL';

client/modules/IDE/actions/ide.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ export function closeNewFileModal() {
7575
};
7676
}
7777

78+
export function openUploadFileModal() {
79+
return {
80+
type: ActionTypes.OPEN_UPLOAD_FILE_MODAL
81+
};
82+
}
83+
84+
export function closeUploadFileModal() {
85+
return {
86+
type: ActionTypes.CLOSE_UPLOAD_FILE_MODAL
87+
};
88+
}
89+
7890
export function expandSidebar() {
7991
return {
8092
type: ActionTypes.EXPAND_SIDEBAR
Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import PropTypes from 'prop-types';
22
import React from 'react';
3+
import { connect } from 'react-redux';
4+
import { bindActionCreators, compose } from 'redux';
35
import { reduxForm } from 'redux-form';
4-
import classNames from 'classnames';
56
import InlineSVG from 'react-inlinesvg';
67
import NewFileForm from './NewFileForm';
7-
import FileUploader from './FileUploader';
8+
import { getCanUploadMedia, getreachedTotalSizeLimit } from '../selectors/users';
9+
import { closeNewFileModal } from '../actions/ide';
10+
import { createFile } from '../actions/files';
811
import { CREATE_FILE_REGEX } from '../../../../server/utils/fileUtils';
912

1013
const exitUrl = require('../../../images/exit.svg');
@@ -28,43 +31,28 @@ class NewFileModal extends React.Component {
2831
}
2932

3033
render() {
31-
const modalClass = classNames({
32-
'modal': true,
33-
'modal--reduced': !this.props.canUploadMedia
34-
});
3534
return (
36-
<section className={modalClass} ref={(element) => { this.modal = element; }}>
35+
<section className="modal" ref={(element) => { this.modal = element; }}>
3736
<div className="modal-content">
3837
<div className="modal__header">
39-
<h2 className="modal__title">Add File</h2>
40-
<button className="modal__exit-button" onClick={this.props.closeModal}>
38+
<h2 className="modal__title">Create File</h2>
39+
<button className="modal__exit-button" onClick={this.props.closeNewFileModal}>
4140
<InlineSVG src={exitUrl} alt="Close New File Modal" />
4241
</button>
4342
</div>
4443
<NewFileForm
4544
focusOnModal={this.focusOnModal}
4645
{...this.props}
4746
/>
48-
{(() => {
49-
if (this.props.canUploadMedia) {
50-
return (
51-
<div>
52-
<p className="modal__divider">OR</p>
53-
<FileUploader />
54-
</div>
55-
);
56-
}
57-
return '';
58-
})()}
5947
</div>
6048
</section>
6149
);
6250
}
6351
}
6452

6553
NewFileModal.propTypes = {
66-
closeModal: PropTypes.func.isRequired,
67-
canUploadMedia: PropTypes.bool.isRequired
54+
createFile: PropTypes.func.isRequired,
55+
closeNewFileModal: PropTypes.func.isRequired
6856
};
6957

7058
function validate(formProps) {
@@ -79,9 +67,22 @@ function validate(formProps) {
7967
return errors;
8068
}
8169

70+
function mapStateToProps(state) {
71+
return {
72+
canUploadMedia: getCanUploadMedia(state),
73+
reachedTotalSizeLimit: getreachedTotalSizeLimit(state)
74+
};
75+
}
76+
77+
function mapDispatchToProps(dispatch) {
78+
return bindActionCreators({ createFile, closeNewFileModal }, dispatch);
79+
}
8280

83-
export default reduxForm({
84-
form: 'new-file',
85-
fields: ['name'],
86-
validate
87-
})(NewFileModal);
81+
export default compose(
82+
connect(mapStateToProps, mapDispatchToProps),
83+
reduxForm({
84+
form: 'new-file',
85+
fields: ['name'],
86+
validate
87+
})
88+
)(NewFileModal);

client/modules/IDE/components/Sidebar.jsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,19 @@ class Sidebar extends React.Component {
113113
Add file
114114
</button>
115115
</li>
116+
<li>
117+
<button
118+
aria-label="upload file"
119+
onClick={() => {
120+
this.props.openUploadFileModal();
121+
setTimeout(this.props.closeProjectOptions, 0);
122+
}}
123+
onBlur={this.onBlurComponent}
124+
onFocus={this.onFocusComponent}
125+
>
126+
Add file
127+
</button>
128+
</li>
116129
</ul>
117130
</div>
118131
</div>
@@ -137,6 +150,7 @@ Sidebar.propTypes = {
137150
openProjectOptions: PropTypes.func.isRequired,
138151
closeProjectOptions: PropTypes.func.isRequired,
139152
newFolder: PropTypes.func.isRequired,
153+
openUploadFileModal: PropTypes.func.isRequired,
140154
owner: PropTypes.shape({
141155
id: PropTypes.string
142156
}),
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { connect } from 'react-redux';
4+
import { Link } from 'react-router';
5+
import FileUploader from './FileUploader';
6+
import { getreachedTotalSizeLimit } from '../selectors/users';
7+
8+
class UploadFileModal extends React.Component {
9+
propTypes = {
10+
reachedTotalSizeLimit: PropTypes.bool.isRequired
11+
}
12+
13+
render() {
14+
return (
15+
<section className="modal" ref={(element) => { this.modal = element; }}>
16+
{ this.props.reachedTotalSizeLimit &&
17+
<p>
18+
{
19+
`You have reached the size limit for the number of files you can upload to your account.
20+
If you would like to upload more, please remove the ones you aren't using anymore by
21+
looking through your `
22+
}
23+
<Link to="/assets">assets</Link>
24+
{'.'}
25+
</p>
26+
}
27+
{ !this.props.reachedTotalSizeLimit &&
28+
<div>
29+
<FileUploader />
30+
</div>
31+
}
32+
</section>
33+
);
34+
}
35+
}
36+
37+
function mapStateToProps(state) {
38+
return {
39+
reachedTotalSizeLimit: getreachedTotalSizeLimit(state)
40+
};
41+
}
42+
43+
export default connect(mapStateToProps)(UploadFileModal);

client/modules/IDE/pages/IDEView.jsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Toolbar from '../components/Toolbar';
1212
import Preferences from '../components/Preferences';
1313
import NewFileModal from '../components/NewFileModal';
1414
import NewFolderModal from '../components/NewFolderModal';
15+
import UploadFileModal from '../components/UploadFileModal';
1516
import ShareModal from '../components/ShareModal';
1617
import KeyboardShortcutModal from '../components/KeyboardShortcutModal';
1718
import ErrorModal from '../components/ErrorModal';
@@ -349,19 +350,20 @@ class IDEView extends React.Component {
349350
</SplitPane>
350351
</SplitPane>
351352
</div>
352-
{this.props.ide.modalIsVisible &&
353-
<NewFileModal
354-
canUploadMedia={this.props.user.authenticated}
355-
closeModal={this.props.closeNewFileModal}
356-
createFile={this.props.createFile}
357-
/>
353+
{ this.props.ide.modalIsVisible &&
354+
<NewFileModal />
358355
}
359356
{this.props.ide.newFolderModalVisible &&
360357
<NewFolderModal
361358
closeModal={this.props.closeNewFolderModal}
362359
createFolder={this.props.createFolder}
363360
/>
364361
}
362+
{this.props.ide.uploadFileModalVisible &&
363+
<UploadFileModal
364+
closeModal={this.props.closeUploadFileModal}
365+
/>
366+
}
365367
{ this.props.location.pathname === '/about' &&
366368
<Overlay
367369
title="About"
@@ -475,6 +477,7 @@ IDEView.propTypes = {
475477
justOpenedProject: PropTypes.bool.isRequired,
476478
errorType: PropTypes.string,
477479
runtimeErrorWarningVisible: PropTypes.bool.isRequired,
480+
uploadFileModalVisible: PropTypes.bool.isRequired
478481
}).isRequired,
479482
stopSketch: PropTypes.func.isRequired,
480483
project: PropTypes.shape({
@@ -532,7 +535,6 @@ IDEView.propTypes = {
532535
}).isRequired,
533536
dispatchConsoleEvent: PropTypes.func.isRequired,
534537
newFile: PropTypes.func.isRequired,
535-
closeNewFileModal: PropTypes.func.isRequired,
536538
expandSidebar: PropTypes.func.isRequired,
537539
collapseSidebar: PropTypes.func.isRequired,
538540
cloneProject: PropTypes.func.isRequired,
@@ -545,7 +547,6 @@ IDEView.propTypes = {
545547
newFolder: PropTypes.func.isRequired,
546548
closeNewFolderModal: PropTypes.func.isRequired,
547549
createFolder: PropTypes.func.isRequired,
548-
createFile: PropTypes.func.isRequired,
549550
closeShareModal: PropTypes.func.isRequired,
550551
showEditorOptions: PropTypes.func.isRequired,
551552
closeEditorOptions: PropTypes.func.isRequired,
@@ -577,6 +578,7 @@ IDEView.propTypes = {
577578
showRuntimeErrorWarning: PropTypes.func.isRequired,
578579
hideRuntimeErrorWarning: PropTypes.func.isRequired,
579580
startSketch: PropTypes.func.isRequired,
581+
closeUploadFileModal: PropTypes.func.isRequired
580582
};
581583

582584
function mapStateToProps(state) {

client/modules/IDE/reducers/ide.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const initialState = {
99
preferencesIsVisible: false,
1010
projectOptionsVisible: false,
1111
newFolderModalVisible: false,
12+
uploadFileModalVisible: false,
1213
shareModalVisible: false,
1314
shareModalProjectId: 'abcd',
1415
shareModalProjectName: 'My Cute Sketch',
@@ -105,6 +106,10 @@ const ide = (state = initialState, action) => {
105106
return Object.assign({}, state, { runtimeErrorWarningVisible: false });
106107
case ActionTypes.SHOW_RUNTIME_ERROR_WARNING:
107108
return Object.assign({}, state, { runtimeErrorWarningVisible: true });
109+
case ActionTypes.OPEN_UPLOAD_FILE_MODAL:
110+
return Object.assign({}, state, { uploadFileModalVisible: true });
111+
case ActionTypes.CLOSE_UPLOAD_FILE_MODAL:
112+
return Object.assign({}, state, { uploadFileModalVisible: false });
108113
default:
109114
return state;
110115
}

client/modules/IDE/selectors/users.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { createSelector } from 'reselect';
2+
3+
const getAuthenticated = state => state.user.authenticated;
4+
const getTotalSize = state => state.user.totalSize;
5+
6+
export const getCanUploadMedia = createSelector(
7+
getAuthenticated,
8+
getTotalSize,
9+
(authenticated, totalSize) => {
10+
if (!authenticated) return false;
11+
// eventually do the same thing for verified when
12+
// email verification actually works
13+
if (totalSize > 250000000) return false;
14+
return true;
15+
}
16+
);
17+
18+
export const getreachedTotalSizeLimit = createSelector(
19+
getTotalSize,
20+
(totalSize) => {
21+
if (totalSize > 250000000) return true;
22+
return false;
23+
}
24+
);

0 commit comments

Comments
 (0)