Skip to content

Commit 0b8e78d

Browse files
committed
an incremental step in separating upload file and new file modals
1 parent eb93e1e commit 0b8e78d

File tree

8 files changed

+137
-34
lines changed

8 files changed

+137
-34
lines changed

client/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ export const SHOW_NEW_FOLDER_MODAL = 'SHOW_NEW_FOLDER_MODAL';
7272
export const CLOSE_NEW_FOLDER_MODAL = 'CLOSE_NEW_FOLDER_MODAL';
7373
export const SHOW_FOLDER_CHILDREN = 'SHOW_FOLDER_CHILDREN';
7474
export const HIDE_FOLDER_CHILDREN = 'HIDE_FOLDER_CHILDREN';
75+
export const OPEN_UPLOAD_FILE_MODAL = 'OPEN_UPLOAD_FILE_MODAL';
76+
export const CLOSE_UPLOAD_FILE_MODAL = 'CLOSE_UPLOAD_FILE_MODAL';
7577

7678
export const SHOW_SHARE_MODAL = 'SHOW_SHARE_MODAL';
7779
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
@@ -74,6 +74,18 @@ export function closeNewFileModal() {
7474
};
7575
}
7676

77+
export function openUploadFileModal() {
78+
return {
79+
type: ActionTypes.OPEN_UPLOAD_FILE_MODAL
80+
};
81+
}
82+
83+
export function closeUploadFileModal() {
84+
return {
85+
type: ActionTypes.CLOSE_UPLOAD_FILE_MODAL
86+
};
87+
}
88+
7789
export function expandSidebar() {
7890
return {
7991
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

912
const exitUrl = require('../../../images/exit.svg');
1013

@@ -27,43 +30,28 @@ class NewFileModal extends React.Component {
2730
}
2831

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

6452
NewFileModal.propTypes = {
65-
closeModal: PropTypes.func.isRequired,
66-
canUploadMedia: PropTypes.bool.isRequired
53+
createFile: PropTypes.func.isRequired,
54+
closeNewFileModal: PropTypes.func.isRequired
6755
};
6856

6957
function validate(formProps) {
@@ -78,9 +66,22 @@ function validate(formProps) {
7866
return errors;
7967
}
8068

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

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

client/modules/IDE/components/Sidebar.jsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,19 @@ class Sidebar extends React.Component {
112112
Add file
113113
</button>
114114
</li>
115+
<li>
116+
<button
117+
aria-label="upload file"
118+
onClick={() => {
119+
this.props.openUploadFileModal();
120+
setTimeout(this.props.closeProjectOptions, 0);
121+
}}
122+
onBlur={this.onBlurComponent}
123+
onFocus={this.onFocusComponent}
124+
>
125+
Add file
126+
</button>
127+
</li>
115128
</ul>
116129
</div>
117130
</div>
@@ -136,6 +149,7 @@ Sidebar.propTypes = {
136149
openProjectOptions: PropTypes.func.isRequired,
137150
closeProjectOptions: PropTypes.func.isRequired,
138151
newFolder: PropTypes.func.isRequired,
152+
openUploadFileModal: PropTypes.func.isRequired,
139153
owner: PropTypes.shape({
140154
id: PropTypes.string
141155
}),
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: 9 additions & 7 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';
@@ -357,18 +358,19 @@ class IDEView extends React.Component {
357358
</SplitPane>
358359
</div>
359360
{ this.props.ide.modalIsVisible &&
360-
<NewFileModal
361-
canUploadMedia={this.props.user.authenticated}
362-
closeModal={this.props.closeNewFileModal}
363-
createFile={this.props.createFile}
364-
/>
361+
<NewFileModal />
365362
}
366363
{ this.props.ide.newFolderModalVisible &&
367364
<NewFolderModal
368365
closeModal={this.props.closeNewFolderModal}
369366
createFolder={this.props.createFolder}
370367
/>
371368
}
369+
{this.props.ide.uploadFileModalVisible &&
370+
<UploadFileModal
371+
closeModal={this.props.closeUploadFileModal}
372+
/>
373+
}
372374
{ this.props.location.pathname.match(/sketches$/) &&
373375
<Overlay
374376
ariaLabel="project list"
@@ -501,6 +503,7 @@ IDEView.propTypes = {
501503
errorType: PropTypes.string,
502504
helpType: PropTypes.string,
503505
runtimeErrorWarningVisible: PropTypes.bool.isRequired,
506+
uploadFileModalVisible: PropTypes.bool.isRequired
504507
}).isRequired,
505508
stopSketch: PropTypes.func.isRequired,
506509
project: PropTypes.shape({
@@ -558,7 +561,6 @@ IDEView.propTypes = {
558561
}).isRequired,
559562
dispatchConsoleEvent: PropTypes.func.isRequired,
560563
newFile: PropTypes.func.isRequired,
561-
closeNewFileModal: PropTypes.func.isRequired,
562564
expandSidebar: PropTypes.func.isRequired,
563565
collapseSidebar: PropTypes.func.isRequired,
564566
cloneProject: PropTypes.func.isRequired,
@@ -571,7 +573,6 @@ IDEView.propTypes = {
571573
newFolder: PropTypes.func.isRequired,
572574
closeNewFolderModal: PropTypes.func.isRequired,
573575
createFolder: PropTypes.func.isRequired,
574-
createFile: PropTypes.func.isRequired,
575576
closeShareModal: PropTypes.func.isRequired,
576577
showEditorOptions: PropTypes.func.isRequired,
577578
closeEditorOptions: PropTypes.func.isRequired,
@@ -604,6 +605,7 @@ IDEView.propTypes = {
604605
showRuntimeErrorWarning: PropTypes.func.isRequired,
605606
hideRuntimeErrorWarning: PropTypes.func.isRequired,
606607
startSketch: PropTypes.func.isRequired,
608+
closeUploadFileModal: PropTypes.func.isRequired
607609
};
608610

609611
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',
@@ -108,6 +109,10 @@ const ide = (state = initialState, action) => {
108109
return Object.assign({}, state, { runtimeErrorWarningVisible: false });
109110
case ActionTypes.SHOW_RUNTIME_ERROR_WARNING:
110111
return Object.assign({}, state, { runtimeErrorWarningVisible: true });
112+
case ActionTypes.OPEN_UPLOAD_FILE_MODAL:
113+
return Object.assign({}, state, { uploadFileModalVisible: true });
114+
case ActionTypes.CLOSE_UPLOAD_FILE_MODAL:
115+
return Object.assign({}, state, { uploadFileModalVisible: false });
111116
default:
112117
return state;
113118
}

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)