Files
zulip-desktop/app/renderer/js/pages/preference/connected-org-section.ts
Anders Kaseorg 6ca4d77b8f Explode ServerInfoForm class to a function.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-04-02 14:25:59 -07:00

93 lines
2.6 KiB
TypeScript

import {ipcRenderer} from "electron";
import type {HTML} from "../../../../common/html";
import {html} from "../../../../common/html";
import * as t from "../../../../common/translation-util";
import * as DomainUtil from "../../utils/domain-util";
import {reloadApp} from "./base-section";
import {initFindAccounts} from "./find-accounts";
import {initServerInfoForm} from "./server-info-form";
interface ConnectedOrgSectionProps {
$root: Element;
}
export default class ConnectedOrgSection {
props: ConnectedOrgSectionProps;
$serverInfoContainer: Element | null;
$existingServers: Element | null;
$newOrgButton: HTMLButtonElement | null;
$findAccountsContainer: Element | null;
constructor(props: ConnectedOrgSectionProps) {
this.props = props;
}
templateHTML(): HTML {
return html`
<div class="settings-pane" id="server-settings-pane">
<div class="page-title">${t.__("Connected organizations")}</div>
<div class="title" id="existing-servers">
${t.__("All the connected orgnizations will appear here.")}
</div>
<div id="server-info-container"></div>
<div id="new-org-button">
<button class="green sea w-250">
${t.__("Connect to another organization")}
</button>
</div>
<div class="page-title">${t.__("Find accounts by email")}</div>
<div id="find-accounts-container"></div>
</div>
`;
}
init(): void {
this.initServers();
}
initServers(): void {
this.props.$root.textContent = "";
const servers = DomainUtil.getDomains();
this.props.$root.innerHTML = this.templateHTML().html;
this.$serverInfoContainer = document.querySelector(
"#server-info-container",
);
this.$existingServers = document.querySelector("#existing-servers");
this.$newOrgButton = document.querySelector("#new-org-button");
this.$findAccountsContainer = document.querySelector(
"#find-accounts-container",
);
const noServerText = t.__(
"All the connected orgnizations will appear here",
);
// Show noServerText if no servers are there otherwise hide it
this.$existingServers.textContent =
servers.length === 0 ? noServerText : "";
for (const [i, server] of servers.entries()) {
initServerInfoForm({
$root: this.$serverInfoContainer,
server,
index: i,
onChange: reloadApp,
});
}
this.$newOrgButton.addEventListener("click", () => {
ipcRenderer.send("forward-message", "open-org-tab");
});
this.initFindAccounts();
}
initFindAccounts(): void {
initFindAccounts({
$root: this.$findAccountsContainer,
});
}
}