Skip to content

Commit e8a88b9

Browse files
Refactor UI mode switching and add sidebar state management
Refactors the permission-based UI switching to use existing robust methods (addClassicUI/addNotebookbarUI) and adds sidebar visibility state management across mode switches. UIManager: - Refactored onUpdatePermission to use addClassicUI/addNotebookbarUI - Added safety checks to prevent duplicate component creation - Added sidebar visibility management (show in edit, hide in readonly) SidebarBase: - Added showSidebar() method to restore sidebar visibility client-side - Complements existing closeSidebar() for clean state management This ensures: - Consistent UI initialization (fixes TopToolbar and style dropdowns) - Sidebar state is preserved across mode switches - Robust handling of duplicate calls and edge cases Signed-off-by: Darshan-upadhyay1110 <[email protected]> Change-Id: I61b71cc4c3a68cce77dc198631fb6600dbb6a0de
1 parent 695c201 commit e8a88b9

File tree

2 files changed

+27
-43
lines changed

2 files changed

+27
-43
lines changed

browser/src/control/Control.SidebarBase.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ abstract class SidebarBase extends JSDialogComponent {
9292
this.map.uiManager.setDocTypePref('Show' + upperCaseType, false);
9393
}
9494

95+
showSidebar() {
96+
$(`#${this.type}-dock-wrapper`).addClass('visible');
97+
if (this.builder && (this.builder as any).windowId === WindowId.Sidebar)
98+
$(`#${this.type}-dock-wrapper`).addClass('coreBased');
99+
100+
const upperCaseType = this.type[0].toUpperCase() + this.type.slice(1);
101+
this.map.uiManager.setDocTypePref('Show' + upperCaseType, true);
102+
}
103+
95104
protected onJSUpdate(e: FireEvent) {
96105
// reduce unwanted warnings in console
97106
if (e?.data?.control.id === 'addonimage') {

browser/src/control/Control.UIManager.ts

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class UIManager extends window.L.Control {
4545
hiddenCommands: { [key: string]: boolean } = {};
4646
// Hidden Notebookbar tabs.
4747
hiddenTabs: { [key: string]: boolean } = {};
48+
permissionViewMode: any = null;
49+
// Add a flag to track initialization
50+
private isUIInitialized: boolean = false;
4851

4952
/**
5053
* Called when the UIManager control is added to the map.
@@ -357,21 +360,8 @@ class UIManager extends window.L.Control {
357360
if (!isMobile && !enableNotebookbar)
358361
this.map.topToolbar = JSDialog.TopToolbar(this.map);
359362

360-
// this will execute only when UI get initialized
361-
if (!isMobile) {
362-
this.topReadonlyBtn = document.getElementById('readonlyMode');
363-
const label = this.topReadonlyBtn?.querySelector(
364-
'.unolabel',
365-
) as HTMLElement | null;
366-
if (label) {
367-
label.textContent = _('Read-only');
368-
this.topReadonlyBtn.setAttribute('data-cooltip', _('Permission Mode'));
369-
window.L.control.attachTooltipEventListener(
370-
this.topReadonlyBtn,
371-
this.map,
372-
);
373-
}
374-
}
363+
this.permissionViewMode = new PermissionViewMode(this.map);
364+
this.permissionViewMode.init();
375365
}
376366

377367
/**
@@ -1475,43 +1465,28 @@ class UIManager extends window.L.Control {
14751465
var enableNotebookbar = this.shouldUseNotebookbarMode();
14761466
if (enableNotebookbar && !window.mode.isMobile()) {
14771467
if (e.detail.perm === 'edit') {
1478-
if (this.map.menubar) {
1479-
this.map.removeControl(this.map.menubar);
1480-
this.map.menubar = null;
1468+
this.removeClassicUI();
1469+
1470+
if (!this.isUIInitialized) {
1471+
this.isUIInitialized = true;
14811472
}
1482-
} else if (e.detail.perm === 'readonly') {
1483-
if (!this.map.menubar) {
1484-
var menubar = new Menubar();
1485-
this.map.menubar = menubar;
1486-
this.map.addControl(menubar);
1473+
else {
1474+
this.makeSpaceForNotebookbar();
1475+
this.addNotebookbarUI();
14871476
}
1488-
1489-
if (this.notebookbar && $('#mobile-edit-button').is(':hidden')) {
1490-
this.notebookbar.onRemove();
1477+
} else if (e.detail.perm === 'readonly') {
1478+
if (this.map.sidebar && this.map.sidebar.isVisible()) {
1479+
this.map.sidebar.closeSidebar();
1480+
app.socket.sendMessage('uno .uno:SidebarHide');
14911481
}
1482+
this.removeNotebookbarUI();
1483+
this.addClassicUI();
14921484
} else {
14931485
app.socket.sendMessage('uno .uno:SidebarHide');
14941486
}
1495-
this.makeSpaceForNotebookbar();
14961487
}
1497-
this.updateReadonlyIndicator();
14981488
}
14991489

1500-
/**
1501-
* Updates visibility of the Read-only badge/button in the top toolbar.
1502-
*/
1503-
updateReadonlyIndicator(): void {
1504-
app.layoutingService.appendLayoutingTask(() =>{
1505-
if (!this.topReadonlyBtn)
1506-
return;
1507-
1508-
if (app.isReadOnly()) {
1509-
this.topReadonlyBtn.classList.remove('hidden');
1510-
} else {
1511-
this.topReadonlyBtn.classList.add('hidden');
1512-
}
1513-
})
1514-
}
15151490

15161491
refreshTheme(): void {
15171492
if (typeof window.initializedUI === 'function') {

0 commit comments

Comments
 (0)