Fixed layout settings badge creation.

Hide sponsorship if no paypal email is configured.
This commit is contained in:
Benoit Schweblin 2019-06-30 13:28:37 +01:00
parent e9e3cb809d
commit 8a6df3ef10
5 changed files with 51 additions and 38 deletions

View File

@ -34,4 +34,5 @@ exports.publicValues = {
googleClientId,
googleApiKey,
wordpressClientId,
allowSponsorship: !!paypalReceiverEmail,
};

View File

@ -105,6 +105,9 @@ exports.paypalIpn = (req, res, next) => Promise.resolve()
.catch(next);
exports.checkSponsor = (idToken) => {
if (!conf.publicValues.allowSponsorship) {
return Promise.resolve(true);
}
if (!idToken) {
return Promise.resolve(false);
}

View File

@ -58,18 +58,14 @@ export default {
store.dispatch('modal/open', {
type: 'couchdbWorkspace',
});
} catch (e) {
// Cancel
}
} catch (e) { /* Cancel */ }
},
async addGithubWorkspace() {
try {
store.dispatch('modal/open', {
type: 'githubWorkspace',
});
} catch (e) {
// Cancel
}
} catch (e) { /* Cancel */ }
},
async addGitlabWorkspace() {
try {
@ -79,9 +75,7 @@ export default {
type: 'gitlabWorkspace',
token,
});
} catch (e) {
// Cancel
}
} catch (e) { /* Cancel */ }
},
async addGoogleDriveWorkspace() {
try {
@ -90,12 +84,12 @@ export default {
type: 'googleDriveWorkspace',
token,
});
} catch (e) {
// Cancel
}
} catch (e) { /* Cancel */ }
},
manageWorkspaces() {
store.dispatch('modal/open', 'workspaceManagement');
try {
store.dispatch('modal/open', 'workspaceManagement');
} catch (e) { /* Cancel */ }
},
},
};

View File

@ -64,21 +64,26 @@ const patcher = id => ({ state, commit }, data) => {
};
// For layoutSettings
const layoutSettingsToggler = (propertyName, featureId) => ({ getters, dispatch }, value) => {
dispatch('patchLayoutSettings', {
[propertyName]: value === undefined ? !getters.layoutSettings[propertyName] : value,
});
badgeSvc.addBadge(featureId);
const toggleLayoutSetting = (name, value, featureId, getters, dispatch) => {
const currentValue = getters.layoutSettings[name];
const patch = {
[name]: value === undefined ? !currentValue : !!value,
};
if (patch[name] !== currentValue) {
dispatch('patchLayoutSettings', patch);
badgeSvc.addBadge(featureId);
}
};
const notEnoughSpace = (getters) => {
const layoutConstants = getters['layout/constants'];
const showGutter = getters['discussion/currentDiscussion'];
return document.body.clientWidth < layoutConstants.editorMinWidth +
const layoutSettingsToggler = (propertyName, featureId) => ({ getters, dispatch }, value) =>
toggleLayoutSetting(propertyName, value, featureId, getters, dispatch);
const notEnoughSpace = (layoutConstants, showGutter) =>
document.body.clientWidth < layoutConstants.editorMinWidth +
layoutConstants.explorerWidth +
layoutConstants.sideBarWidth +
layoutConstants.buttonBarWidth +
(showGutter ? layoutConstants.gutterWidth : 0);
};
// For templates
const makeAdditionalTemplate = (name, value, helpers = '\n') => ({
@ -239,26 +244,30 @@ export default {
// Reset side bar
dispatch('setSideBarPanel');
// Toggle it
toggleLayoutSetting('showSideBar', value, 'toggleSideBar', getters, dispatch);
// Close explorer if not enough space
const patch = {
showSideBar: value === undefined ? !getters.layoutSettings.showSideBar : value,
};
if (patch.showSideBar && notEnoughSpace(rootGetters)) {
patch.showExplorer = false;
if (getters.layoutSettings.showSideBar &&
notEnoughSpace(rootGetters['layout/constants'], rootGetters['discussion/currentDiscussion'])
) {
dispatch('patchLayoutSettings', {
showExplorer: false,
});
}
dispatch('patchLayoutSettings', patch);
badgeSvc.addBadge('toggleSideBar');
},
toggleExplorer: ({ getters, dispatch, rootGetters }, value) => {
// Toggle explorer
toggleLayoutSetting('showExplorer', value, 'toggleExplorer', getters, dispatch);
// Close side bar if not enough space
const patch = {
showExplorer: value === undefined ? !getters.layoutSettings.showExplorer : value,
};
if (patch.showExplorer && notEnoughSpace(rootGetters)) {
patch.showSideBar = false;
if (getters.layoutSettings.showExplorer &&
notEnoughSpace(rootGetters['layout/constants'], rootGetters['discussion/currentDiscussion'])
) {
dispatch('patchLayoutSettings', {
showSideBar: false,
});
}
dispatch('patchLayoutSettings', patch);
badgeSvc.addBadge('toggleExplorer');
},
setSideBarPanel: ({ dispatch }, value) => dispatch('patchLayoutSettings', {
sideBarPanel: value === undefined ? 'menu' : value,

View File

@ -155,8 +155,14 @@ const store = new Vuex.Store({
return result;
},
isSponsor: ({ light }, getters) => {
if (light) {
return true;
}
if (!getters['data/serverConf'].allowSponsorship) {
return true;
}
const sponsorToken = getters['workspace/sponsorToken'];
return light || (sponsorToken && sponsorToken.isSponsor);
return sponsorToken ? sponsorToken.isSponsor : false;
},
},
actions: {