Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/lint-eslint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# This workflow is provided via the organization template repository
#
# https://github.com/nextcloud-libraries/.github
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization
#
# SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: MIT

name: Lint eslint

on: pull_request

permissions:
contents: read

concurrency:
group: lint-eslint-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest

name: eslint

steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false

- name: Set up node
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version-file: 'package.json'

- name: Install dependencies
env:
CYPRESS_INSTALL_BINARY: 0
PUPPETEER_SKIP_DOWNLOAD: true
run: npm ci

- name: Lint
run: npm run lint
27 changes: 16 additions & 11 deletions lib/components/PublicAuthPrompt.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@
-->

<script setup lang="ts">
import { computed, ref, useTemplateRef, watch } from 'vue'
import { getBuilder } from '@nextcloud/browser-storage'
import { setGuestNickname } from '@nextcloud/auth'
import { getBuilder } from '@nextcloud/browser-storage'
import { showError } from '@nextcloud/dialogs'

import { computed, ref, useTemplateRef, watch } from 'vue'
import NcDialog from '@nextcloud/vue/components/NcDialog'
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
import NcTextField from '@nextcloud/vue/components/NcTextField'

import { t } from '../utils/l10n.ts'
import { logger } from '../utils/logger.ts'

export interface PublicAuthPromptProps {
/**
* Preselected nickname.
* No name preselected by default.
*/
nickname?: string,
nickname?: string

/**
* Dialog title
Expand Down Expand Up @@ -51,10 +50,11 @@ export interface PublicAuthPromptProps {
}

const props = withDefaults(defineProps<PublicAuthPromptProps>(), {
title: t('Guest identification'),
nickname: '',
notice: t('You are currently not identified.'),
submitLabel: t('Submit name'),
text: '',
title: t('Guest identification'),
})

const emit = defineEmits<{
Expand Down Expand Up @@ -91,6 +91,9 @@ const buttons = computed(() => {
return [submitButton]
})

/**
* Handle saving the nickname and return it.
*/
function onSubmit() {
const nickname = name.value.trim()

Expand All @@ -113,9 +116,9 @@ function onSubmit() {
try {
// Set the nickname
setGuestNickname(nickname)
} catch (e) {
} catch (error) {
logger.error('Failed to set nickname', { error })
showError(t('Failed to set nickname.'))
console.error('Failed to set nickname', e)
inputElement.value.focus()
return
}
Expand All @@ -142,18 +145,20 @@ function onSubmit() {
</p>

<!-- Header -->
<NcNoteCard class="public-auth-prompt__header"
<NcNoteCard
class="public-auth-prompt__header"
:text="notice"
type="info" />

<!-- Form -->
<NcTextField ref="input"
<NcTextField
ref="input"
v-model="name"
class="public-auth-prompt__input"
data-cy-public-auth-prompt-dialog-name
:label="t('Name')"
:placeholder="t('Enter your name')"
:required="!cancellable"
v-model="name"
minlength="2"
name="name" />
</NcDialog>
Expand Down
6 changes: 6 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ export {
getFilePickerBuilder,
} from './filepicker-builder.ts'

export {
type GuestUserPromptOptions,

showGuestUserPrompt,
} from './public-auth.ts'

export {
showError,
showInfo,
Expand Down
23 changes: 13 additions & 10 deletions lib/public-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@

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

import { defineAsyncComponent } from 'vue'
import { spawnDialog } from '@nextcloud/vue/functions/dialog'
import { defineAsyncComponent } from 'vue'

export type GuestUserPromptOptions = PublicAuthPromptProps

/**
* Show the public auth prompt dialog
* This is used to ask the current user their nickname
* as well as show some additional contextual information
* @param props The props to pass to the dialog, see PublicAuthPrompt.vue for details
*
* @param props - The props to pass to the dialog
* @return The selected name or undefined if dialog was closed
*/
export function showGuestUserPrompt(props: PublicAuthPromptProps) {
return new Promise((resolve) => {
spawnDialog(
defineAsyncComponent(() => import('./components/PublicAuthPrompt.vue')),
props,
resolve,
)
})
export async function showGuestUserPrompt(props: GuestUserPromptOptions): Promise<string | undefined> {
const name = await spawnDialog(
defineAsyncComponent(() => import('./components/PublicAuthPrompt.vue')),
props,
)
/// @ts-expect-error TODO: remove when fixed upstream: https://github.com/nextcloud-libraries/nextcloud-vue/issues/6902
return name
}
40 changes: 20 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
"name": "@nextcloud/dialogs",
"version": "7.0.0-rc.0",
"description": "Nextcloud dialog helpers",
"keywords": [
"nextcloud"
],
"homepage": "https://github.com/nextcloud-libraries/nextcloud-dialogs#readme",
"repository": {
"type": "git",
"url": "https://github.com/nextcloud-libraries/nextcloud-dialogs"
},
"license": "AGPL-3.0-or-later",
"type": "module",
"exports": {
".": {
Expand All @@ -12,33 +21,30 @@
"import": "./dist/style.css"
}
},
"files": [
"dist"
],
"scripts": {
"build:doc": "npm run dev && npm run doc",
"build": "vite --mode production build",
"build:doc": "npm run dev && npm run doc",
"dev": "vite --mode development build",
"watch": "vite --mode development build --watch",
"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",
"prerelease:format-changelog": "node build/format-changelog.mjs",
"l10n:extract": "node build/extract-l10n.js",
"lint": "eslint lib/",
"lint:fix": "eslint --fix lib/",
"prerelease:format-changelog": "node build/format-changelog.mjs",
"stylelint": "stylelint lib/**/*.vue",
"stylelint:fix": "stylelint lib/**/*.vue --fix",
"test": "vitest run",
"test:coverage": "vitest run --coverage",
"l10n:extract": "node build/extract-l10n.js"
"watch": "vite --mode development build --watch"
},
"keywords": [
"nextcloud"
"browserslist": [
"extends @nextcloud/browserslist-config"
],
"homepage": "https://github.com/nextcloud-libraries/nextcloud-dialogs#readme",
"license": "AGPL-3.0-or-later",
"repository": {
"type": "git",
"url": "https://github.com/nextcloud-libraries/nextcloud-dialogs"
"stylelint": {
"extends": "@nextcloud/stylelint-config"
},
"files": [
"dist"
],
"dependencies": {
"@mdi/js": "^7.4.47",
"@nextcloud/auth": "^2.4.0",
Expand Down Expand Up @@ -90,11 +96,5 @@
"engines": {
"node": "^20 || ^22",
"npm": "^10.0.0"
},
"browserslist": [
"extends @nextcloud/browserslist-config"
],
"stylelint": {
"extends": "@nextcloud/stylelint-config"
}
}
Loading