Skip to content

Commit 64e827a

Browse files
committed
fixed overflow, redundant db calls, package.json
1 parent aedab17 commit 64e827a

File tree

5 files changed

+40
-26
lines changed

5 files changed

+40
-26
lines changed

app/renderer/css/main.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ body {
4545
#view-controls-container {
4646
height: calc(100% - 208px);
4747
scrollbar-gutter: stable both-edges;
48-
overflow-y: hidden;
48+
overflow: hidden;
4949
}
5050

5151
#view-controls-container::-webkit-scrollbar {

app/renderer/js/main.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class ServerManagerView {
8282
tabIndex: number;
8383
presetOrgs: string[];
8484
preferenceView?: PreferenceView;
85-
sortableSidebar: SortableJS | null;
85+
sortableSidebar?: SortableJS;
8686
constructor() {
8787
this.$addServerButton = document.querySelector("#add-tab")!;
8888
this.$tabsContainer = document.querySelector("#tabs-container")!;
@@ -125,7 +125,6 @@ export class ServerManagerView {
125125
this.presetOrgs = [];
126126
this.functionalTabs = new Map();
127127
this.tabIndex = 0;
128-
this.sortableSidebar = null;
129128
}
130129

131130
async init(): Promise<void> {
@@ -242,14 +241,23 @@ export class ServerManagerView {
242241
animation: 150,
243242
onEnd: (event: SortableJS.SortableEvent) => {
244243
// Update the domain order in the database
245-
DomainUtil.updateDomainOrder(event.oldIndex ?? 0, event.newIndex ?? 0);
244+
if (
245+
event.oldIndex !== null &&
246+
event.newIndex !== null &&
247+
event.oldIndex !== event.newIndex
248+
) {
249+
DomainUtil.updateDomainOrder(
250+
event.oldIndex ?? 0,
251+
event.newIndex ?? 0,
252+
);
246253

247-
// Update the current active tab index
248-
this.activeTabIndex = event.newIndex ?? 0;
249-
ConfigUtil.setConfigItem("lastActiveTab", event.newIndex ?? 0);
254+
// Update the current active tab index
255+
this.activeTabIndex = event.newIndex ?? 0;
256+
ConfigUtil.setConfigItem("lastActiveTab", event.newIndex ?? 0);
250257

251-
// Reload the app to give the tabs their new indexes
252-
ipcRenderer.send("reload-full-app");
258+
// Reload the app to give the tabs their new indexes
259+
ipcRenderer.send("reload-full-app");
260+
}
253261
},
254262
});
255263
}

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

+17-11
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,23 @@ 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);
75+
export function updateDomainOrder(oldIndex: number, newIndex: number): void {
76+
const domains = getDomains();
77+
78+
if (
79+
!(
80+
oldIndex < 0 ||
81+
oldIndex >= domains.length ||
82+
newIndex < 0 ||
83+
newIndex >= domains.length
84+
)
85+
) {
86+
const [movedDomain] = domains.splice(oldIndex, 1);
87+
domains.splice(newIndex, 0, movedDomain);
88+
89+
for (const [index, domain] of domains.entries()) {
90+
updateDomain(index, domain);
91+
}
8692
}
8793
}
8894

package-lock.json

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

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,7 @@
143143
"InstantMessaging"
144144
],
145145
"dependencies": {
146-
"@types/sortablejs": "^1.15.8",
147-
"gatemaker": "https://github.com/andersk/gatemaker/archive/d31890ae1cb293faabcb1e4e465c673458f6eed2.tar.gz",
148-
"sortablejs": "^1.15.2"
146+
"gatemaker": "https://github.com/andersk/gatemaker/archive/d31890ae1cb293faabcb1e4e465c673458f6eed2.tar.gz"
149147
},
150148
"devDependencies": {
151149
"@electron/remote": "^2.0.8",
@@ -157,6 +155,7 @@
157155
"@types/i18n": "^0.13.1",
158156
"@types/node": "~18.17.19",
159157
"@types/requestidlecallback": "^0.3.4",
158+
"@types/sortablejs": "^1.15.8",
160159
"@types/yaireo__tagify": "^4.3.2",
161160
"@yaireo/tagify": "^4.5.0",
162161
"adm-zip": "^0.5.5",
@@ -178,6 +177,7 @@
178177
"prettier": "^3.0.3",
179178
"rimraf": "^5.0.0",
180179
"semver": "^7.3.5",
180+
"sortablejs": "^1.15.2",
181181
"stylelint": "^16.1.0",
182182
"stylelint-config-standard": "^36.0.0",
183183
"tape": "^5.2.2",

0 commit comments

Comments
 (0)