fix preferences font size text size bug
This commit is contained in:
parent
d9ea10c4c6
commit
afc86740b3
7 changed files with 44 additions and 17 deletions
|
@ -23,7 +23,7 @@ export function setFontSize(value) {
|
|||
if (state.user.authenticated) {
|
||||
const formParams = {
|
||||
preferences: {
|
||||
textSize: value
|
||||
fontSize: value
|
||||
}
|
||||
};
|
||||
updatePreferences(formParams, dispatch);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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));
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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' });
|
||||
|
|
|
@ -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
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue