From c29e4a1c527a4c8389c08c80e2ba3de54687eca1 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Tue, 24 Mar 2020 18:07:58 -0400 Subject: [PATCH] Close new file modal on enter, update upload limit selector to handle undefined case --- client/modules/IDE/actions/files.js | 12 +++++------- client/modules/IDE/components/NewFileModal.jsx | 8 ++------ client/modules/IDE/components/NewFolderForm.jsx | 4 +--- client/modules/IDE/selectors/users.js | 7 +++++-- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/client/modules/IDE/actions/files.js b/client/modules/IDE/actions/files.js index 0bbf292d..8fb230cc 100644 --- a/client/modules/IDE/actions/files.js +++ b/client/modules/IDE/actions/files.js @@ -3,7 +3,7 @@ import objectID from 'bson-objectid'; import blobUtil from 'blob-util'; import { reset } from 'redux-form'; import * as ActionTypes from '../../../constants'; -import { setUnsavedChanges } from './ide'; +import { setUnsavedChanges, closeNewFolderModal, closeNewFileModal } from './ide'; import { setProjectSavedTime } from './project'; const __process = (typeof global !== 'undefined' ? global : window).process; @@ -58,6 +58,7 @@ export function createFile(formProps) { parentId }); dispatch(setProjectSavedTime(response.data.project.updatedAt)); + dispatch(closeNewFileModal()); dispatch(reset('new-file')); // dispatch({ // type: ActionTypes.HIDE_MODAL @@ -85,6 +86,7 @@ export function createFile(formProps) { // type: ActionTypes.HIDE_MODAL // }); dispatch(setUnsavedChanges(true)); + dispatch(closeNewFileModal()); } }; } @@ -109,9 +111,7 @@ export function createFolder(formProps) { parentId }); dispatch(setProjectSavedTime(response.data.project.updatedAt)); - dispatch({ - type: ActionTypes.CLOSE_NEW_FOLDER_MODAL - }); + dispatch(closeNewFolderModal()); }) .catch(response => dispatch({ type: ActionTypes.ERROR, @@ -130,9 +130,7 @@ export function createFolder(formProps) { fileType: 'folder', children: [] }); - dispatch({ - type: ActionTypes.CLOSE_NEW_FOLDER_MODAL - }); + dispatch(closeNewFolderModal()); } }; } diff --git a/client/modules/IDE/components/NewFileModal.jsx b/client/modules/IDE/components/NewFileModal.jsx index e7747d2d..36c3cc4d 100644 --- a/client/modules/IDE/components/NewFileModal.jsx +++ b/client/modules/IDE/components/NewFileModal.jsx @@ -5,7 +5,6 @@ import { bindActionCreators, compose } from 'redux'; import { reduxForm } from 'redux-form'; import InlineSVG from 'react-inlinesvg'; import NewFileForm from './NewFileForm'; -import { getCanUploadMedia, getreachedTotalSizeLimit } from '../selectors/users'; import { closeNewFileModal } from '../actions/ide'; import { createFile } from '../actions/files'; import { CREATE_FILE_REGEX } from '../../../../server/utils/fileUtils'; @@ -67,11 +66,8 @@ function validate(formProps) { return errors; } -function mapStateToProps(state) { - return { - canUploadMedia: getCanUploadMedia(state), - reachedTotalSizeLimit: getreachedTotalSizeLimit(state) - }; +function mapStateToProps() { + return {}; } function mapDispatchToProps(dispatch) { diff --git a/client/modules/IDE/components/NewFolderForm.jsx b/client/modules/IDE/components/NewFolderForm.jsx index 92b91442..5fa48acd 100644 --- a/client/modules/IDE/components/NewFolderForm.jsx +++ b/client/modules/IDE/components/NewFolderForm.jsx @@ -20,9 +20,7 @@ class NewFolderForm extends React.Component {
{ - if (handleSubmit(this.createFolder)(data)) { - this.props.closeModal(); - } + handleSubmit(this.createFolder)(data); }} >
diff --git a/client/modules/IDE/selectors/users.js b/client/modules/IDE/selectors/users.js index c656e283..556d99dd 100644 --- a/client/modules/IDE/selectors/users.js +++ b/client/modules/IDE/selectors/users.js @@ -3,6 +3,7 @@ import { createSelector } from 'reselect'; const __process = (typeof global !== 'undefined' ? global : window).process; const getAuthenticated = state => state.user.authenticated; const getTotalSize = state => state.user.totalSize; +const getAssetsTotalSize = state => state.assets.totalSize; const limit = __process.env.UPLOAD_LIMIT || 250000000; export const getCanUploadMedia = createSelector( @@ -19,8 +20,10 @@ export const getCanUploadMedia = createSelector( export const getreachedTotalSizeLimit = createSelector( getTotalSize, - (totalSize) => { - if (totalSize > limit) return true; + getAssetsTotalSize, + (totalSize, assetsTotalSize) => { + const currentSize = totalSize || assetsTotalSize; + if (currentSize && currentSize > limit) return true; // if (totalSize > 1000) return true; return false; }