Skip to content

Commit 2ac2ef2

Browse files
authored
Merge pull request #1774 from nextcloud-libraries/refactor/code-style
2 parents 79fe932 + 684ebe2 commit 2ac2ef2

File tree

5 files changed

+99
-41
lines changed

5 files changed

+99
-41
lines changed

.github/workflows/lint-eslint.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# This workflow is provided via the organization template repository
2+
#
3+
# https://github.com/nextcloud-libraries/.github
4+
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization
5+
#
6+
# SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors
7+
# SPDX-License-Identifier: MIT
8+
9+
name: Lint eslint
10+
11+
on: pull_request
12+
13+
permissions:
14+
contents: read
15+
16+
concurrency:
17+
group: lint-eslint-${{ github.head_ref || github.run_id }}
18+
cancel-in-progress: true
19+
20+
jobs:
21+
lint:
22+
runs-on: ubuntu-latest
23+
24+
name: eslint
25+
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
29+
with:
30+
persist-credentials: false
31+
32+
- name: Set up node
33+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
34+
with:
35+
node-version-file: 'package.json'
36+
37+
- name: Install dependencies
38+
env:
39+
CYPRESS_INSTALL_BINARY: 0
40+
PUPPETEER_SKIP_DOWNLOAD: true
41+
run: npm ci
42+
43+
- name: Lint
44+
run: npm run lint

lib/components/PublicAuthPrompt.vue

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,22 @@
44
-->
55

66
<script setup lang="ts">
7-
import { computed, ref, useTemplateRef, watch } from 'vue'
8-
import { getBuilder } from '@nextcloud/browser-storage'
97
import { setGuestNickname } from '@nextcloud/auth'
8+
import { getBuilder } from '@nextcloud/browser-storage'
109
import { showError } from '@nextcloud/dialogs'
11-
10+
import { computed, ref, useTemplateRef, watch } from 'vue'
1211
import NcDialog from '@nextcloud/vue/components/NcDialog'
1312
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
1413
import NcTextField from '@nextcloud/vue/components/NcTextField'
15-
1614
import { t } from '../utils/l10n.ts'
15+
import { logger } from '../utils/logger.ts'
1716
1817
export interface PublicAuthPromptProps {
1918
/**
2019
* Preselected nickname.
2120
* No name preselected by default.
2221
*/
23-
nickname?: string,
22+
nickname?: string
2423
2524
/**
2625
* Dialog title
@@ -51,10 +50,11 @@ export interface PublicAuthPromptProps {
5150
}
5251
5352
const props = withDefaults(defineProps<PublicAuthPromptProps>(), {
54-
title: t('Guest identification'),
5553
nickname: '',
5654
notice: t('You are currently not identified.'),
5755
submitLabel: t('Submit name'),
56+
text: '',
57+
title: t('Guest identification'),
5858
})
5959
6060
const emit = defineEmits<{
@@ -91,6 +91,9 @@ const buttons = computed(() => {
9191
return [submitButton]
9292
})
9393
94+
/**
95+
* Handle saving the nickname and return it.
96+
*/
9497
function onSubmit() {
9598
const nickname = name.value.trim()
9699
@@ -113,9 +116,9 @@ function onSubmit() {
113116
try {
114117
// Set the nickname
115118
setGuestNickname(nickname)
116-
} catch (e) {
119+
} catch (error) {
120+
logger.error('Failed to set nickname', { error })
117121
showError(t('Failed to set nickname.'))
118-
console.error('Failed to set nickname', e)
119122
inputElement.value.focus()
120123
return
121124
}
@@ -142,18 +145,20 @@ function onSubmit() {
142145
</p>
143146

144147
<!-- Header -->
145-
<NcNoteCard class="public-auth-prompt__header"
148+
<NcNoteCard
149+
class="public-auth-prompt__header"
146150
:text="notice"
147151
type="info" />
148152

149153
<!-- Form -->
150-
<NcTextField ref="input"
154+
<NcTextField
155+
ref="input"
156+
v-model="name"
151157
class="public-auth-prompt__input"
152158
data-cy-public-auth-prompt-dialog-name
153159
:label="t('Name')"
154160
:placeholder="t('Enter your name')"
155161
:required="!cancellable"
156-
v-model="name"
157162
minlength="2"
158163
name="name" />
159164
</NcDialog>

lib/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ export {
1111
getFilePickerBuilder,
1212
} from './filepicker-builder.ts'
1313

14+
export {
15+
type GuestUserPromptOptions,
16+
17+
showGuestUserPrompt,
18+
} from './public-auth.ts'
19+
1420
export {
1521
showError,
1622
showInfo,

lib/public-auth.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,24 @@
55

66
import type { PublicAuthPromptProps } from './components/PublicAuthPrompt.vue'
77

8-
import { defineAsyncComponent } from 'vue'
98
import { spawnDialog } from '@nextcloud/vue/functions/dialog'
9+
import { defineAsyncComponent } from 'vue'
10+
11+
export type GuestUserPromptOptions = PublicAuthPromptProps
1012

1113
/**
1214
* Show the public auth prompt dialog
1315
* This is used to ask the current user their nickname
1416
* as well as show some additional contextual information
15-
* @param props The props to pass to the dialog, see PublicAuthPrompt.vue for details
17+
*
18+
* @param props - The props to pass to the dialog
19+
* @return The selected name or undefined if dialog was closed
1620
*/
17-
export function showGuestUserPrompt(props: PublicAuthPromptProps) {
18-
return new Promise((resolve) => {
19-
spawnDialog(
20-
defineAsyncComponent(() => import('./components/PublicAuthPrompt.vue')),
21-
props,
22-
resolve,
23-
)
24-
})
21+
export async function showGuestUserPrompt(props: GuestUserPromptOptions): Promise<string | undefined> {
22+
const name = await spawnDialog(
23+
defineAsyncComponent(() => import('./components/PublicAuthPrompt.vue')),
24+
props,
25+
)
26+
/// @ts-expect-error TODO: remove when fixed upstream: https://github.com/nextcloud-libraries/nextcloud-vue/issues/6902
27+
return name
2528
}

package.json

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
"name": "@nextcloud/dialogs",
33
"version": "7.0.0-rc.0",
44
"description": "Nextcloud dialog helpers",
5+
"keywords": [
6+
"nextcloud"
7+
],
8+
"homepage": "https://github.com/nextcloud-libraries/nextcloud-dialogs#readme",
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/nextcloud-libraries/nextcloud-dialogs"
12+
},
13+
"license": "AGPL-3.0-or-later",
514
"type": "module",
615
"exports": {
716
".": {
@@ -12,33 +21,30 @@
1221
"import": "./dist/style.css"
1322
}
1423
},
24+
"files": [
25+
"dist"
26+
],
1527
"scripts": {
16-
"build:doc": "npm run dev && npm run doc",
1728
"build": "vite --mode production build",
29+
"build:doc": "npm run dev && npm run doc",
1830
"dev": "vite --mode development build",
19-
"watch": "vite --mode development build --watch",
2031
"doc": "typedoc --tsconfig tsconfig-typedoc.json --highlightLanguages vue --plugin typedoc-plugin-missing-exports --out dist/doc dist/index.d.ts dist/filepicker.d.ts && touch dist/doc/.nojekyll",
21-
"prerelease:format-changelog": "node build/format-changelog.mjs",
32+
"l10n:extract": "node build/extract-l10n.js",
2233
"lint": "eslint lib/",
2334
"lint:fix": "eslint --fix lib/",
35+
"prerelease:format-changelog": "node build/format-changelog.mjs",
2436
"stylelint": "stylelint lib/**/*.vue",
2537
"stylelint:fix": "stylelint lib/**/*.vue --fix",
2638
"test": "vitest run",
2739
"test:coverage": "vitest run --coverage",
28-
"l10n:extract": "node build/extract-l10n.js"
40+
"watch": "vite --mode development build --watch"
2941
},
30-
"keywords": [
31-
"nextcloud"
42+
"browserslist": [
43+
"extends @nextcloud/browserslist-config"
3244
],
33-
"homepage": "https://github.com/nextcloud-libraries/nextcloud-dialogs#readme",
34-
"license": "AGPL-3.0-or-later",
35-
"repository": {
36-
"type": "git",
37-
"url": "https://github.com/nextcloud-libraries/nextcloud-dialogs"
45+
"stylelint": {
46+
"extends": "@nextcloud/stylelint-config"
3847
},
39-
"files": [
40-
"dist"
41-
],
4248
"dependencies": {
4349
"@mdi/js": "^7.4.47",
4450
"@nextcloud/auth": "^2.4.0",
@@ -90,11 +96,5 @@
9096
"engines": {
9197
"node": "^20 || ^22",
9298
"npm": "^10.0.0"
93-
},
94-
"browserslist": [
95-
"extends @nextcloud/browserslist-config"
96-
],
97-
"stylelint": {
98-
"extends": "@nextcloud/stylelint-config"
9999
}
100100
}

0 commit comments

Comments
 (0)