overleaf/services/web/frontend/js/ide/review-panel/directives/addCommentEntry.js
Alf Eaton 1be43911b4 Merge pull request #3942 from overleaf/prettier-trailing-comma
Set Prettier's "trailingComma" setting to "es5"

GitOrigin-RevId: 9f14150511929a855b27467ad17be6ab262fe5d5
2021-04-28 02:10:01 +00:00

50 lines
1.2 KiB
JavaScript

import App from '../../../base'
let content = ''
App.directive('addCommentEntry', () => ({
restrict: 'E',
templateUrl: 'addCommentEntryTemplate',
scope: {
onStartNew: '&',
onSubmit: '&',
onCancel: '&',
},
link(scope, element, attrs) {
scope.state = {
isAdding: false,
content: content,
}
scope.$on('comment:start_adding', () => scope.startNewComment())
scope.$on('$destroy', function () {
content = scope.state.content
})
scope.startNewComment = function () {
scope.state.isAdding = true
scope.onStartNew()
setTimeout(() => scope.$broadcast('comment:new:open'))
}
scope.cancelNewComment = function () {
scope.state.isAdding = false
scope.state.content = ''
scope.onCancel()
}
scope.handleCommentKeyPress = function (ev) {
if (ev.keyCode === 13 && !ev.shiftKey && !ev.ctrlKey && !ev.metaKey) {
ev.preventDefault()
if (scope.state.content.length > 0) {
scope.submitNewComment()
}
}
}
scope.submitNewComment = function (event) {
scope.onSubmit({ content: scope.state.content })
content = scope.state.content
scope.state.isAdding = false
scope.state.content = ''
}
},
}))