import '../user/Avatar' import '../utils/PrettyCreated' import './CommentEditor' import './Rating' import { Linkable } from '../mixins/Linkable' import { UnitOfWorkTracker } from '../mixins/UnitOfWorkTracker' import { EventBus, Events } from './EventBus' const TEMPLATE = `

{{ comment.user.full_name }}

Reply Edit Cancel
`; Vue.component('comment', { template: TEMPLATE, mixins: [Linkable, UnitOfWorkTracker], props: { user: Object, comment: Object, readOnly: { type: Boolean, default: false, }, isReply: { type: Boolean, default: false, }, }, data() { return { isReplying: false, isUpdating: false, id: this.comment.id, } }, computed: { canUpdate() { return !this.readOnly && this.comment.user.id === this.user.user_id && !this.isUpdating && !this.isReplying; }, canReply() { return !this.readOnly && !this.isUpdating && !this.isReplying; }, canCancel() { return this.isReplying || this.isUpdating; }, editorMode() { if(this.isReplying) { return 'reply'; } if(this.isUpdating) { return 'update'; } } }, created() { EventBus.$on(Events.BEFORE_SHOW_EDITOR, this.doHideEditors); EventBus.$on(Events.EDIT_DONE, this.doHideEditors); }, beforeDestroy() { EventBus.$off(Events.BEFORE_SHOW_EDITOR, this.doHideEditors); EventBus.$off(Events.EDIT_DONE, this.doHideEditors); }, methods: { showReplyEditor() { EventBus.$emit(Events.BEFORE_SHOW_EDITOR, this.comment.id ); this.isReplying = true; }, showUpdateEditor() { EventBus.$emit(Events.BEFORE_SHOW_EDITOR, this.comment.id ); this.isUpdating = true; }, cancleEdit() { this.doHideEditors(); EventBus.$emit(Events.EDIT_DONE); }, doHideEditors() { this.isReplying = false; this.isUpdating = false; }, } });