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) { if (state.user.authenticated) {
const formParams = { const formParams = {
preferences: { preferences: {
textSize: value fontSize: value
} }
}; };
updatePreferences(formParams, dispatch); updatePreferences(formParams, dispatch);

View file

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

View file

@ -51,6 +51,8 @@ export function getUser() {
preferences: response.data.preferences 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) { if (req.user) {
Project.find({user: req.user._id}) // eslint-disable-line no-underscore-dangle Project.find({user: req.user._id}) // eslint-disable-line no-underscore-dangle
.sort('-createdAt') .sort('-createdAt')
.select('name files _id createdAt updatedAt') .select('name files id createdAt updatedAt')
.exec((err, projects) => { .exec((err, projects) => {
res.json(projects); res.json(projects);
}); });

View file

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

View file

@ -22,7 +22,9 @@ export function createUser(req, res, next) {
} }
res.json({ res.json({
email: req.user.email, 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 }, email: { type: String, unique: true },
tokens: Array, tokens: Array,
preferences: { preferences: {
textSize: { type: Number, default: 18 }, fontSize: { type: Number, default: 18 },
indentationAmount: { type: Number, default: 2 }, indentationAmount: { type: Number, default: 2 },
isTabIndent: { type: Boolean, default: false }, isTabIndent: { type: Boolean, default: false },
autosave: { type: Boolean, default: true } 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. * Helper method for validating user's password.
*/ */