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) {
|
if (state.user.authenticated) {
|
||||||
const formParams = {
|
const formParams = {
|
||||||
preferences: {
|
preferences: {
|
||||||
textSize: value
|
fontSize: value
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
updatePreferences(formParams, dispatch);
|
updatePreferences(formParams, dispatch);
|
||||||
|
|
|
@ -21,22 +21,31 @@ 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 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 &&
|
if (!this.autosaveInterval &&
|
||||||
((this.props.preferences.autosave && !prevProps.preferences.autosave) ||
|
((this.props.preferences.autosave && !prevProps.preferences.autosave) ||
|
||||||
(this.props.project.id && !prevProps.project.id))) {
|
(this.props.project.id && !prevProps.project.id))) {
|
||||||
this.autosaveInterval = setInterval(this.props.saveProject, 30000);
|
this.autosaveInterval = setInterval(this.props.saveProject, 30000);
|
||||||
|
// if user turns off autosave preference
|
||||||
} else if (this.autosaveInterval && !this.props.preferences.autosave && prevProps.preferences.autosave) {
|
} else if (this.autosaveInterval && !this.props.preferences.autosave && prevProps.preferences.autosave) {
|
||||||
clearInterval(this.autosaveInterval);
|
clearInterval(this.autosaveInterval);
|
||||||
this.autosaveInterval = null;
|
this.autosaveInterval = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
clearInterval(this.autosaveInterval);
|
clearInterval(this.autosaveInterval);
|
||||||
|
@ -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,
|
||||||
|
|
|
@ -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));
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
});
|
});
|
||||||
|
|
|
@ -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' });
|
||||||
|
|
|
@ -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
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -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.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue