aboutsummaryrefslogtreecommitdiffstats
path: root/apps/comments/src/services/CommentsInstance.js
blob: cc45d0cbea7b54ad0b848519d87ec74f1b945909 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
 * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

import { getCSPNonce } from '@nextcloud/auth'
import { t, n } from '@nextcloud/l10n'
import { PiniaVuePlugin, createPinia } from 'pinia'
import Vue from 'vue'
import CommentsApp from '../views/Comments.vue'
import logger from '../logger.js'

Vue.use(PiniaVuePlugin)
// eslint-disable-next-line camelcase
__webpack_nonce__ = getCSPNonce()

// Add translates functions
Vue.mixin({
	data() {
		return {
			logger,
		}
	},
	methods: {
		t,
		n,
	},
})

export default class CommentInstance {

	/**
	 * Initialize a new Comments instance for the desired type
	 *
	 * @param {string} resourceType the comments endpoint type
	 * @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)
		return new View(options)
	}

}