Skip to content

Commit 875e22d

Browse files
committed
added ordering feature for server tabs
1 parent af7272a commit 875e22d

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
@@ -145,6 +145,10 @@ body {
145145
color: rgb(108 133 146 / 100%);
146146
}
147147

148+
.sortable-chosen .server-tooltip {
149+
display: none;
150+
}
151+
148152
.tab {
149153
position: relative;
150154
margin: 2px 0;

app/renderer/js/main.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {initializeTray} from "./tray.js";
2828
import {ipcRenderer} from "./typed-ipc-renderer.js";
2929
import * as DomainUtil from "./utils/domain-util.js";
3030
import ReconnectUtil from "./utils/reconnect-util.js";
31+
import Sortable from "sortablejs";
3132

3233
Sentry.init({});
3334

@@ -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: Sortable | 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 Sortable(this.$tabsContainer, {
242+
animation: 150,
243+
onEnd: (event: Sortable.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+
let 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+
domains.forEach((domain, index) => {
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)