fix preferences font size text size bug

This commit is contained in:
catarak 2016-08-09 18:45:59 -04:00
parent d9ea10c4c6
commit afc86740b3
7 changed files with 44 additions and 17 deletions

View file

@ -23,7 +23,7 @@ export function setFontSize(value) {
if (state.user.authenticated) {
const formParams = {
preferences: {
textSize: value
fontSize: value
}
};
updatePreferences(formParams, dispatch);

View file

@ -21,20 +21,29 @@ class IDEView extends React.Component {
const id = this.props.params.project_id;
this.props.getProject(id);
if (this.props.preferences.autosave) {
// if autosave is on and the user is the owner of the project
if (this.props.preferences.autosave
&& this.props.project.owner
&& this.props.project.owner.id === this.props.user.id) {
this.autosaveInterval = setInterval(this.props.saveProject, 30000);
}
}
}
componentDidUpdate(prevProps) {
if (!this.autosaveInterval &&
((this.props.preferences.autosave && !prevProps.preferences.autosave) ||
(this.props.project.id && !prevProps.project.id))) {
this.autosaveInterval = setInterval(this.props.saveProject, 30000);
} else if (this.autosaveInterval && !this.props.preferences.autosave && prevProps.preferences.autosave) {
clearInterval(this.autosaveInterval);
this.autosaveInterval = null;
// if user is the owner of the project
if (this.props.project.owner && this.props.project.owner.id === this.props.user.id) {
// if the user turns on autosave
// or the user saves the project for the first time
if (!this.autosaveInterval &&
((this.props.preferences.autosave && !prevProps.preferences.autosave) ||
(this.props.project.id && !prevProps.project.id))) {
this.autosaveInterval = setInterval(this.props.saveProject, 30000);
// if user turns off autosave preference
} else if (this.autosaveInterval && !this.props.preferences.autosave && prevProps.preferences.autosave) {
clearInterval(this.autosaveInterval);
this.autosaveInterval = null;
}
}
}
@ -145,7 +154,8 @@ IDEView.propTypes = {
}),
getProject: PropTypes.func.isRequired,
user: PropTypes.shape({
authenticated: PropTypes.bool.isRequired
authenticated: PropTypes.bool.isRequired,
id: PropTypes.string
}).isRequired,
createProject: PropTypes.func.isRequired,
saveProject: PropTypes.func.isRequired,
@ -163,7 +173,8 @@ IDEView.propTypes = {
id: PropTypes.string,
name: PropTypes.string.isRequired,
owner: PropTypes.shape({
username: PropTypes.string
username: PropTypes.string,
id: PropTypes.string
})
}).isRequired,
setProjectName: PropTypes.func.isRequired,

View file

@ -51,6 +51,8 @@ export function getUser() {
preferences: response.data.preferences
});
})
.catch(response => dispatch(authError(response.data.error)));
.catch(response => {
dispatch(authError(response.data.error));
});
};
}

View file

@ -46,7 +46,7 @@ export function getProjects(req, res) {
if (req.user) {
Project.find({user: req.user._id}) // eslint-disable-line no-underscore-dangle
.sort('-createdAt')
.select('name files _id createdAt updatedAt')
.select('name files id createdAt updatedAt')
.exec((err, projects) => {
res.json(projects);
});

View file

@ -11,7 +11,9 @@ export function createSession(req, res, next) {
if (innerErr) { return next(innerErr); }
return res.json({
email: req.user.email,
username: req.user.username
username: req.user.username,
preferences: req.user.preferences,
id: req.user._id
});
});
})(req, res, next);
@ -22,7 +24,8 @@ export function getSession(req, res) {
return res.json({
email: req.user.email,
username: req.user.username,
preferences: req.user.preferences
preferences: req.user.preferences,
id: req.user._id
});
}
return res.status(404).send({ message: 'Session does not exist' });

View file

@ -22,7 +22,9 @@ export function createUser(req, res, next) {
}
res.json({
email: req.user.email,
username: req.user.username
username: req.user.username,
preferences: req.user.preferences,
id: req.user._id
});
});
});

View file

@ -10,7 +10,7 @@ const userSchema = new Schema({
email: { type: String, unique: true },
tokens: Array,
preferences: {
textSize: { type: Number, default: 18 },
fontSize: { type: Number, default: 18 },
indentationAmount: { type: Number, default: 2 },
isTabIndent: { type: Boolean, default: false },
autosave: { type: Boolean, default: true }
@ -33,6 +33,15 @@ userSchema.pre('save', function checkPassword(next) { // eslint-disable-line con
});
});
userSchema.virtual('id').get(function(){
return this._id.toHexString();
});
userSchema.set('toJSON', {
virtuals: true
});
/**
* Helper method for validating user's password.
*/