aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/src/files_headers/noteToRecipient.ts
blob: 7cf859172c59f3f5014df640d089bea0d99c05e5 (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
/**
 * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
import type { ComponentPublicInstance, VueConstructor } from 'vue'

import { Folder, Header, registerFileListHeaders } from '@nextcloud/files'
import Vue from 'vue'

type IFilesHeaderNoteToRecipient = ComponentPublicInstance & { updateFolder: (folder: Folder) => void }

/**
 * Register the  "note to recipient" as a files list header
 */
export default function registerNoteToRecipient() {
	let FilesHeaderNoteToRecipient: VueConstructor
	let instance: IFilesHeaderNoteToRecipient

	registerFileListHeaders(new Header({
		id: 'note-to-recipient',
		order: 0,
		// Always if there is a note
		enabled: (folder: Folder) => Boolean(folder.attributes.note),
		// Update the root folder if needed
		updated: (folder: Folder) => {
			if (instance) {
				instance.updateFolder(folder)
			}
		},
		// render simply spawns the component
		render: async (el: HTMLElement, folder: Folder) => {
			if (FilesHeaderNoteToRecipient === undefined) {
				const { default: component } = await import('../views/FilesHeaderNoteToRecipient.vue')
				FilesHeaderNoteToRecipient = Vue.extend(component)
			}
			instance = new FilesHeaderNoteToRecipient().$mount(el) as unknown as IFilesHeaderNoteToRecipient
			instance.updateFolder(folder)
		},
	}))
}