-
-
Notifications
You must be signed in to change notification settings - Fork 453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Left sidebar: Added ordering feature for server tabs #1359
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import url from "node:url"; | |
import {Menu, app, dialog, session} from "@electron/remote"; | ||
import * as remote from "@electron/remote"; | ||
import * as Sentry from "@sentry/electron/renderer"; | ||
import SortableJS from "sortablejs"; | ||
|
||
import type {Config} from "../../common/config-util.js"; | ||
import * as ConfigUtil from "../../common/config-util.js"; | ||
|
@@ -57,7 +58,7 @@ const dingSound = new Audio( | |
|
||
export class ServerManagerView { | ||
$addServerButton: HTMLButtonElement; | ||
$tabsContainer: Element; | ||
$tabsContainer: HTMLElement; | ||
$reloadButton: HTMLButtonElement; | ||
$loadingIndicator: HTMLButtonElement; | ||
$settingsButton: HTMLButtonElement; | ||
|
@@ -81,6 +82,7 @@ export class ServerManagerView { | |
tabIndex: number; | ||
presetOrgs: string[]; | ||
preferenceView?: PreferenceView; | ||
sortableSidebar: SortableJS | null; | ||
constructor() { | ||
this.$addServerButton = document.querySelector("#add-tab")!; | ||
this.$tabsContainer = document.querySelector("#tabs-container")!; | ||
|
@@ -123,6 +125,7 @@ export class ServerManagerView { | |
this.presetOrgs = []; | ||
this.functionalTabs = new Map(); | ||
this.tabIndex = 0; | ||
this.sortableSidebar = null; | ||
} | ||
|
||
async init(): Promise<void> { | ||
|
@@ -235,6 +238,20 @@ export class ServerManagerView { | |
initSidebar(): void { | ||
const showSidebar = ConfigUtil.getConfigItem("showSidebar", true); | ||
this.toggleSidebar(showSidebar); | ||
this.sortableSidebar = new SortableJS(this.$tabsContainer, { | ||
animation: 150, | ||
onEnd: (event: SortableJS.SortableEvent) => { | ||
// Update the domain order in the database | ||
DomainUtil.updateDomainOrder(event.oldIndex ?? 0, event.newIndex ?? 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unexpected data should be rejected and ignored, not silently replaced with fake values like |
||
|
||
// Update the current active tab index | ||
this.activeTabIndex = event.newIndex ?? 0; | ||
ConfigUtil.setConfigItem("lastActiveTab", event.newIndex ?? 0); | ||
|
||
// Reload the app to give the tabs their new indexes | ||
ipcRenderer.send("reload-full-app"); | ||
}, | ||
}); | ||
} | ||
|
||
// Remove the stale UA string from the disk if the app is not freshly | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,20 @@ export function updateDomain(index: number, server: ServerConf): void { | |
db.push(`/domains[${index}]`, server, true); | ||
} | ||
|
||
export function updateDomainOrder(oldIndex: number, newIndex: number) { | ||
const domains = serverConfSchema | ||
.array() | ||
.parse(db.getObject<unknown>("/domains")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use |
||
|
||
const [movedDomain] = domains.splice(oldIndex, 1); | ||
domains.splice(newIndex, 0, movedDomain); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the database is out of sync (e.g. it has been manually edited), it’s possible for |
||
|
||
// Update each domain in the database with its new order | ||
for (const [index, domain] of domains.entries()) { | ||
updateDomain(index, domain); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do this in a single |
||
} | ||
|
||
export async function addDomain(server: { | ||
url: string; | ||
alias: string; | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,7 +143,9 @@ | |
"InstantMessaging" | ||
], | ||
"dependencies": { | ||
"gatemaker": "https://github.com/andersk/gatemaker/archive/d31890ae1cb293faabcb1e4e465c673458f6eed2.tar.gz" | ||
"@types/sortablejs": "^1.15.8", | ||
"gatemaker": "https://github.com/andersk/gatemaker/archive/d31890ae1cb293faabcb1e4e465c673458f6eed2.tar.gz", | ||
"sortablejs": "^1.15.2" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}, | ||
"devDependencies": { | ||
"@electron/remote": "^2.0.8", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to avoid explicitly assigning
null
.