@@ -6,6 +6,7 @@ import url from "node:url";
66import { Menu , app , dialog , session } from "@electron/remote" ;
77import * as remote from "@electron/remote" ;
88import * as Sentry from "@sentry/electron/renderer" ;
9+ import SortableJS from "sortablejs" ;
910
1011import type { Config } from "../../common/config-util.js" ;
1112import * as ConfigUtil from "../../common/config-util.js" ;
@@ -57,7 +58,7 @@ const dingSound = new Audio(
5758
5859export 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
0 commit comments