Skip to content

Commit 33690b2

Browse files
committed
tab: Rename tabIndex to tabId.
For `data-tab-id`, we were using tabIndex as a unique numeric incremental identifier. Having the work index in it was confusing since we have other index fields which do act like indexes.
1 parent 9e7b718 commit 33690b2

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

app/renderer/js/components/functional-tab.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default class FunctionalTab extends Tab {
4343

4444
templateHtml(): Html {
4545
return html`
46-
<div class="tab functional-tab" data-tab-id="${this.properties.tabIndex}">
46+
<div class="tab functional-tab" data-tab-id="${this.properties.tabId}">
4747
<div class="server-tab-badge close-button">
4848
<i class="material-icons">close</i>
4949
</div>

app/renderer/js/components/server-tab.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default class ServerTab extends Tab {
4747

4848
templateHtml(): Html {
4949
return html`
50-
<div class="tab" data-tab-id="${this.properties.tabIndex}">
50+
<div class="tab" data-tab-id="${this.properties.tabId}">
5151
<div class="server-tooltip" style="display:none">
5252
${this.properties.label}
5353
</div>

app/renderer/js/components/tab.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type TabProperties = {
88
$root: Element;
99
onClick: () => void;
1010
index: number;
11-
tabIndex: number;
11+
tabId: number;
1212
onHover?: () => void;
1313
onHoverOut?: () => void;
1414
materialIcon?: string;

app/renderer/js/components/webview.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type WebViewProperties = {
2222
$root: Element;
2323
rootWebContents: WebContents;
2424
index: number;
25-
tabIndex: number;
25+
tabId: number;
2626
url: string;
2727
role: TabRole;
2828
isActive: () => boolean;
@@ -48,7 +48,7 @@ export default class WebView {
4848
<span class="webview-unsupported-dismiss">×</span>
4949
</div>
5050
<webview
51-
data-tab-id="${properties.tabIndex}"
51+
data-tab-id="${properties.tabId}"
5252
src="${properties.url}"
5353
${properties.preload === undefined
5454
? html``
@@ -89,7 +89,7 @@ export default class WebView {
8989
}
9090

9191
const selector = `webview[data-tab-id="${CSS.escape(
92-
`${properties.tabIndex}`,
92+
`${properties.tabId}`,
9393
)}"]`;
9494
const webContentsId: unknown =
9595
await properties.rootWebContents.executeJavaScript(

app/renderer/js/main.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class ServerManagerView {
8686
activeTab?: ServerOrFunctionalTab;
8787
tabs: ServerOrFunctionalTab[];
8888
functionalTabs: Map<TabPage, number>;
89-
tabIndex: number;
89+
tabId: number;
9090
presetOrgs: string[];
9191
preferenceView?: PreferenceView;
9292
constructor() {
@@ -132,7 +132,7 @@ export class ServerManagerView {
132132
this.tabs = [];
133133
this.presetOrgs = [];
134134
this.functionalTabs = new Map();
135-
this.tabIndex = 0;
135+
this.tabId = 0;
136136
}
137137

138138
async init(): Promise<void> {
@@ -375,22 +375,22 @@ export class ServerManagerView {
375375
}
376376

377377
initServer(server: ServerConfig, index: number): ServerTab {
378-
const tabIndex = this.getTabIndex();
378+
const tabId = this.gettabId();
379379
const tab: ServerTab = new ServerTab({
380380
role: "server",
381381
icon: DomainUtil.iconAsUrl(server.icon),
382382
label: server.alias,
383383
$root: this.$tabsContainer,
384384
onClick: this.activateLastTab.bind(this, index),
385385
index,
386-
tabIndex,
386+
tabId,
387387
onHover: this.onHover.bind(this, index),
388388
onHoverOut: this.onHoverOut.bind(this, index),
389389
webview: WebView.create({
390390
$root: this.$webviewsContainer,
391391
rootWebContents,
392392
index,
393-
tabIndex,
393+
tabId,
394394
url: server.url,
395395
role: "server",
396396
hasPermission: (origin: string, permission: string) =>
@@ -483,9 +483,9 @@ export class ServerManagerView {
483483
this.toggleDndButton(dnd);
484484
}
485485

486-
getTabIndex(): number {
487-
const currentIndex = this.tabIndex;
488-
this.tabIndex++;
486+
gettabId(): number {
487+
const currentIndex = this.tabId;
488+
this.tabId++;
489489
return currentIndex;
490490
}
491491

@@ -574,7 +574,7 @@ export class ServerManagerView {
574574
const index = this.tabs.length;
575575
this.functionalTabs.set(tabProperties.page, index);
576576

577-
const tabIndex = this.getTabIndex();
577+
const tabId = this.gettabId();
578578
const $view = await tabProperties.makeView();
579579
this.$webviewsContainer.append($view);
580580

@@ -586,7 +586,7 @@ export class ServerManagerView {
586586
page: tabProperties.page,
587587
$root: this.$tabsContainer,
588588
index,
589-
tabIndex,
589+
tabId,
590590
onClick: this.activateTab.bind(this, index),
591591
onDestroy: async () => {
592592
await this.destroyFunctionalTab(tabProperties.page, index);
@@ -824,8 +824,8 @@ export class ServerManagerView {
824824
}
825825
}
826826

827-
async isLoggedIn(tabIndex: number): Promise<boolean> {
828-
const tab = this.tabs[tabIndex];
827+
async isLoggedIn(tabId: number): Promise<boolean> {
828+
const tab = this.tabs[tabId];
829829
if (!(tab instanceof ServerTab)) return false;
830830
const webview = await tab.webview;
831831
const url = webview.getWebContents().getURL();
@@ -1133,7 +1133,7 @@ export class ServerManagerView {
11331133
(await tab.webview).webContentsId === webviewId
11341134
) {
11351135
const concurrentTab: HTMLButtonElement = document.querySelector(
1136-
`div[data-tab-id="${CSS.escape(`${tab.properties.tabIndex}`)}"]`,
1136+
`div[data-tab-id="${CSS.escape(`${tab.properties.tabId}`)}"]`,
11371137
)!;
11381138
concurrentTab.click();
11391139
}

0 commit comments

Comments
 (0)