Skip to content

Commit 6463a27

Browse files
committed
renderer: onHoverOut and onHover should use tabId.
1 parent f17e01f commit 6463a27

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

app/renderer/js/main.ts

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ export class ServerManagerView {
7777
$reloadTooltip: HTMLElement;
7878
$loadingTooltip: HTMLElement;
7979
$settingsTooltip: HTMLElement;
80-
$serverIconTooltip: HTMLCollectionOf<HTMLElement>;
8180
$backTooltip: HTMLElement;
8281
$dndTooltip: HTMLElement;
8382
$sidebar: Element;
@@ -106,15 +105,6 @@ export class ServerManagerView {
106105
this.$loadingTooltip = $actionsContainer.querySelector("#loading-tooltip")!;
107106
this.$settingsTooltip =
108107
$actionsContainer.querySelector("#setting-tooltip")!;
109-
110-
// TODO: This should have been querySelector but the problem is that
111-
// querySelector doesn't return elements not present in dom whereas somehow
112-
// getElementsByClassName does. To fix this we need to call this after this.initTabs
113-
// is called in this.init.
114-
// eslint-disable-next-line unicorn/prefer-query-selector
115-
this.$serverIconTooltip = document.getElementsByClassName(
116-
"server-tooltip",
117-
) as HTMLCollectionOf<HTMLElement>;
118108
this.$backTooltip = $actionsContainer.querySelector("#back-tooltip")!;
119109
this.$dndTooltip = $actionsContainer.querySelector("#dnd-tooltip")!;
120110

@@ -392,8 +382,8 @@ export class ServerManagerView {
392382
onClick: this.activateLastTab.bind(this, tabId),
393383
index,
394384
tabId,
395-
onHover: this.onHover.bind(this, index),
396-
onHoverOut: this.onHoverOut.bind(this, index),
385+
onHover: this.onHover.bind(this, tabId),
386+
onHoverOut: this.onHoverOut.bind(this, tabId),
397387
webview: WebView.create({
398388
$root: this.$webviewsContainer,
399389
rootWebContents,
@@ -545,20 +535,18 @@ export class ServerManagerView {
545535
});
546536
}
547537

548-
onHover(index: number): void {
549-
// `this.$serverIconTooltip[index].textContent` already has realm name, so we are just
550-
// removing the style.
551-
this.$serverIconTooltip[index].removeAttribute("style");
538+
onHover(tabId: string): void {
539+
const tooltip = this.getServerTooltip(tabId)!;
540+
tooltip.removeAttribute("style");
552541
// To handle position of servers' tooltip due to scrolling of list of organizations
553542
// This could not be handled using CSS, hence the top of the tooltip is made same
554543
// as that of its parent element.
555-
const {top} =
556-
this.$serverIconTooltip[index].parentElement!.getBoundingClientRect();
557-
this.$serverIconTooltip[index].style.top = `${top}px`;
544+
const {top} = tooltip.parentElement!.getBoundingClientRect();
545+
tooltip.style.top = `${top}px`;
558546
}
559547

560-
onHoverOut(index: number): void {
561-
this.$serverIconTooltip[index].style.display = "none";
548+
onHoverOut(tabId: string): void {
549+
this.getServerTooltip(tabId)!.style.display = "none";
562550
}
563551

564552
async openFunctionalTab(tabProperties: {
@@ -826,6 +814,13 @@ export class ServerManagerView {
826814
return this.tabs.find((tab) => tab.properties.tabId === tabId);
827815
}
828816

817+
getServerTooltip(tabId: string): HTMLElement | undefined {
818+
const tooltipElement = this.$tabsContainer.querySelector(
819+
`.tab[data-tab-id="${CSS.escape(tabId)}"] .server-tooltip`,
820+
);
821+
return tooltipElement instanceof HTMLElement ? tooltipElement : undefined;
822+
}
823+
829824
addContextMenu($serverImg: HTMLElement): void {
830825
$serverImg.addEventListener("contextmenu", async (event) => {
831826
event.preventDefault();

0 commit comments

Comments
 (0)