From 21cfd2cd36dcb772772caf5284d5a424e7f957d5 Mon Sep 17 00:00:00 2001 From: Aitchessbee Date: Mon, 25 Mar 2024 00:51:27 +0530 Subject: [PATCH] fixed overflow, redundant db calls, package.json --- app/renderer/css/main.css | 2 +- app/renderer/js/main.ts | 24 +++++++++++++++-------- app/renderer/js/utils/domain-util.ts | 29 +++++++++++++++++----------- package-lock.json | 6 +++--- package.json | 6 +++--- 5 files changed, 41 insertions(+), 26 deletions(-) diff --git a/app/renderer/css/main.css b/app/renderer/css/main.css index 6b9b5aa50..02cd873cb 100644 --- a/app/renderer/css/main.css +++ b/app/renderer/css/main.css @@ -45,7 +45,7 @@ body { #view-controls-container { height: calc(100% - 208px); scrollbar-gutter: stable both-edges; - overflow-y: hidden; + overflow: hidden; } #view-controls-container::-webkit-scrollbar { diff --git a/app/renderer/js/main.ts b/app/renderer/js/main.ts index ff0cdffe2..2c32a1ae6 100644 --- a/app/renderer/js/main.ts +++ b/app/renderer/js/main.ts @@ -82,7 +82,7 @@ export class ServerManagerView { tabIndex: number; presetOrgs: string[]; preferenceView?: PreferenceView; - sortableSidebar: SortableJS | null; + sortableSidebar?: SortableJS; constructor() { this.$addServerButton = document.querySelector("#add-tab")!; this.$tabsContainer = document.querySelector("#tabs-container")!; @@ -125,7 +125,6 @@ export class ServerManagerView { this.presetOrgs = []; this.functionalTabs = new Map(); this.tabIndex = 0; - this.sortableSidebar = null; } async init(): Promise { @@ -242,14 +241,23 @@ export class ServerManagerView { animation: 150, onEnd: (event: SortableJS.SortableEvent) => { // Update the domain order in the database - DomainUtil.updateDomainOrder(event.oldIndex ?? 0, event.newIndex ?? 0); + if ( + event.oldIndex !== null && + event.newIndex !== null && + event.oldIndex !== event.newIndex + ) { + DomainUtil.updateDomainOrder( + event.oldIndex ?? 0, + event.newIndex ?? 0, + ); - // Update the current active tab index - this.activeTabIndex = event.newIndex ?? 0; - ConfigUtil.setConfigItem("lastActiveTab", event.newIndex ?? 0); + // 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"); + // Reload the app to give the tabs their new indexes + ipcRenderer.send("reload-full-app"); + } }, }); } diff --git a/app/renderer/js/utils/domain-util.ts b/app/renderer/js/utils/domain-util.ts index bdded99a4..d0a91877f 100644 --- a/app/renderer/js/utils/domain-util.ts +++ b/app/renderer/js/utils/domain-util.ts @@ -72,17 +72,24 @@ 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("/domains")); - - const [movedDomain] = domains.splice(oldIndex, 1); - domains.splice(newIndex, 0, movedDomain); - - // Update each domain in the database with its new order - for (const [index, domain] of domains.entries()) { - updateDomain(index, domain); +export function updateDomainOrder(oldIndex: number, newIndex: number): void { + const domains = getDomains(); + + if ( + !( + oldIndex < 0 || + oldIndex >= domains.length || + newIndex < 0 || + newIndex >= domains.length + ) + ) { + const [movedDomain] = domains.splice(oldIndex, 1); + domains.splice(newIndex, 0, movedDomain); + + serverConfSchema.array().parse(domains); + + db.push("/domains", domains, true); + reloadDb(); } } diff --git a/package-lock.json b/package-lock.json index fc714eb5a..14e219b9b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,9 +10,7 @@ "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { - "@types/sortablejs": "^1.15.8", - "gatemaker": "https://github.com/andersk/gatemaker/archive/d31890ae1cb293faabcb1e4e465c673458f6eed2.tar.gz", - "sortablejs": "^1.15.2" + "gatemaker": "https://github.com/andersk/gatemaker/archive/d31890ae1cb293faabcb1e4e465c673458f6eed2.tar.gz" }, "devDependencies": { "@electron/remote": "^2.0.8", @@ -24,6 +22,7 @@ "@types/i18n": "^0.13.1", "@types/node": "~18.17.19", "@types/requestidlecallback": "^0.3.4", + "@types/sortablejs": "^1.15.8", "@types/yaireo__tagify": "^4.3.2", "@yaireo/tagify": "^4.5.0", "adm-zip": "^0.5.5", @@ -45,6 +44,7 @@ "prettier": "^3.0.3", "rimraf": "^5.0.0", "semver": "^7.3.5", + "sortablejs": "^1.15.2", "stylelint": "^16.1.0", "stylelint-config-standard": "^36.0.0", "tape": "^5.2.2", diff --git a/package.json b/package.json index 214150d65..37a18ab5d 100644 --- a/package.json +++ b/package.json @@ -143,9 +143,7 @@ "InstantMessaging" ], "dependencies": { - "@types/sortablejs": "^1.15.8", - "gatemaker": "https://github.com/andersk/gatemaker/archive/d31890ae1cb293faabcb1e4e465c673458f6eed2.tar.gz", - "sortablejs": "^1.15.2" + "gatemaker": "https://github.com/andersk/gatemaker/archive/d31890ae1cb293faabcb1e4e465c673458f6eed2.tar.gz" }, "devDependencies": { "@electron/remote": "^2.0.8", @@ -157,6 +155,7 @@ "@types/i18n": "^0.13.1", "@types/node": "~18.17.19", "@types/requestidlecallback": "^0.3.4", + "@types/sortablejs": "^1.15.8", "@types/yaireo__tagify": "^4.3.2", "@yaireo/tagify": "^4.5.0", "adm-zip": "^0.5.5", @@ -178,6 +177,7 @@ "prettier": "^3.0.3", "rimraf": "^5.0.0", "semver": "^7.3.5", + "sortablejs": "^1.15.2", "stylelint": "^16.1.0", "stylelint-config-standard": "^36.0.0", "tape": "^5.2.2",