diff --git a/apps/comments/src/comments-activity-tab.ts b/apps/comments/src/comments-activity-tab.ts index 765777884f2864cf45b09881c86796cee1b1aa45..f67f702d97bc9e18578f7decd182571b2723bcf5 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 8c6287d9ecba9de77ca38a994ddb88725eb96dc8..29711ad687db0c87bcc2462e6da54623817ecff8 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 bbf7189a6107e9fa7541a060e9f9c19671f799d1..722ad3444ce57311acaf04e3d73ab3981949556c 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 ae6b45a95f26fdace99675ba70a364cf320399cc..fccf55814ce574747cd333da4b5f0b56e227241f 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 0000000000000000000000000000000000000000..3e511addebb448f6715fddafb0454472f6a584b8 --- /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) + }, + }, +}) diff --git a/dist/3920-3920.js.license b/dist/3920-3920.js.license index 85ca87b5fdfe9b73f76d822d41e0a0409c25a0eb..ae814c133f50edd399305e937b8383c587128f28 100644 Binary files a/dist/3920-3920.js.license and b/dist/3920-3920.js.license differ diff --git a/dist/7462-7462.js b/dist/7462-7462.js index bdb9ec8bac8cc37cab5a45388a2e0d8397090fad..6d3062131a3621c99e7e383d60f7b9fd0496096e 100644 Binary files a/dist/7462-7462.js and b/dist/7462-7462.js differ diff --git a/dist/7462-7462.js.license b/dist/7462-7462.js.license index 85ca87b5fdfe9b73f76d822d41e0a0409c25a0eb..ae814c133f50edd399305e937b8383c587128f28 100644 Binary files a/dist/7462-7462.js.license and b/dist/7462-7462.js.license differ diff --git a/dist/7462-7462.js.map b/dist/7462-7462.js.map index 1f7e826f01c12f1a88869fd87c132fe8e30fd55f..f305bdcd01239613bb2343cf43339057c9c818c0 100644 Binary files a/dist/7462-7462.js.map and b/dist/7462-7462.js.map differ diff --git a/dist/8057-8057.js.license b/dist/8057-8057.js.license index 85ca87b5fdfe9b73f76d822d41e0a0409c25a0eb..ae814c133f50edd399305e937b8383c587128f28 100644 Binary files a/dist/8057-8057.js.license and b/dist/8057-8057.js.license differ diff --git a/dist/comments-comments-app.js b/dist/comments-comments-app.js index 41345e27b52ed354a904cbde1780cd99fc72cb7e..38cc96bd6a642ff56b85c0ebd9a2c4b0ee95998d 100644 Binary files a/dist/comments-comments-app.js and b/dist/comments-comments-app.js differ diff --git a/dist/comments-comments-app.js.license b/dist/comments-comments-app.js.license index 735dc5147c16b56f6066c1afc7f34afb0627f969..394d541f601f9196511c4f2162eeebd3e78ccdd4 100644 Binary files a/dist/comments-comments-app.js.license and b/dist/comments-comments-app.js.license differ diff --git a/dist/comments-comments-app.js.map b/dist/comments-comments-app.js.map index 013ec2bd00ffd3ee9780ba7d313371d5f9b9bee4..276bf7e7b3bbb66ba2c8f1b419e02874ca602be2 100644 Binary files a/dist/comments-comments-app.js.map and b/dist/comments-comments-app.js.map differ diff --git a/dist/comments-comments-tab.js b/dist/comments-comments-tab.js index a57ab8cabee85e5e86ae3a17fd021cf3f5a95d88..119a6fbd0bee4f7779317bd665ad7ca8ad5bf7bc 100644 Binary files a/dist/comments-comments-tab.js and b/dist/comments-comments-tab.js differ diff --git a/dist/comments-comments-tab.js.license b/dist/comments-comments-tab.js.license index e01922b21a82f594981dc65d1bc0209705dd4245..419d76c8c812cfaa82dcfb91ad74bd47652c1d46 100644 Binary files a/dist/comments-comments-tab.js.license and b/dist/comments-comments-tab.js.license differ diff --git a/dist/comments-comments-tab.js.map b/dist/comments-comments-tab.js.map index 4fdf5065942285c7cf1c22f4fe412ccae6ed73b5..4049ff10f6796000abe6a0729cee2b7e12c327d3 100644 Binary files a/dist/comments-comments-tab.js.map and b/dist/comments-comments-tab.js.map differ diff --git a/dist/core-common.js b/dist/core-common.js index ae0b9508bbf9391c9f59dacded2dea35d3d20fa9..2fe22b80de05fc7fd6d287e2f90b8aebfd494aa5 100644 Binary files a/dist/core-common.js and b/dist/core-common.js differ diff --git a/dist/core-common.js.map b/dist/core-common.js.map index 1e3af1bc1153959f7737f0fab46f0d6b9b1602f3..a1fba9382866159523c98e5ceffc3bc67b1a4f69 100644 Binary files a/dist/core-common.js.map and b/dist/core-common.js.map differ diff --git a/dist/files_sharing-additionalScripts.js b/dist/files_sharing-additionalScripts.js index bd8c015749e66f66b3e7f6a52e613c2862e762bb..cf3b30269e91b9e8089cd3c3dcca4dc317d9f759 100644 Binary files a/dist/files_sharing-additionalScripts.js and b/dist/files_sharing-additionalScripts.js differ diff --git a/dist/files_sharing-additionalScripts.js.map b/dist/files_sharing-additionalScripts.js.map index 1f344595599882c8161e4743d5a194c8480e45f0..9016d5aa02703072185beed257b1b451df92ff27 100644 Binary files a/dist/files_sharing-additionalScripts.js.map and b/dist/files_sharing-additionalScripts.js.map differ