Skip to content

Commit aedab17

Browse files
committed
left sidebar: added ordering feature for server tabs, fixes #548
1 parent af7272a commit aedab17

File tree

5 files changed

+52
-3
lines changed

5 files changed

+52
-3
lines changed

app/renderer/css/main.css

+4
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,10 @@ webview.focus {
419419
left: -5px;
420420
}
421421

422+
.sortable-chosen .server-tooltip {
423+
display: none;
424+
}
425+
422426
#collapse-button {
423427
bottom: 30px;
424428
left: 20px;

app/renderer/js/main.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import url from "node:url";
66
import {Menu, app, dialog, session} from "@electron/remote";
77
import * as remote from "@electron/remote";
88
import * as Sentry from "@sentry/electron/renderer";
9+
import SortableJS from "sortablejs";
910

1011
import type {Config} from "../../common/config-util.js";
1112
import * as ConfigUtil from "../../common/config-util.js";
@@ -57,7 +58,7 @@ const dingSound = new Audio(
5758

5859
export class ServerManagerView {
5960
$addServerButton: HTMLButtonElement;
60-
$tabsContainer: Element;
61+
$tabsContainer: HTMLElement;
6162
$reloadButton: HTMLButtonElement;
6263
$loadingIndicator: HTMLButtonElement;
6364
$settingsButton: HTMLButtonElement;
@@ -81,6 +82,7 @@ export class ServerManagerView {
8182
tabIndex: number;
8283
presetOrgs: string[];
8384
preferenceView?: PreferenceView;
85+
sortableSidebar: SortableJS | null;
8486
constructor() {
8587
this.$addServerButton = document.querySelector("#add-tab")!;
8688
this.$tabsContainer = document.querySelector("#tabs-container")!;
@@ -123,6 +125,7 @@ export class ServerManagerView {
123125
this.presetOrgs = [];
124126
this.functionalTabs = new Map();
125127
this.tabIndex = 0;
128+
this.sortableSidebar = null;
126129
}
127130

128131
async init(): Promise<void> {
@@ -235,6 +238,20 @@ export class ServerManagerView {
235238
initSidebar(): void {
236239
const showSidebar = ConfigUtil.getConfigItem("showSidebar", true);
237240
this.toggleSidebar(showSidebar);
241+
this.sortableSidebar = new SortableJS(this.$tabsContainer, {
242+
animation: 150,
243+
onEnd: (event: SortableJS.SortableEvent) => {
244+
// Update the domain order in the database
245+
DomainUtil.updateDomainOrder(event.oldIndex ?? 0, event.newIndex ?? 0);
246+
247+
// Update the current active tab index
248+
this.activeTabIndex = event.newIndex ?? 0;
249+
ConfigUtil.setConfigItem("lastActiveTab", event.newIndex ?? 0);
250+
251+
// Reload the app to give the tabs their new indexes
252+
ipcRenderer.send("reload-full-app");
253+
},
254+
});
238255
}
239256

240257
// Remove the stale UA string from the disk if the app is not freshly

app/renderer/js/utils/domain-util.ts

+14
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ export function updateDomain(index: number, server: ServerConf): void {
7272
db.push(`/domains[${index}]`, server, true);
7373
}
7474

75+
export function updateDomainOrder(oldIndex: number, newIndex: number) {
76+
const domains = serverConfSchema
77+
.array()
78+
.parse(db.getObject<unknown>("/domains"));
79+
80+
const [movedDomain] = domains.splice(oldIndex, 1);
81+
domains.splice(newIndex, 0, movedDomain);
82+
83+
// Update each domain in the database with its new order
84+
for (const [index, domain] of domains.entries()) {
85+
updateDomain(index, domain);
86+
}
87+
}
88+
7589
export async function addDomain(server: {
7690
url: string;
7791
alias: string;

package-lock.json

+13-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@
143143
"InstantMessaging"
144144
],
145145
"dependencies": {
146-
"gatemaker": "https://github.com/andersk/gatemaker/archive/d31890ae1cb293faabcb1e4e465c673458f6eed2.tar.gz"
146+
"@types/sortablejs": "^1.15.8",
147+
"gatemaker": "https://github.com/andersk/gatemaker/archive/d31890ae1cb293faabcb1e4e465c673458f6eed2.tar.gz",
148+
"sortablejs": "^1.15.2"
147149
},
148150
"devDependencies": {
149151
"@electron/remote": "^2.0.8",

0 commit comments

Comments
 (0)