11/**
2- * @copyright Copyright (c) 2023 Ferdinand Thiessen <opensource@fthiessen.de>
3- *
4- * @author Ferdinand Thiessen <opensource@fthiessen.de>
5- *
6- * @license AGPL-3.0-or-later
7- *
8- * This program is free software: you can redistribute it and/or modify
9- * it under the terms of the GNU Affero General Public License as
10- * published by the Free Software Foundation, either version 3 of the
11- * License, or (at your option) any later version.
12- *
13- * This program is distributed in the hope that it will be useful,
14- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16- * GNU Affero General Public License for more details.
17- *
18- * You should have received a copy of the GNU Affero General Public License
19- * along with this program. If not, see <http://www.gnu.org/licenses/>.
20- *
2+ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
3+ * SPDX-License-Identifier: AGPL-3.0-or-later
214 */
225import moment from '@nextcloud/moment'
23- import Vue from 'vue'
6+ import Vue , { type ComponentPublicInstance } from 'vue'
247import logger from './logger.js'
258import { getComments } from './services/GetComments.js'
269
10+ import { PiniaVuePlugin , createPinia } from 'pinia'
11+
12+ Vue . use ( PiniaVuePlugin )
13+
2714let ActivityTabPluginView
2815let ActivityTabPluginInstance
2916
@@ -33,18 +20,22 @@ let ActivityTabPluginInstance
3320export function registerCommentsPlugins ( ) {
3421 window . OCA . Activity . registerSidebarAction ( {
3522 mount : async ( el , { context, fileInfo, reload } ) => {
23+ const pinia = createPinia ( )
24+
3625 if ( ! ActivityTabPluginView ) {
37- const { default : ActivityCommmentAction } = await import ( './views/ActivityCommentAction.vue' )
38- ActivityTabPluginView = Vue . extend ( ActivityCommmentAction )
26+ const { default : ActivityCommentAction } = await import ( './views/ActivityCommentAction.vue' )
27+ /** @ts -expect-error Types are broken for Vue2 */
28+ ActivityTabPluginView = Vue . extend ( ActivityCommentAction )
3929 }
4030 ActivityTabPluginInstance = new ActivityTabPluginView ( {
31+ el,
4132 parent : context ,
33+ pinia,
4234 propsData : {
4335 reloadCallback : reload ,
4436 resourceId : fileInfo . id ,
4537 } ,
4638 } )
47- ActivityTabPluginInstance . $mount ( el )
4839 logger . info ( 'Comments plugin mounted in Activity sidebar action' , { fileInfo } )
4940 } ,
5041 unmount : ( ) => {
@@ -59,23 +50,27 @@ export function registerCommentsPlugins() {
5950 const { data : comments } = await getComments ( { resourceType : 'files' , resourceId : fileInfo . id } , { limit, offset } )
6051 logger . debug ( 'Loaded comments' , { fileInfo, comments } )
6152 const { default : CommentView } = await import ( './views/ActivityCommentEntry.vue' )
53+ /** @ts -expect-error Types are broken for Vue2 */
6254 const CommentsViewObject = Vue . extend ( CommentView )
6355
6456 return comments . map ( ( comment ) => ( {
65- timestamp : moment ( comment . props . creationDateTime ) . toDate ( ) . getTime ( ) ,
66- mount ( element , { context, reload } ) {
57+ _CommentsViewInstance : undefined as ComponentPublicInstance | undefined ,
58+
59+ timestamp : moment ( comment . props ?. creationDateTime ) . toDate ( ) . getTime ( ) ,
60+
61+ mount ( element : HTMLElement , { context, reload } ) {
6762 this . _CommentsViewInstance = new CommentsViewObject ( {
63+ el : element ,
6864 parent : context ,
6965 propsData : {
7066 comment,
7167 resourceId : fileInfo . id ,
7268 reloadCallback : reload ,
7369 } ,
7470 } )
75- this . _CommentsViewInstance . $mount ( element )
7671 } ,
7772 unmount ( ) {
78- this . _CommentsViewInstance . $destroy ( )
73+ this . _CommentsViewInstance ? .$destroy ( )
7974 } ,
8075 } ) )
8176 } )
0 commit comments