From 217b17c279dde43641842d2bc3b8c917f622186a Mon Sep 17 00:00:00 2001 From: benweet Date: Fri, 17 Nov 2017 20:33:49 +0000 Subject: [PATCH] Force signin before commenting --- .../gutters/EditorNewDiscussionButton.vue | 1 + .../gutters/PreviewNewDiscussionButton.vue | 1 + src/components/modals/common/ModalInner.vue | 2 +- src/services/editorSvc.js | 2 +- src/store/discussion.js | 13 +++++++++++-- src/store/modal.js | 6 ++++++ 6 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/components/gutters/EditorNewDiscussionButton.vue b/src/components/gutters/EditorNewDiscussionButton.vue index 127d5e9b..afa827b4 100644 --- a/src/components/gutters/EditorNewDiscussionButton.vue +++ b/src/components/gutters/EditorNewDiscussionButton.vue @@ -10,6 +10,7 @@ import editorSvc from '../../services/editorSvc'; export default { data: () => ({ + selection: null, coordinates: null, }), methods: { diff --git a/src/components/gutters/PreviewNewDiscussionButton.vue b/src/components/gutters/PreviewNewDiscussionButton.vue index 9a3eb248..014004de 100644 --- a/src/components/gutters/PreviewNewDiscussionButton.vue +++ b/src/components/gutters/PreviewNewDiscussionButton.vue @@ -10,6 +10,7 @@ import editorSvc from '../../services/editorSvc'; export default { data: () => ({ + selection: null, coordinates: null, }), methods: { diff --git a/src/components/modals/common/ModalInner.vue b/src/components/modals/common/ModalInner.vue index c4b1a9dd..dc4549c9 100644 --- a/src/components/modals/common/ModalInner.vue +++ b/src/components/modals/common/ModalInner.vue @@ -70,7 +70,7 @@ export default { color: darken($error-color, 10%); background-color: transparentize($error-color, 0.85); border-radius: $border-radius-base; - padding: 1em 1.5em; + padding: 0.75em 1.5em; margin-bottom: 1.2em; } diff --git a/src/services/editorSvc.js b/src/services/editorSvc.js index 350bdea0..6d80ab2e 100644 --- a/src/services/editorSvc.js +++ b/src/services/editorSvc.js @@ -210,7 +210,7 @@ const editorSvc = Object.assign(new Vue(), editorSvcDiscussions, editorSvcUtils, this.$emit('previewText', this.previewText); // Debounce if sections have already been mesured this.measureSectionDimensions(!!this.sectionDescMeasuredList); - this.makeTextToPreviewDiffs(true); + this.makeTextToPreviewDiffs(); }); }, diff --git a/src/store/discussion.js b/src/store/discussion.js index ae77ab7b..565bcb9e 100644 --- a/src/store/discussion.js +++ b/src/store/discussion.js @@ -1,4 +1,6 @@ import utils from '../services/utils'; +import googleHelper from '../services/providers/helpers/googleHelper'; +import syncSvc from '../services/syncSvc'; const idShifter = offset => (state, getters) => { const ids = Object.keys(getters.currentFileDiscussions); @@ -115,8 +117,15 @@ export default { getters.currentDiscussionComments[getters.currentDiscussionLastCommentId], }, actions: { - createNewDiscussion({ commit, rootGetters }, selection) { - if (selection) { + createNewDiscussion({ commit, dispatch, rootGetters }, selection) { + const loginToken = rootGetters['data/loginToken']; + if (!loginToken) { + dispatch('modal/signInForComment', null, { root: true }) + .then(() => googleHelper.signin()) + .then(() => syncSvc.requestSync()) + .then(() => dispatch('createNewDiscussion', selection)) + .catch(() => { }); // Cancel + } else if (selection) { let text = rootGetters['content/current'].text.slice(selection.start, selection.end).trim(); const maxLength = 80; if (text.length > maxLength) { diff --git a/src/store/modal.js b/src/store/modal.js index 7db38c2c..24ac2c11 100644 --- a/src/store/modal.js +++ b/src/store/modal.js @@ -88,6 +88,12 @@ export default { resolveText: 'Ok, sign in', rejectText: 'Cancel', }), + signInForComment: ({ dispatch }) => dispatch('open', { + content: `

You have to sign in with Google to start commenting.

+ `, + resolveText: 'Ok, sign in', + rejectText: 'Cancel', + }), sponsorOnly: ({ dispatch }) => dispatch('open', { content: '

This feature is restricted to sponsor users as it relies on server resources.

', resolveText: 'Ok, I understand',