Skip to content

Commit 493a95a

Browse files
committed
fix(sidebar): properly implement sidebar Proxy for Nextcloud 33+
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent b3b2f4d commit 493a95a

2 files changed

Lines changed: 63 additions & 19 deletions

File tree

lib/sidebar/Sidebar.ts

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

6+
import type { INode } from '../node/node.ts'
67
import type { ISidebarContext, ISidebarTab } from './SidebarTab.ts'
78

89
import { getSidebarTabs, registerSidebarTab } from './SidebarTab.ts'
@@ -17,17 +18,47 @@ export interface ISidebar {
1718
/**
1819
* The current open state of the sidebar
1920
*/
20-
readonly open: boolean
21+
readonly isOpen: boolean
2122

2223
/**
23-
* Open or close the sidebar
24+
* The currently active sidebar tab id
25+
*/
26+
readonly activeTab?: string
27+
28+
/**
29+
* The currently opened node in the sidebar
30+
*/
31+
readonly node?: INode
32+
33+
/**
34+
* Open the sidebar for a specific node.
35+
*
36+
* When the sidebar is fully opened the `files:sidebar:opened` event is emitted,
37+
* see also `@nextcloud/event-bus`.
2438
*
25-
* @param open - The new open state
39+
* @param node - The node to open the sidebar for
40+
* @param tab - The tab to open by default
2641
*/
27-
setOpen(open: boolean): void
42+
open(node: INode, tab?: string): void
2843

2944
/**
30-
* Register a new sidebar tab
45+
* Close the sidebar.
46+
*
47+
* When the sidebar is fully closed the `files:sidebar:closed` event is emitted,
48+
* see also `@nextcloud/event-bus`.
49+
*/
50+
close(): void
51+
52+
/**
53+
* Set the active sidebar tab
54+
*
55+
* @param tabId - The tab to set active
56+
*/
57+
setActiveTab(tabId: string): void
58+
59+
/**
60+
* Register a new sidebar tab.
61+
* This should ideally be done on app initialization using Nextcloud init scripts.
3162
*
3263
* @param tab - The sidebar tab to register
3364
*/
@@ -50,36 +81,49 @@ export interface ISidebar {
5081
*/
5182
class SidebarProxy implements ISidebar {
5283

84+
get #impl(): Omit<ISidebar, 'available' | 'registerTab'> | undefined {
85+
return window.OCA?.Files?._sidebar
86+
}
87+
5388
get available(): boolean {
54-
return !!window.OCA?.Files?.Sidebar
89+
return !!this.#impl
5590
}
5691

57-
get open(): boolean {
58-
return !!window.OCA?.Files?.Sidebar?.state.file
92+
get isOpen(): boolean {
93+
return this.#impl?.isOpen ?? false
5994
}
6095

61-
setOpen(open: boolean): void {
62-
if (open) {
63-
window.OCA?.Files?.Sidebar?.open()
64-
} else {
65-
window.OCA?.Files?.Sidebar?.close()
66-
}
96+
get activeTab(): string | undefined {
97+
return this.#impl?.activeTab
98+
}
99+
100+
get node(): INode | undefined {
101+
return this.#impl?.node
102+
}
103+
104+
open(node: INode, tab?: string): void {
105+
this.#impl?.open(node, tab)
106+
}
107+
108+
close(): void {
109+
this.#impl?.close()
67110
}
68111

69112
setActiveTab(tabId: string): void {
70-
window.OCA?.Files?.Sidebar?.setActiveTab(tabId)
113+
this.#impl?.setActiveTab(tabId)
71114
}
72115

73116
registerTab(tab: ISidebarTab): void {
74117
registerSidebarTab(tab)
75118
}
76119

77120
getTabs(context?: ISidebarContext): ISidebarTab[] {
78-
const tabs = getSidebarTabs()
121+
let tabs = getSidebarTabs()
79122
if (context) {
80-
return tabs.filter((tab) => tab.enabled(context))
123+
tabs = tabs.filter((tab) => tab.enabled(context))
81124
}
82-
return tabs
125+
126+
return tabs.sort((a, b) => a.order - b.order)
83127
}
84128

85129
}

lib/sidebar/index.ts

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

6-
export type { ISidebarContext, ISidebarTab, SidebarComponent } from './SidebarTab.ts'
76
export * from './Sidebar.ts'
7+
export * from './SidebarTab.ts'

0 commit comments

Comments
 (0)