mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-11-10 17:05:47 +00:00
nav: Add NavItem literal type.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
@@ -13,6 +13,7 @@ import FunctionalTab from "./components/functional-tab";
|
|||||||
import ServerTab from "./components/server-tab";
|
import ServerTab from "./components/server-tab";
|
||||||
import WebView from "./components/webview";
|
import WebView from "./components/webview";
|
||||||
import {feedbackHolder} from "./feedback";
|
import {feedbackHolder} from "./feedback";
|
||||||
|
import type {NavItem} from "./pages/preference/nav";
|
||||||
import * as DomainUtil from "./utils/domain-util";
|
import * as DomainUtil from "./utils/domain-util";
|
||||||
import * as LinkUtil from "./utils/link-util";
|
import * as LinkUtil from "./utils/link-util";
|
||||||
import ReconnectUtil from "./utils/reconnect-util";
|
import ReconnectUtil from "./utils/reconnect-util";
|
||||||
@@ -612,7 +613,7 @@ class ServerManagerView {
|
|||||||
this.activateTab(this.functionalTabs.get(tabProps.name));
|
this.activateTab(this.functionalTabs.get(tabProps.name));
|
||||||
}
|
}
|
||||||
|
|
||||||
async openSettings(nav = "General"): Promise<void> {
|
async openSettings(nav: NavItem = "General"): Promise<void> {
|
||||||
this.openFunctionalTab({
|
this.openFunctionalTab({
|
||||||
name: "Settings",
|
name: "Settings",
|
||||||
materialIcon: "settings",
|
materialIcon: "settings",
|
||||||
@@ -971,12 +972,9 @@ class ServerManagerView {
|
|||||||
this.openNetworkTroubleshooting(index);
|
this.openNetworkTroubleshooting(index);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcRenderer.on(
|
ipcRenderer.on("open-settings", async () => {
|
||||||
"open-settings",
|
await this.openSettings();
|
||||||
async (event: Event, settingNav: string) => {
|
});
|
||||||
await this.openSettings(settingNav);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
ipcRenderer.on("open-about", this.openAbout.bind(this));
|
ipcRenderer.on("open-about", this.openAbout.bind(this));
|
||||||
|
|
||||||
|
|||||||
@@ -3,14 +3,21 @@ import {html} from "../../../../common/html";
|
|||||||
import * as t from "../../../../common/translation-util";
|
import * as t from "../../../../common/translation-util";
|
||||||
import BaseComponent from "../../components/base";
|
import BaseComponent from "../../components/base";
|
||||||
|
|
||||||
|
export type NavItem =
|
||||||
|
| "General"
|
||||||
|
| "Network"
|
||||||
|
| "AddServer"
|
||||||
|
| "Organizations"
|
||||||
|
| "Shortcuts";
|
||||||
|
|
||||||
interface PreferenceNavProps {
|
interface PreferenceNavProps {
|
||||||
$root: Element;
|
$root: Element;
|
||||||
onItemSelected: (navItem: string) => void;
|
onItemSelected: (navItem: NavItem) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class PreferenceNav extends BaseComponent {
|
export default class PreferenceNav extends BaseComponent {
|
||||||
props: PreferenceNavProps;
|
props: PreferenceNavProps;
|
||||||
navItems: string[];
|
navItems: NavItem[];
|
||||||
$el: Element;
|
$el: Element;
|
||||||
constructor(props: PreferenceNavProps) {
|
constructor(props: PreferenceNavProps) {
|
||||||
super();
|
super();
|
||||||
@@ -57,7 +64,7 @@ export default class PreferenceNav extends BaseComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
select(navItemToSelect: string): void {
|
select(navItemToSelect: NavItem): void {
|
||||||
for (const navItem of this.navItems) {
|
for (const navItem of this.navItems) {
|
||||||
if (navItem === navItemToSelect) {
|
if (navItem === navItemToSelect) {
|
||||||
this.activate(navItem);
|
this.activate(navItem);
|
||||||
@@ -67,12 +74,12 @@ export default class PreferenceNav extends BaseComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
activate(navItem: string): void {
|
activate(navItem: NavItem): void {
|
||||||
const $item = document.querySelector(`#nav-${CSS.escape(navItem)}`);
|
const $item = document.querySelector(`#nav-${CSS.escape(navItem)}`);
|
||||||
$item.classList.add("active");
|
$item.classList.add("active");
|
||||||
}
|
}
|
||||||
|
|
||||||
deactivate(navItem: string): void {
|
deactivate(navItem: NavItem): void {
|
||||||
const $item = document.querySelector(`#nav-${CSS.escape(navItem)}`);
|
const $item = document.querySelector(`#nav-${CSS.escape(navItem)}`);
|
||||||
$item.classList.remove("active");
|
$item.classList.remove("active");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import BaseComponent from "../../components/base";
|
|||||||
import ConnectedOrgSection from "./connected-org-section";
|
import ConnectedOrgSection from "./connected-org-section";
|
||||||
import GeneralSection from "./general-section";
|
import GeneralSection from "./general-section";
|
||||||
import Nav from "./nav";
|
import Nav from "./nav";
|
||||||
|
import type {NavItem} from "./nav";
|
||||||
import NetworkSection from "./network-section";
|
import NetworkSection from "./network-section";
|
||||||
import ServersSection from "./servers-section";
|
import ServersSection from "./servers-section";
|
||||||
import ShortcutsSection from "./shortcuts-section";
|
import ShortcutsSection from "./shortcuts-section";
|
||||||
@@ -39,16 +40,15 @@ export default class PreferenceView extends BaseComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setDefaultView(): void {
|
setDefaultView(): void {
|
||||||
let nav = "General";
|
const navItem =
|
||||||
const hasTag = window.location.hash;
|
this.nav.navItems.find(
|
||||||
if (hasTag) {
|
(navItem) => window.location.hash === `#${navItem}`,
|
||||||
nav = hasTag.slice(1);
|
) ?? "General";
|
||||||
|
|
||||||
|
this.handleNavigation(navItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.handleNavigation(nav);
|
handleNavigation(navItem: NavItem): void {
|
||||||
}
|
|
||||||
|
|
||||||
handleNavigation(navItem: string): void {
|
|
||||||
this.nav.select(navItem);
|
this.nav.select(navItem);
|
||||||
switch (navItem) {
|
switch (navItem) {
|
||||||
case "AddServer": {
|
case "AddServer": {
|
||||||
@@ -87,7 +87,7 @@ export default class PreferenceView extends BaseComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
((n: never) => n)(navItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.section.init();
|
this.section.init();
|
||||||
@@ -104,7 +104,7 @@ export default class PreferenceView extends BaseComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
registerIpcs(): void {
|
registerIpcs(): void {
|
||||||
ipcRenderer.on("switch-settings-nav", (_event: Event, navItem: string) => {
|
ipcRenderer.on("switch-settings-nav", (_event: Event, navItem: NavItem) => {
|
||||||
this.handleNavigation(navItem);
|
this.handleNavigation(navItem);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user