Skip to content

Commit a95a51a

Browse files
committed
refactor(systemtags): properly register hotkey in the files app
Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent 46f754b commit a95a51a

32 files changed

+56
-620
lines changed

apps/systemtags/src/files_actions/bulkSystemTagsAction.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
/**
1+
/*!
22
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import type { INode } from '@nextcloud/files'
6+
import type { ActionContext, ActionContextSingle } from '@nextcloud/files'
77

88
import TagMultipleSvg from '@mdi/svg/svg/tag-multiple-outline.svg?raw'
99
import { FileAction, Permission } from '@nextcloud/files'
@@ -15,10 +15,10 @@ import { defineAsyncComponent } from 'vue'
1515
/**
1616
* Spawn a dialog to add or remove tags from multiple nodes.
1717
*
18-
* @param nodes Nodes to modify tags for
19-
* @param nodes.nodes
18+
* @param context - The action context
19+
* @param context.nodes - Nodes to modify tags for
2020
*/
21-
async function execBatch({ nodes }: { nodes: INode[] }): Promise<(null | boolean)[]> {
21+
async function execBatch({ nodes }: ActionContext | ActionContextSingle): Promise<(null | boolean)[]> {
2222
const response = await new Promise<null | boolean>((resolve) => {
2323
spawnDialog(defineAsyncComponent(() => import('../components/SystemTagPicker.vue')), {
2424
nodes,
@@ -53,9 +53,15 @@ export const action = new FileAction({
5353
return !nodes.some((node) => (node.permissions & Permission.UPDATE) === 0)
5454
},
5555

56-
async exec({ nodes }) {
57-
return execBatch({ nodes })[0]
56+
async exec(context: ActionContextSingle) {
57+
const [result] = await execBatch(context)
58+
return result
5859
},
5960

6061
execBatch,
62+
63+
hotkey: {
64+
description: t('systemtags', 'Manage tags'),
65+
key: 't',
66+
},
6167
})

apps/systemtags/src/files_actions/inlineSystemTagsAction.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
/**
1+
/*!
22
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import type { Node } from '@nextcloud/files'
6+
import type { INode } from '@nextcloud/files'
77
import type { TagWithId } from '../types.ts'
88

99
import { subscribe } from '@nextcloud/event-bus'
@@ -44,11 +44,6 @@ export const action = new FileAction({
4444
},
4545

4646
order: 0,
47-
48-
hotkey: {
49-
description: t('files', 'Manage tags'),
50-
key: 'T',
51-
},
5247
})
5348

5449
// Subscribe to the events
@@ -62,7 +57,7 @@ subscribe('systemtags:tag:updated', updateTag)
6257
*
6358
* @param node - The updated node
6459
*/
65-
function updateSystemTagsHtml(node: Node) {
60+
function updateSystemTagsHtml(node: INode) {
6661
renderInline(node).then((systemTagsHtml) => {
6762
document.querySelectorAll(`[data-systemtags-fileid="${node.fileid}"]`).forEach((element) => {
6863
element.replaceWith(systemTagsHtml)
@@ -113,9 +108,10 @@ function updateSystemTagsColorAttribute(tag: TagWithId) {
113108
}
114109

115110
/**
111+
* Render a single tag element
116112
*
117-
* @param tag
118-
* @param isMore
113+
* @param tag - The tag to render
114+
* @param isMore - Whether this is a "more" tag
119115
*/
120116
function renderTag(tag: string, isMore = false): HTMLElement {
121117
const tagElement = document.createElement('li')
@@ -143,10 +139,11 @@ function renderTag(tag: string, isMore = false): HTMLElement {
143139
}
144140

145141
/**
142+
* Render the inline system tags for a node
146143
*
147-
* @param node
144+
* @param node - The node to render the tags for
148145
*/
149-
async function renderInline(node: Node): Promise<HTMLElement> {
146+
async function renderInline(node: INode): Promise<HTMLElement> {
150147
// Ensure we have the system tags as an array
151148
const tags = getNodeSystemTags(node)
152149

apps/systemtags/src/init.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { registerFileSidebarAction } from './files_actions/filesSidebarAction.ts
1010
import { action as inlineSystemTagsAction } from './files_actions/inlineSystemTagsAction.ts'
1111
import { action as openInFilesAction } from './files_actions/openInFilesAction.ts'
1212
import { registerSystemTagsView } from './files_views/systemtagsView.ts'
13-
import { registerHotkeys } from './services/HotKeysService.ts'
1413

1514
registerDavProperty('nc:system-tags')
1615
registerFileAction(bulkSystemTagsAction)
@@ -19,7 +18,3 @@ registerFileAction(openInFilesAction)
1918

2019
registerSystemTagsView()
2120
registerFileSidebarAction()
22-
23-
document.addEventListener('DOMContentLoaded', () => {
24-
registerHotkeys()
25-
})

apps/systemtags/src/services/HotKeysService.spec.ts

Lines changed: 0 additions & 75 deletions
This file was deleted.

apps/systemtags/src/services/HotKeysService.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

dist/2605-2605.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

dist/2605-2605.js.map.license

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/3442-3442.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)