|
1 | 1 | /** |
2 | | - * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors |
| 2 | + * SPDX-FileCopyrightText: Nextcloud GmbH and Nextcloud contributors |
3 | 3 | * SPDX-License-Identifier: AGPL-3.0-or-later |
4 | 4 | */ |
5 | 5 |
|
| 6 | +import { logger } from './logger.ts' |
| 7 | + |
| 8 | +export interface IProfileSection { |
| 9 | + /** |
| 10 | + * Unique identifier for the section |
| 11 | + */ |
| 12 | + id: string |
| 13 | + /** |
| 14 | + * The order in which the section should appear |
| 15 | + */ |
| 16 | + order: number |
| 17 | + /** |
| 18 | + * The custom element tag name to be used for this section |
| 19 | + * |
| 20 | + * The custom element must have been registered beforehand, |
| 21 | + * and must have the a `user` property of type `string | undefined`. |
| 22 | + * |
| 23 | + * @see https://developer.mozilla.org/en-US/docs/Web/API/Web_components |
| 24 | + */ |
| 25 | + tagName: string |
| 26 | + /** |
| 27 | + * Static parameters to be passed to the custom web component |
| 28 | + */ |
| 29 | + params?: Record<string, unknown> |
| 30 | +} |
| 31 | + |
6 | 32 | export default class ProfileSections { |
7 | | - _sections |
| 33 | + #sections: Map<string, IProfileSection> |
8 | 34 |
|
9 | 35 | constructor() { |
10 | | - this._sections = [] |
| 36 | + this.#sections = new Map() |
11 | 37 | } |
12 | 38 |
|
13 | 39 | /** |
14 | 40 | * @param section To be called to mount the section to the profile page |
15 | 41 | */ |
16 | | - registerSection(section) { |
17 | | - this._sections.push(section) |
| 42 | + registerSection(section: IProfileSection) { |
| 43 | + if (this.#sections.has(section.id)) { |
| 44 | + logger.warn(`Profile section with id '${section.id}' is already registered.`) |
| 45 | + } |
| 46 | + this.#sections.set(section.id, section) |
18 | 47 | } |
19 | 48 |
|
20 | 49 | getSections() { |
21 | | - return this._sections |
| 50 | + return [...this.#sections.values()] |
22 | 51 | } |
23 | 52 | } |
0 commit comments