aboutsummaryrefslogtreecommitdiffstats
path: root/core/src/components/PublicPageMenu/PublicPageMenuLinkEntry.vue
blob: 54645e9ce48ac0b12efdbf5aef7985c1ac182bf6 (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
<!--
 - SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
 - SPDX-License-Identifier: AGPL-3.0-or-later
 -->
<template>
	<PublicPageMenuEntry :id="id"
		click-only
		:icon="icon"
		:href="href"
		:label="label"
		@click="onClick" />
</template>

<script setup lang="ts">
import { showSuccess } from '@nextcloud/dialogs'
import { t } from '@nextcloud/l10n'
import PublicPageMenuEntry from './PublicPageMenuEntry.vue'

const props = defineProps<{
	id: string
	label: string
	icon: string
	href: string
}>()

const emit = defineEmits<{
	(e: 'click'): void
}>()

/**
 * Copy the href to the clipboard
 */
async function copyLink() {
	try {
		await window.navigator.clipboard.writeText(props.href)
		showSuccess(t('core', 'Direct link copied to clipboard'))
	} catch {
		// No secure context -> fallback to dialog
		window.prompt(t('core', 'Please copy the link manually:'), props.href)
	}
}

/**
 * onclick handler to trigger the "copy link" action
 * and emit the event so the menu can be closed
 */
function onClick() {
	copyLink()
	emit('click')
}
</script>