Skip to content

Commit 797bf9f

Browse files
committed
🔀 merge from develop
2 parents df5ac3f + 3253770 commit 797bf9f

File tree

11 files changed

+89
-31
lines changed

11 files changed

+89
-31
lines changed

client/modules/IDE/components/NewFileForm.jsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import PropTypes from 'prop-types';
22
import React from 'react';
3+
import { withTranslation } from 'react-i18next';
34
import { domOnlyProps } from '../../../utils/reduxFormUtils';
45

56
import Button from '../../../common/Button';
@@ -35,14 +36,17 @@ class NewFileForm extends React.Component {
3536
className="new-file-form__name-input"
3637
id="name"
3738
type="text"
38-
placeholder="Name"
39+
placeholder={this.props.t('NewFileForm.Placeholder')}
3940
maxLength="128"
4041
{...domOnlyProps(name)}
4142
ref={(element) => {
4243
this.fileName = element;
4344
}}
4445
/>
45-
<Button type="submit">Add File</Button>
46+
<Button
47+
type="submit"
48+
>{this.props.t('NewFileForm.AddFileSubmit')}
49+
</Button>
4650
</div>
4751
{name.touched && name.error && (
4852
<span className="form-error">{name.error}</span>
@@ -59,6 +63,7 @@ NewFileForm.propTypes = {
5963
handleSubmit: PropTypes.func.isRequired,
6064
createFile: PropTypes.func.isRequired,
6165
focusOnModal: PropTypes.func.isRequired,
66+
t: PropTypes.func.isRequired
6267
};
6368

64-
export default NewFileForm;
69+
export default withTranslation()(NewFileForm);

client/modules/IDE/components/NewFileModal.jsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import React from 'react';
33
import { connect } from 'react-redux';
44
import { bindActionCreators, compose } from 'redux';
55
import { reduxForm } from 'redux-form';
6+
import { withTranslation } from 'react-i18next';
7+
import i18n from 'i18next';
68
import NewFileForm from './NewFileForm';
79
import { closeNewFileModal } from '../actions/ide';
810
import { createFile } from '../actions/files';
@@ -33,11 +35,11 @@ class NewFileModal extends React.Component {
3335
<section className="modal" ref={(element) => { this.modal = element; }}>
3436
<div className="modal-content">
3537
<div className="modal__header">
36-
<h2 className="modal__title">Create File</h2>
38+
<h2 className="modal__title">{this.props.t('NewFileModal.Title')}</h2>
3739
<button
3840
className="modal__exit-button"
3941
onClick={this.props.closeNewFileModal}
40-
aria-label="Close New File Modal"
42+
aria-label={this.props.t('NewFileModal.CloseButtonARIA')}
4143
>
4244
<ExitIcon focusable="false" aria-hidden="true" />
4345
</button>
@@ -54,16 +56,17 @@ class NewFileModal extends React.Component {
5456

5557
NewFileModal.propTypes = {
5658
createFile: PropTypes.func.isRequired,
57-
closeNewFileModal: PropTypes.func.isRequired
59+
closeNewFileModal: PropTypes.func.isRequired,
60+
t: PropTypes.func.isRequired
5861
};
5962

6063
function validate(formProps) {
6164
const errors = {};
6265

6366
if (!formProps.name) {
64-
errors.name = 'Please enter a name';
67+
errors.name = i18n.t('NewFileModal.EnterName');
6568
} else if (!formProps.name.match(CREATE_FILE_REGEX)) {
66-
errors.name = 'Invalid file type. Valid extensions are .js, .css, .json, .txt, .csv, .tsv, .frag, and .vert.';
69+
errors.name = i18n.t('NewFileModal.InvalidType');
6770
}
6871

6972
return errors;
@@ -77,11 +80,11 @@ function mapDispatchToProps(dispatch) {
7780
return bindActionCreators({ createFile, closeNewFileModal }, dispatch);
7881
}
7982

80-
export default compose(
83+
export default withTranslation()(compose(
8184
connect(mapStateToProps, mapDispatchToProps),
8285
reduxForm({
8386
form: 'new-file',
8487
fields: ['name'],
8588
validate
8689
})
87-
)(NewFileModal);
90+
)(NewFileModal));

client/modules/IDE/components/NewFolderForm.jsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import PropTypes from 'prop-types';
22
import React from 'react';
3+
import { withTranslation } from 'react-i18next';
34
import { domOnlyProps } from '../../../utils/reduxFormUtils';
45

56
import Button from '../../../common/Button';
67

8+
79
class NewFolderForm extends React.Component {
810
constructor(props) {
911
super(props);
@@ -35,13 +37,14 @@ class NewFolderForm extends React.Component {
3537
id="name"
3638
type="text"
3739
maxLength="128"
38-
placeholder="Name"
39-
ref={(element) => {
40-
this.fileName = element;
41-
}}
40+
placeholder={this.props.t('NewFolderForm.Placeholder')}
41+
ref={(element) => { this.fileName = element; }}
4242
{...domOnlyProps(name)}
4343
/>
44-
<Button type="submit">Add Folder</Button>
44+
<Button
45+
type="submit"
46+
>{this.props.t('NewFolderForm.AddFolderSubmit')}
47+
</Button>
4548
</div>
4649
{name.touched && name.error && (
4750
<span className="form-error">{name.error}</span>
@@ -60,9 +63,10 @@ NewFolderForm.propTypes = {
6063
closeModal: PropTypes.func.isRequired,
6164
submitting: PropTypes.bool,
6265
pristine: PropTypes.bool,
66+
t: PropTypes.func.isRequired
6367
};
6468
NewFolderForm.defaultProps = {
6569
submitting: false,
6670
pristine: true,
6771
};
68-
export default NewFolderForm;
72+
export default withTranslation()(NewFolderForm);

client/modules/IDE/components/NewFolderModal.jsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import PropTypes from 'prop-types';
22
import React from 'react';
33
import { reduxForm } from 'redux-form';
4+
import { withTranslation } from 'react-i18next';
5+
import i18n from 'i18next';
46
import NewFolderForm from './NewFolderForm';
57

68
import ExitIcon from '../../../images/exit.svg';
@@ -15,11 +17,11 @@ class NewFolderModal extends React.Component {
1517
<section className="modal" ref={(element) => { this.newFolderModal = element; }} >
1618
<div className="modal-content-folder">
1719
<div className="modal__header">
18-
<h2 className="modal__title">Create Folder</h2>
20+
<h2 className="modal__title">{this.props.t('NewFolderModal.Title')}</h2>
1921
<button
2022
className="modal__exit-button"
2123
onClick={this.props.closeModal}
22-
aria-label="Close New Folder Modal"
24+
aria-label={this.props.t('NewFolderModal.CloseButtonARIA')}
2325
>
2426
<ExitIcon focusable="false" aria-hidden="true" />
2527
</button>
@@ -32,23 +34,24 @@ class NewFolderModal extends React.Component {
3234
}
3335

3436
NewFolderModal.propTypes = {
35-
closeModal: PropTypes.func.isRequired
37+
closeModal: PropTypes.func.isRequired,
38+
t: PropTypes.func.isRequired
3639
};
3740

3841
function validate(formProps) {
3942
const errors = {};
4043
if (!formProps.name) {
41-
errors.name = 'Please enter a name';
44+
errors.name = i18n.t('NewFolderModal.EnterName');
4245
} else if (formProps.name.trim().length === 0) {
43-
errors.name = 'Folder name cannot contain only spaces';
46+
errors.name = i18n.t('NewFolderModal.EmptyName');
4447
} else if (formProps.name.match(/\.+/i)) {
45-
errors.name = 'Folder name cannot contain an extension';
48+
errors.name = i18n.t('NewFolderModal.InvalidExtension');
4649
}
4750

4851
return errors;
4952
}
50-
export default reduxForm({
53+
export default withTranslation()(reduxForm({
5154
form: 'new-folder',
5255
fields: ['name'],
5356
validate
54-
})(NewFolderModal);
57+
})(NewFolderModal));

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "p5.js-web-editor",
3-
"version": "1.0.6",
3+
"version": "1.0.7",
44
"description": "The web editor for p5.js.",
55
"scripts": {
66
"clean": "rimraf dist",

server/controllers/project.controller.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ export function updateProject(req, res) {
3030
$set: req.body
3131
},
3232
{
33-
new: true
33+
new: true,
34+
runValidators: true
3435
}
3536
)
3637
.populate('user', 'username')
3738
.exec((updateProjectErr, updatedProject) => {
3839
if (updateProjectErr) {
3940
console.log(updateProjectErr);
40-
res.json({ success: false });
41+
res.status(400).json({ success: false });
4142
return;
4243
}
4344
if (req.body.files && updatedProject.files.length !== req.body.files.length) {
@@ -50,7 +51,7 @@ export function updateProject(req, res) {
5051
updatedProject.save((innerErr, savedProject) => {
5152
if (innerErr) {
5253
console.log(innerErr);
53-
res.json({ success: false });
54+
res.status(400).json({ success: false });
5455
return;
5556
}
5657
res.json(savedProject);

server/controllers/project.controller/createProject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default function createProject(req, res) {
99
projectValues = Object.assign(projectValues, req.body);
1010

1111
function sendFailure() {
12-
res.json({ success: false });
12+
res.status(400).json({ success: false });
1313
}
1414

1515
function populateUserData(newProject) {

server/models/project.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fileSchema.set('toJSON', {
2929

3030
const projectSchema = new Schema(
3131
{
32-
name: { type: String, default: "Hello p5.js, it's the server" },
32+
name: { type: String, default: "Hello p5.js, it's the server", maxlength: 128 },
3333
user: { type: Schema.Types.ObjectId, ref: 'User' },
3434
serveSecure: { type: Boolean, default: false },
3535
files: { type: [fileSchema] },

translations/locales/en-US/translations.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,5 +173,26 @@
173173
},
174174
"IDEView": {
175175
"SubmitFeedback": "Submit Feedback"
176+
},
177+
"NewFileModal": {
178+
"Title": "Create File",
179+
"CloseButtonARIA": "Close New File Modal",
180+
"EnterName": "Please enter a name",
181+
"InvalidType": "Invalid file type. Valid extensions are .js, .css, .json, .txt, .csv, .tsv, .frag, and .vert."
182+
},
183+
"NewFileForm": {
184+
"AddFileSubmit": "Add File",
185+
"Placeholder": "Name"
186+
},
187+
"NewFolderModal": {
188+
"Title": "Create Folder",
189+
"CloseButtonARIA": "Close New Folder Modal",
190+
"EnterName": "Please enter a name",
191+
"EmptyName": "Folder name cannot contain only spaces",
192+
"InvalidExtension": "Folder name cannot contain an extension"
193+
},
194+
"NewFolderForm": {
195+
"AddFolderSubmit": "Add Folder",
196+
"Placeholder": "Name"
176197
}
177198
}

translations/locales/es-419/translations.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,27 @@
172172
},
173173
"IDEView": {
174174
"SubmitFeedback": "Enviar retroalimentación"
175+
},
176+
"NewFileModal": {
177+
"Title": "Crear Archivo",
178+
"CloseButtonARIA": "Cerrar diálogo de crear archivo",
179+
"EnterName": "Por favor introduce un nombre",
180+
"InvalidType": "Tipo de archivo inválido. Las extensiones válidas son .js, .css, .json, .txt, .csv, .tsv, .frag y .vert."
181+
},
182+
"NewFileForm": {
183+
"AddFileSubmit": "Agregar Archivo",
184+
"Placeholder": "Nombre"
185+
},
186+
"NewFolderModal": {
187+
"Title": "Crear Directorio",
188+
"CloseButtonARIA": "Cerrar Diálogo de Nuevo Directorio",
189+
"EnterName": "Por favor introduce un nombre",
190+
"EmptyName": " El nombre del directorio no debe contener solo espacios vacíos",
191+
"InvalidExtension": "El nombre del directorio no debe contener una extensión"
192+
},
193+
"NewFolderForm": {
194+
"AddFolderSubmit": "Agregar Directorio",
195+
"Placeholder": "Nombre"
175196
}
176197
}
177198

0 commit comments

Comments
 (0)