Skip to content

Commit 1527c5e

Browse files
committed
fixup! feat(files_sharing): show Account menu on public pages
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent 2ad1fc6 commit 1527c5e

3 files changed

Lines changed: 82 additions & 25 deletions

File tree

apps/files_sharing/src/views/PublicAuthPrompt.vue

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
data-cy-public-auth-prompt-dialog-name
2727
:label="t('files_sharing', 'Name')"
2828
:placeholder="t('files_sharing', 'Enter your name')"
29+
:required="!cancellable"
30+
:value.sync="name"
2931
minlength="2"
30-
name="name"
31-
required
32-
:value.sync="name" />
32+
name="name" />
3333
</NcDialog>
3434
</template>
3535

@@ -42,9 +42,11 @@ import { t } from '@nextcloud/l10n'
4242
import NcDialog from '@nextcloud/vue/components/NcDialog'
4343
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
4444
import NcTextField from '@nextcloud/vue/components/NcTextField'
45+
import { showError } from '@nextcloud/dialogs'
4546
4647
const storage = getBuilder('files_sharing').build()
4748
49+
// TODO: move to @nextcloud/auth
4850
export default defineComponent({
4951
name: 'PublicAuthPrompt',
5052
@@ -89,6 +91,24 @@ export default defineComponent({
8991
type: String,
9092
default: t('files_sharing', 'You are currently not identified.'),
9193
},
94+
95+
/**
96+
* Dialog submit button label
97+
* @default 'Submit name'
98+
*/
99+
submitLabel: {
100+
type: String,
101+
default: t('files_sharing', 'Submit name'),
102+
},
103+
104+
/**
105+
* Whether the dialog is cancellable
106+
* @default false
107+
*/
108+
cancellable: {
109+
type: Boolean,
110+
default: false,
111+
},
92112
},
93113
94114
setup() {
@@ -105,11 +125,24 @@ export default defineComponent({
105125
106126
computed: {
107127
dialogButtons() {
108-
return [{
109-
label: t('files_sharing', 'Submit name'),
128+
const cancelButton = {
129+
label: t('files_sharing', 'Cancel'),
130+
type: 'tertiary',
131+
callback: () => this.$emit('close'),
132+
}
133+
134+
const submitButton = {
135+
label: this.submitLabel,
110136
type: 'primary',
111137
nativeType: 'submit',
112-
}]
138+
}
139+
140+
// If the dialog is cancellable, add a cancel button
141+
if (this.cancellable) {
142+
return [cancelButton, submitButton]
143+
}
144+
145+
return [submitButton]
113146
},
114147
},
115148
@@ -127,8 +160,24 @@ export default defineComponent({
127160
onSubmit() {
128161
const nickname = this.name.trim()
129162
130-
// Set the nickname
131-
setGuestNickname(nickname)
163+
if (nickname === '') {
164+
// Show error if the nickname is empty
165+
showError(t('files_sharing', 'You cannot leave the name empty.'))
166+
return
167+
}
168+
169+
if (nickname.length < 2) {
170+
// Show error if the nickname is too short
171+
showError(t('files_sharing', 'Please enter a name with at least 2 characters.'))
172+
return
173+
}
174+
175+
try {
176+
// Set the nickname
177+
setGuestNickname(nickname)
178+
} catch (e) {
179+
showError(t('files_sharing', 'Failed to set nickname.'))
180+
}
132181
133182
// Set the dialog as shown
134183
storage.setItem('public-auth-prompt-shown', 'true')

core/src/components/AccountMenu/AccountMenuEntry.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,14 @@ export default defineComponent({
7878
},
7979
8080
methods: {
81-
onClick(e) {
82-
this.loading = true
81+
onClick(e: MouseEvent) {
8382
this.$emit('click', e)
83+
84+
// Allow to not show the loading indicator
85+
// in case the click event was already handled
86+
if (!e.defaultPrevented) {
87+
this.loading = true
88+
}
8489
},
8590
},
8691
})

core/src/views/PublicPageUserMenu.vue

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
disable-menu
1414
disable-tooltip
1515
is-guest
16-
:user="currentUser || '?'" />
16+
:user="displayName || '?'" />
1717
</template>
1818
<ul class="public-page-user-menu__list">
1919
<!-- Privacy notice -->
@@ -25,7 +25,7 @@
2525
<AccountMenuEntry id="set-nickname"
2626
:name="!currentUser ? t('core', 'Set public name') : t('core', 'Change public name')"
2727
href="#"
28-
@click.capture.prevent.stop="setNickname">
28+
@click.prevent.stop="setNickname">
2929
<template #icon>
3030
<IconAccount />
3131
</template>
@@ -35,9 +35,8 @@
3535
</template>
3636

3737
<script lang="ts">
38-
import { defineAsyncComponent, defineComponent } from 'vue'
39-
import { getGuestNickname } from '@nextcloud/auth'
40-
import { spawnDialog } from '@nextcloud/dialogs'
38+
import { defineComponent } from 'vue'
39+
import { getGuestUser, showGuestUserPrompt } from '@nextcloud/auth'
4140
import { t } from '@nextcloud/l10n'
4241
4342
import NcAvatar from '@nextcloud/vue/components/NcAvatar'
@@ -65,7 +64,8 @@ export default defineComponent({
6564
6665
data() {
6766
return {
68-
currentUser: getGuestNickname(),
67+
currentUser: getGuestUser(),
68+
displayName: getGuestUser().displayName,
6969
}
7070
},
7171
@@ -75,21 +75,24 @@ export default defineComponent({
7575
},
7676
7777
privacyNotice(): string {
78-
return this.currentUser
79-
? t('core', 'You will be identified as {user} by the account owner.', { user: this.currentUser })
78+
return this.displayName
79+
? t('core', 'You will be identified as {user} by the account owner.', { user: this.displayName })
8080
: t('core', 'You are currently not identified.')
8181
},
8282
},
8383
84+
mounted() {
85+
this.currentUser.addEventListener('updateDisplayName', () => {
86+
this.displayName = getGuestUser().displayName || ''
87+
})
88+
},
89+
8490
methods: {
8591
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-
)
92+
showGuestUserPrompt({
93+
nickname: this.displayName,
94+
cancellable: true,
95+
})
9396
},
9497
},
9598
})

0 commit comments

Comments
 (0)