diff options
author | Grigory Vodyanov <scratchx@gmx.com> | 2024-06-13 11:39:18 +0200 |
---|---|---|
committer | nextcloud-command <nextcloud-command@users.noreply.github.com> | 2024-07-15 13:38:41 +0000 |
commit | bd7c29c362c3bbd9f1ff495674a1980b54d14104 (patch) | |
tree | d466fa2272a837168b38e525871c738d1c9aee2d /apps | |
parent | d42849852e2d4b8b84f37e5e5efc5a3ca7625138 (diff) | |
download | nextcloud-server-bd7c29c362c3bbd9f1ff495674a1980b54d14104.tar.gz nextcloud-server-bd7c29c362c3bbd9f1ff495674a1980b54d14104.zip |
fix(comments): comment deleting with activities installed
Signed-off-by: Grigory Vodyanov <scratchx@gmx.com>
Signed-off-by: Grigory V <scratchx@gmx.com>
Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/comments/src/comments-activity-tab.ts | 11 | ||||
-rw-r--r-- | apps/comments/src/components/Comment.vue | 9 | ||||
-rw-r--r-- | apps/comments/src/mixins/CommentMixin.js | 10 | ||||
-rw-r--r-- | apps/comments/src/services/CommentsInstance.js | 5 | ||||
-rw-r--r-- | apps/comments/src/store/deletedCommentLimbo.js | 28 |
5 files changed, 60 insertions, 3 deletions
diff --git a/apps/comments/src/comments-activity-tab.ts b/apps/comments/src/comments-activity-tab.ts index 765777884f2..f67f702d97b 100644 --- a/apps/comments/src/comments-activity-tab.ts +++ b/apps/comments/src/comments-activity-tab.ts @@ -7,6 +7,10 @@ import Vue from 'vue' import logger from './logger.js' import { getComments } from './services/GetComments.js' +import { PiniaVuePlugin, createPinia } from 'pinia' + +Vue.use(PiniaVuePlugin) + let ActivityTabPluginView let ActivityTabPluginInstance @@ -16,9 +20,11 @@ let ActivityTabPluginInstance export function registerCommentsPlugins() { window.OCA.Activity.registerSidebarAction({ mount: async (el, { context, fileInfo, reload }) => { + const pinia = createPinia() + if (!ActivityTabPluginView) { const { default: ActivityCommmentAction } = await import('./views/ActivityCommentAction.vue') - ActivityTabPluginView = Vue.extend(ActivityCommmentAction) + ActivityTabPluginView = ActivityCommmentAction } ActivityTabPluginInstance = new ActivityTabPluginView({ parent: context, @@ -26,6 +32,7 @@ export function registerCommentsPlugins() { reloadCallback: reload, resourceId: fileInfo.id, }, + pinia, }) ActivityTabPluginInstance.$mount(el) logger.info('Comments plugin mounted in Activity sidebar action', { fileInfo }) @@ -42,7 +49,7 @@ export function registerCommentsPlugins() { const { data: comments } = await getComments({ resourceType: 'files', resourceId: fileInfo.id }, { limit, offset }) logger.debug('Loaded comments', { fileInfo, comments }) const { default: CommentView } = await import('./views/ActivityCommentEntry.vue') - const CommentsViewObject = Vue.extend(CommentView) + const CommentsViewObject = CommentView return comments.map((comment) => ({ timestamp: moment(comment.props.creationDateTime).toDate().getTime(), diff --git a/apps/comments/src/components/Comment.vue b/apps/comments/src/components/Comment.vue index 8c6287d9ecb..29711ad687d 100644 --- a/apps/comments/src/components/Comment.vue +++ b/apps/comments/src/components/Comment.vue @@ -4,7 +4,7 @@ --> <template> <component :is="tag" - v-show="!deleted" + v-show="!deleted && !isLimbo" :class="{'comment--loading': loading}" class="comment"> <!-- Comment header toolbar --> @@ -121,6 +121,8 @@ import IconDelete from 'vue-material-design-icons/Delete.vue' import IconEdit from 'vue-material-design-icons/Pencil.vue' import CommentMixin from '../mixins/CommentMixin.js' +import { mapStores } from 'pinia' +import { useDeletedCommentLimbo } from '../store/deletedCommentLimbo.js' // Dynamic loading const NcRichContenteditable = () => import('@nextcloud/vue/dist/Components/NcRichContenteditable.js') @@ -193,6 +195,7 @@ export default { }, computed: { + ...mapStores(useDeletedCommentLimbo), /** * Is the current user the author of this comment @@ -225,6 +228,10 @@ export default { timestamp() { return Date.parse(this.creationDateTime) }, + + isLimbo() { + return this.deletedCommentLimboStore.checkForId(this.id) + }, }, watch: { diff --git a/apps/comments/src/mixins/CommentMixin.js b/apps/comments/src/mixins/CommentMixin.js index bbf7189a610..722ad3444ce 100644 --- a/apps/comments/src/mixins/CommentMixin.js +++ b/apps/comments/src/mixins/CommentMixin.js @@ -7,6 +7,8 @@ import { showError, showUndo, TOAST_UNDO_TIMEOUT } from '@nextcloud/dialogs' import NewComment from '../services/NewComment.js' import DeleteComment from '../services/DeleteComment.js' import EditComment from '../services/EditComment.js' +import { mapStores } from 'pinia' +import { useDeletedCommentLimbo } from '../store/deletedCommentLimbo.js' import logger from '../logger.js' export default { @@ -37,6 +39,10 @@ export default { } }, + computed: { + ...mapStores(useDeletedCommentLimbo), + }, + methods: { // EDITION onEdit() { @@ -64,11 +70,14 @@ export default { // DELETION onDeleteWithUndo() { + this.$emit('delete') this.deleted = true + this.deletedCommentLimboStore.addId(this.id) const timeOutDelete = setTimeout(this.onDelete, TOAST_UNDO_TIMEOUT) showUndo(t('comments', 'Comment deleted'), () => { clearTimeout(timeOutDelete) this.deleted = false + this.deletedCommentLimboStore.removeId(this.id) }) }, async onDelete() { @@ -80,6 +89,7 @@ export default { showError(t('comments', 'An error occurred while trying to delete the comment')) console.error(error) this.deleted = false + this.deletedCommentLimboStore.removeId(this.id) } }, diff --git a/apps/comments/src/services/CommentsInstance.js b/apps/comments/src/services/CommentsInstance.js index ae6b45a95f2..fccf55814ce 100644 --- a/apps/comments/src/services/CommentsInstance.js +++ b/apps/comments/src/services/CommentsInstance.js @@ -6,9 +6,11 @@ import { translate as t, translatePlural as n } from '@nextcloud/l10n' import { getRequestToken } from '@nextcloud/auth' import Vue from 'vue' +import { PiniaVuePlugin, createPinia } from 'pinia' import CommentsApp from '../views/Comments.vue' import logger from '../logger.js' +Vue.use(PiniaVuePlugin) // eslint-disable-next-line camelcase __webpack_nonce__ = btoa(getRequestToken()) @@ -34,6 +36,8 @@ export default class CommentInstance { * @param {object} options the vue options (propsData, parent, el...) */ constructor(resourceType = 'files', options = {}) { + const pinia = createPinia() + // Merge options and set `resourceType` property options = { ...options, @@ -41,6 +45,7 @@ export default class CommentInstance { ...(options.propsData ?? {}), resourceType, }, + pinia, } // Init Comments component const View = Vue.extend(CommentsApp) diff --git a/apps/comments/src/store/deletedCommentLimbo.js b/apps/comments/src/store/deletedCommentLimbo.js new file mode 100644 index 00000000000..3e511addebb --- /dev/null +++ b/apps/comments/src/store/deletedCommentLimbo.js @@ -0,0 +1,28 @@ +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import { defineStore } from 'pinia' + +export const useDeletedCommentLimbo = defineStore('deletedCommentLimbo', { + state: () => ({ + idsInLimbo: [], + }), + actions: { + addId(id) { + this.idsInLimbo.push(id) + }, + + removeId(id) { + const index = this.idsInLimbo.indexOf(id) + if (index > -1) { + this.idsInLimbo.splice(index, 1) + } + }, + + checkForId(id) { + this.idsInLimbo.includes(id) + }, + }, +}) |