|
| 1 | +<!-- |
| 2 | + - SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors |
| 3 | + - SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + --> |
| 5 | +<template> |
| 6 | + <NcHeaderMenu id="public-page-user-menu" |
| 7 | + class="public-page-user-menu" |
| 8 | + is-nav |
| 9 | + :aria-label="t('core', 'User menu')" |
| 10 | + :description="avatarDescription"> |
| 11 | + <template #trigger> |
| 12 | + <NcAvatar class="public-page-user-menu__avatar" |
| 13 | + disable-menu |
| 14 | + disable-tooltip |
| 15 | + is-guest |
| 16 | + :user="currentUser || '?'" /> |
| 17 | + </template> |
| 18 | + <ul class="public-page-user-menu__list"> |
| 19 | + <!-- Privacy notice --> |
| 20 | + <NcNoteCard class="public-page-user-menu__list-note" |
| 21 | + :text="privacyNotice" |
| 22 | + type="info" /> |
| 23 | + |
| 24 | + <!-- Nickname dialog --> |
| 25 | + <AccountMenuEntry id="set-nickname" |
| 26 | + :name="!currentUser ? t('core', 'Set public name') : t('core', 'Change public name')" |
| 27 | + href="#" |
| 28 | + @click.capture.prevent.stop="setNickname"> |
| 29 | + <template #icon> |
| 30 | + <IconAccount /> |
| 31 | + </template> |
| 32 | + </AccountMenuEntry> |
| 33 | + </ul> |
| 34 | + </NcHeaderMenu> |
| 35 | +</template> |
| 36 | + |
| 37 | +<script lang="ts"> |
| 38 | +import { defineAsyncComponent, defineComponent } from 'vue' |
| 39 | +import { getGuestNickname } from '@nextcloud/auth' |
| 40 | +import { spawnDialog } from '@nextcloud/dialogs' |
| 41 | +import { t } from '@nextcloud/l10n' |
| 42 | +
|
| 43 | +import NcAvatar from '@nextcloud/vue/components/NcAvatar' |
| 44 | +import NcHeaderMenu from '@nextcloud/vue/components/NcHeaderMenu' |
| 45 | +import NcNoteCard from '@nextcloud/vue/components/NcNoteCard' |
| 46 | +import IconAccount from 'vue-material-design-icons/Account.vue' |
| 47 | +
|
| 48 | +import AccountMenuEntry from '../components/AccountMenu/AccountMenuEntry.vue' |
| 49 | +
|
| 50 | +export default defineComponent({ |
| 51 | + name: 'PublicPageUserMenu', |
| 52 | + components: { |
| 53 | + AccountMenuEntry, |
| 54 | + IconAccount, |
| 55 | + NcAvatar, |
| 56 | + NcHeaderMenu, |
| 57 | + NcNoteCard, |
| 58 | + }, |
| 59 | +
|
| 60 | + setup() { |
| 61 | + return { |
| 62 | + t, |
| 63 | + } |
| 64 | + }, |
| 65 | +
|
| 66 | + data() { |
| 67 | + return { |
| 68 | + currentUser: getGuestNickname(), |
| 69 | + } |
| 70 | + }, |
| 71 | +
|
| 72 | + computed: { |
| 73 | + avatarDescription(): string { |
| 74 | + return t('core', 'User menu') |
| 75 | + }, |
| 76 | +
|
| 77 | + privacyNotice(): string { |
| 78 | + return this.currentUser |
| 79 | + ? t('core', 'You will be identified as {user} by the account owner.', { user: this.currentUser }) |
| 80 | + : t('core', 'You are currently not identified.') |
| 81 | + }, |
| 82 | + }, |
| 83 | +
|
| 84 | + methods: { |
| 85 | + setNickname() { |
| 86 | + spawnDialog( |
| 87 | + defineAsyncComponent(() => import('../../../apps/files_sharing/src/views/PublicAuthPrompt.vue')), |
| 88 | + { |
| 89 | + nickname: this.currentUser, |
| 90 | + }, |
| 91 | + ((newName: string) => { this.currentUser = newName }) as (...rest: unknown[]) => void, |
| 92 | + ) |
| 93 | + }, |
| 94 | + }, |
| 95 | +}) |
| 96 | +</script> |
| 97 | + |
| 98 | +<style scoped lang="scss"> |
| 99 | +.public-page-user-menu { |
| 100 | + box-sizing: border-box; |
| 101 | +
|
| 102 | + // Ensure we do not waste space, as the header menu sets a default width of 350px |
| 103 | + :deep(.header-menu__content) { |
| 104 | + width: fit-content !important; |
| 105 | + } |
| 106 | +
|
| 107 | + &__list-note { |
| 108 | + padding-block: 5px !important; |
| 109 | + padding-inline: 5px !important; |
| 110 | + max-width: 300px; |
| 111 | + margin: 5px !important; |
| 112 | + margin-bottom: 0 !important; |
| 113 | + } |
| 114 | +
|
| 115 | + &__list { |
| 116 | + display: inline-flex; |
| 117 | + flex-direction: column; |
| 118 | + padding-block: var(--default-grid-baseline) 0; |
| 119 | + padding-inline: 0 var(--default-grid-baseline); |
| 120 | +
|
| 121 | + > :deep(li) { |
| 122 | + box-sizing: border-box; |
| 123 | + // basically "fit-content" |
| 124 | + flex: 0 1; |
| 125 | + } |
| 126 | + } |
| 127 | +} |
| 128 | +</style> |
0 commit comments