Skip to content

Commit 1e2af46

Browse files
committed
feat: allow sharee to copy public link of a shared calendar
Signed-off-by: Ammar Hussein <ammaratef45@proton.me>
1 parent 051414c commit 1e2af46

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

src/components/AppNavigation/CalendarList/CalendarListItem.vue

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@
4646
</NcActionText>
4747
<NcActionSeparator />
4848
</template>
49+
<ActionButton v-if="isPublished" @click.prevent.stop="copyPublicLink">
50+
<template #icon>
51+
<ContentCopy :size="20" decorative />
52+
</template>
53+
{{ $t('calendar', 'Copy public link') }}
54+
</ActionButton>
4955
<ActionButton @click.prevent.stop="showEditModal">
5056
<template #icon>
5157
<Pencil :size="20" decorative />
@@ -81,7 +87,8 @@
8187
</template>
8288

8389
<script>
84-
import { showError } from '@nextcloud/dialogs'
90+
import { showError, showSuccess } from '@nextcloud/dialogs'
91+
import { generateRemoteUrl, generateUrl } from '@nextcloud/router'
8592
import {
8693
NcActionButton as ActionButton,
8794
NcAppNavigationItem as AppNavigationItem,
@@ -93,6 +100,7 @@ import {
93100
import { mapStores } from 'pinia'
94101
import CheckboxBlank from 'vue-material-design-icons/CheckboxBlankOutline.vue'
95102
import CheckboxMarked from 'vue-material-design-icons/CheckboxMarked.vue'
103+
import ContentCopy from 'vue-material-design-icons/ContentCopy.vue'
96104
import LinkVariant from 'vue-material-design-icons/Link.vue'
97105
import Pencil from 'vue-material-design-icons/PencilOutline.vue'
98106
import Undo from 'vue-material-design-icons/Undo.vue'
@@ -113,6 +121,7 @@ export default {
113121
NcActionText,
114122
NcActionSeparator,
115123
NcActionCaption,
124+
ContentCopy,
116125
},
117126
118127
props: {
@@ -145,6 +154,15 @@ export default {
145154
return this.calendar.canBeShared || this.calendar.canBePublished
146155
},
147156
157+
/**
158+
* Whether the calendar is already published or not.
159+
*
160+
* @return {boolean}
161+
*/
162+
isPublished() {
163+
return this.calendar.publishURL !== null
164+
},
165+
148166
/**
149167
* Is the calendar shared with me?
150168
*
@@ -260,6 +278,27 @@ export default {
260278
showEditModal() {
261279
this.calendarsStore.editCalendarModal = { calendarId: this.calendar.id }
262280
},
281+
282+
async copyPublicLink() {
283+
this.showCopyPublicLinkLabel = false
284+
this.showCopyPublicLinkSpinner = true
285+
286+
const rootURL = generateRemoteUrl('dav')
287+
const token = this.calendar.publishURL.split('/').slice(-1)[0]
288+
const url = new URL(generateUrl('apps/calendar') + '/p/' + token, rootURL)
289+
290+
// copy link for calendar to clipboard
291+
try {
292+
await navigator.clipboard.writeText(url)
293+
showSuccess(this.$t('calendar', 'Calendar link copied to clipboard.'))
294+
} catch (error) {
295+
console.debug(error)
296+
showError(this.$t('calendar', 'Calendar link could not be copied to clipboard.'))
297+
} finally {
298+
this.showCopyPublicLinkLabel = true
299+
this.showCopyPublicLinkSpinner = false
300+
}
301+
},
263302
},
264303
}
265304
</script>

0 commit comments

Comments
 (0)