Skip to content

Commit f596764

Browse files
authored
Merge pull request #1440 from nextcloud-libraries/fix/types
chore: adjust types to only use interfaces if possible
2 parents 5377cd3 + 2647084 commit f596764

3 files changed

Lines changed: 23 additions & 16 deletions

File tree

lib/navigation/view.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,23 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import type { Folder } from '../node/folder.ts'
7-
import type { Node } from '../node/node.ts'
6+
import type { IFolder, INode } from '../node/index.ts'
87

98
import isSvg from 'is-svg'
109
import { Column } from './column.ts'
1110

1211
export type ContentsWithRoot = {
13-
folder: Folder,
14-
contents: Node[]
12+
folder: IFolder,
13+
contents: INode[]
14+
}
15+
16+
export interface IGetContentsOptions {
17+
/**
18+
* Abort signal to be able to cancel the request.
19+
*
20+
*@see https://developer.mozilla.org/en-US/docs/Web/API/AbortController
21+
*/
22+
signal: AbortSignal
1523
}
1624

1725
export interface IView {
@@ -42,11 +50,11 @@ export interface IView {
4250
* This method _must_ also return the current directory
4351
* information alongside with its content.
4452
*
45-
* Usually a abort signal is provided to be able to
53+
* An abort signal is provided to be able to
4654
* cancel the request if the user change directory
4755
* {@see https://developer.mozilla.org/en-US/docs/Web/API/AbortController }.
4856
*/
49-
getContents(path: string, options: { signal: AbortSignal }): Promise<ContentsWithRoot>
57+
getContents(path: string, options: IGetContentsOptions): Promise<ContentsWithRoot>
5058

5159
/**
5260
* If set then the view will be hidden from the navigation unless its the active view.
@@ -95,8 +103,7 @@ export interface IView {
95103
/**
96104
* Method called to load child views if any
97105
*/
98-
// eslint-disable-next-line no-use-before-define
99-
loadChildViews?: (view: View) => Promise<void>
106+
loadChildViews?: (view: IView) => Promise<void>
100107
}
101108

102109
export class View implements IView {

lib/newMenu/NewMenu.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import type { Folder, Node } from '../node/index.ts'
6+
import type { IFolder, INode } from '../node/index.ts'
77

88
import logger from '../utils/logger.ts'
99

@@ -43,7 +43,7 @@ export interface NewMenuEntry {
4343
* Condition wether this entry is shown or not
4444
* @param context the creation context. Usually the current folder
4545
*/
46-
enabled?: (context: Folder) => boolean
46+
enabled?: (context: IFolder) => boolean
4747

4848
/**
4949
* Either iconSvgInline or iconClass must be defined
@@ -59,7 +59,7 @@ export interface NewMenuEntry {
5959
* @param context - The creation context. Usually the current folder
6060
* @param content - List of file/folders present in the context folder
6161
*/
62-
handler: (context: Folder, content: Node[]) => void
62+
handler: (context: IFolder, content: INode[]) => void
6363
}
6464

6565
export class NewMenu {
@@ -88,9 +88,9 @@ export class NewMenu {
8888
/**
8989
* Get the list of registered entries
9090
*
91-
* @param {Folder} context the creation context. Usually the current folder
91+
* @param context - The creation context. Usually the current folder
9292
*/
93-
public getEntries(context?: Folder): Array<NewMenuEntry> {
93+
public getEntries(context?: IFolder): Array<NewMenuEntry> {
9494
if (context) {
9595
return this._entries
9696
.filter(entry => typeof entry.enabled === 'function' ? entry.enabled(context) : true)

lib/newMenu/functions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import type { Folder } from '../node/index.ts'
6+
import type { IFolder } from '../node/index.ts'
77
import type { NewMenuEntry } from './NewMenu.ts'
88

99
import { NewMenu } from './NewMenu.ts'
@@ -43,9 +43,9 @@ export function removeNewFileMenuEntry(entry: NewMenuEntry | string) {
4343
/**
4444
* Get the list of registered entries from the upload menu
4545
*
46-
* @param {Folder} context - The current folder to get the available entries
46+
* @param context - The current folder to get the available entries
4747
*/
48-
export function getNewFileMenuEntries(context?: Folder): NewMenuEntry[] {
48+
export function getNewFileMenuEntries(context?: IFolder): NewMenuEntry[] {
4949
const newFileMenu = getNewFileMenu()
5050
return newFileMenu.getEntries(context).sort((a: NewMenuEntry, b: NewMenuEntry) => {
5151
// If defined and different, sort by order

0 commit comments

Comments
 (0)