Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/comment deleting with activities installed #45848

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions apps/comments/src/comments-activity-tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
GretaD marked this conversation as resolved.
Show resolved Hide resolved

let ActivityTabPluginView
let ActivityTabPluginInstance

Expand All @@ -16,16 +20,19 @@ 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,
propsData: {
reloadCallback: reload,
resourceId: fileInfo.id,
},
pinia,
})
ActivityTabPluginInstance.$mount(el)
logger.info('Comments plugin mounted in Activity sidebar action', { fileInfo })
Expand All @@ -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(),
Expand Down
9 changes: 8 additions & 1 deletion apps/comments/src/components/Comment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
-->
<template>
<component :is="tag"
v-show="!deleted"
v-show="!deleted && !isLimbo"
:class="{'comment--loading': loading}"
class="comment">
<!-- Comment header toolbar -->
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -193,6 +195,7 @@ export default {
},

computed: {
...mapStores(useDeletedCommentLimbo),

/**
* Is the current user the author of this comment
Expand Down Expand Up @@ -225,6 +228,10 @@ export default {
timestamp() {
return Date.parse(this.creationDateTime)
},

isLimbo() {
return this.deletedCommentLimboStore.checkForId(this.id)
},
},

watch: {
Expand Down
10 changes: 10 additions & 0 deletions apps/comments/src/mixins/CommentMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -37,6 +39,10 @@ export default {
}
},

computed: {
...mapStores(useDeletedCommentLimbo),
},

methods: {
// EDITION
onEdit() {
Expand Down Expand Up @@ -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() {
Expand All @@ -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)
}
},

Expand Down
5 changes: 5 additions & 0 deletions apps/comments/src/services/CommentsInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand All @@ -34,13 +36,16 @@ 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,
propsData: {
...(options.propsData ?? {}),
resourceType,
},
pinia,
}
// Init Comments component
const View = Vue.extend(CommentsApp)
Expand Down
28 changes: 28 additions & 0 deletions apps/comments/src/store/deletedCommentLimbo.js
Original file line number Diff line number Diff line change
@@ -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)
},
},
})
8 changes: 8 additions & 0 deletions dist/3920-3920.js.license
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ SPDX-FileCopyrightText: Jacob Clevenger<https://github.com/wheatjs>
SPDX-FileCopyrightText: Irakli Gozalishvili <rfobic@gmail.com> (http://jeditoolkit.com)
SPDX-FileCopyrightText: Hypercontext
SPDX-FileCopyrightText: Guillaume Chau <guillaume.b.chau@gmail.com>
SPDX-FileCopyrightText: Guillaume Chau
SPDX-FileCopyrightText: GitHub Inc.
SPDX-FileCopyrightText: Feross Aboukhadijeh
SPDX-FileCopyrightText: Evan You
SPDX-FileCopyrightText: Eugene Sharygin <eush77@gmail.com>
SPDX-FileCopyrightText: Eric Norris (https://github.com/ericnorris)
SPDX-FileCopyrightText: Eduardo San Martin Morote
SPDX-FileCopyrightText: Dylan Piercey <pierceydylan@gmail.com>
SPDX-FileCopyrightText: Dr.-Ing. Mario Heiderich, Cure53 <mario@cure53.de> (https://cure53.de/)
SPDX-FileCopyrightText: David Clark
Expand Down Expand Up @@ -96,6 +98,9 @@ This file is generated from multiple sources. Included packages:
- @nextcloud/vue
- version: 8.14.0
- license: AGPL-3.0-or-later
- @vue/devtools-api
- version: 6.6.1
- license: MIT
- @vueuse/components
- version: 10.11.0
- license: MIT
Expand Down Expand Up @@ -279,6 +284,9 @@ This file is generated from multiple sources. Included packages:
- path
- version: 0.12.7
- license: MIT
- pinia
- version: 2.1.7
- license: MIT
- possible-typed-array-names
- version: 1.0.0
- license: MIT
Expand Down
4 changes: 2 additions & 2 deletions dist/7462-7462.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions dist/7462-7462.js.license
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ SPDX-FileCopyrightText: Jacob Clevenger<https://github.com/wheatjs>
SPDX-FileCopyrightText: Irakli Gozalishvili <rfobic@gmail.com> (http://jeditoolkit.com)
SPDX-FileCopyrightText: Hypercontext
SPDX-FileCopyrightText: Guillaume Chau <guillaume.b.chau@gmail.com>
SPDX-FileCopyrightText: Guillaume Chau
SPDX-FileCopyrightText: GitHub Inc.
SPDX-FileCopyrightText: Feross Aboukhadijeh
SPDX-FileCopyrightText: Evan You
SPDX-FileCopyrightText: Eugene Sharygin <eush77@gmail.com>
SPDX-FileCopyrightText: Eric Norris (https://github.com/ericnorris)
SPDX-FileCopyrightText: Eduardo San Martin Morote
SPDX-FileCopyrightText: Dylan Piercey <pierceydylan@gmail.com>
SPDX-FileCopyrightText: Dr.-Ing. Mario Heiderich, Cure53 <mario@cure53.de> (https://cure53.de/)
SPDX-FileCopyrightText: David Clark
Expand Down Expand Up @@ -96,6 +98,9 @@ This file is generated from multiple sources. Included packages:
- @nextcloud/vue
- version: 8.14.0
- license: AGPL-3.0-or-later
- @vue/devtools-api
- version: 6.6.1
- license: MIT
- @vueuse/components
- version: 10.11.0
- license: MIT
Expand Down Expand Up @@ -279,6 +284,9 @@ This file is generated from multiple sources. Included packages:
- path
- version: 0.12.7
- license: MIT
- pinia
- version: 2.1.7
- license: MIT
- possible-typed-array-names
- version: 1.0.0
- license: MIT
Expand Down
2 changes: 1 addition & 1 deletion dist/7462-7462.js.map

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions dist/8057-8057.js.license
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ SPDX-FileCopyrightText: Jacob Clevenger<https://github.com/wheatjs>
SPDX-FileCopyrightText: Irakli Gozalishvili <rfobic@gmail.com> (http://jeditoolkit.com)
SPDX-FileCopyrightText: Hypercontext
SPDX-FileCopyrightText: Guillaume Chau <guillaume.b.chau@gmail.com>
SPDX-FileCopyrightText: Guillaume Chau
SPDX-FileCopyrightText: GitHub Inc.
SPDX-FileCopyrightText: Feross Aboukhadijeh
SPDX-FileCopyrightText: Evan You
SPDX-FileCopyrightText: Eugene Sharygin <eush77@gmail.com>
SPDX-FileCopyrightText: Eric Norris (https://github.com/ericnorris)
SPDX-FileCopyrightText: Eduardo San Martin Morote
SPDX-FileCopyrightText: Dylan Piercey <pierceydylan@gmail.com>
SPDX-FileCopyrightText: Dr.-Ing. Mario Heiderich, Cure53 <mario@cure53.de> (https://cure53.de/)
SPDX-FileCopyrightText: David Clark
Expand Down Expand Up @@ -96,6 +98,9 @@ This file is generated from multiple sources. Included packages:
- @nextcloud/vue
- version: 8.14.0
- license: AGPL-3.0-or-later
- @vue/devtools-api
- version: 6.6.1
- license: MIT
- @vueuse/components
- version: 10.11.0
- license: MIT
Expand Down Expand Up @@ -279,6 +284,9 @@ This file is generated from multiple sources. Included packages:
- path
- version: 0.12.7
- license: MIT
- pinia
- version: 2.1.7
- license: MIT
- possible-typed-array-names
- version: 1.0.0
- license: MIT
Expand Down
4 changes: 2 additions & 2 deletions dist/comments-comments-app.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions dist/comments-comments-app.js.license
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ SPDX-FileCopyrightText: Jacob Clevenger<https://github.com/wheatjs>
SPDX-FileCopyrightText: Irakli Gozalishvili <rfobic@gmail.com> (http://jeditoolkit.com)
SPDX-FileCopyrightText: Hypercontext
SPDX-FileCopyrightText: Guillaume Chau <guillaume.b.chau@gmail.com>
SPDX-FileCopyrightText: Guillaume Chau
SPDX-FileCopyrightText: GitHub Inc.
SPDX-FileCopyrightText: Feross Aboukhadijeh
SPDX-FileCopyrightText: Evan You
SPDX-FileCopyrightText: Eugene Sharygin <eush77@gmail.com>
SPDX-FileCopyrightText: Eric Norris (https://github.com/ericnorris)
SPDX-FileCopyrightText: Eduardo San Martin Morote
SPDX-FileCopyrightText: Dylan Piercey <pierceydylan@gmail.com>
SPDX-FileCopyrightText: Dr.-Ing. Mario Heiderich, Cure53 <mario@cure53.de> (https://cure53.de/)
SPDX-FileCopyrightText: David Clark
Expand Down Expand Up @@ -96,6 +98,9 @@ This file is generated from multiple sources. Included packages:
- @nextcloud/vue
- version: 8.14.0
- license: AGPL-3.0-or-later
- @vue/devtools-api
- version: 6.6.1
- license: MIT
- @vueuse/components
- version: 10.11.0
- license: MIT
Expand Down Expand Up @@ -279,6 +284,9 @@ This file is generated from multiple sources. Included packages:
- path
- version: 0.12.7
- license: MIT
- pinia
- version: 2.1.7
- license: MIT
- possible-typed-array-names
- version: 1.0.0
- license: MIT
Expand Down
2 changes: 1 addition & 1 deletion dist/comments-comments-app.js.map

Large diffs are not rendered by default.

Loading
Loading