Skip to content

Commit

Permalink
fixed overflow, redundant db calls, package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Aitchessbee committed Apr 14, 2024
1 parent aedab17 commit 21cfd2c
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app/renderer/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 16 additions & 8 deletions app/renderer/js/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")!;
Expand Down Expand Up @@ -125,7 +125,6 @@ export class ServerManagerView {
this.presetOrgs = [];
this.functionalTabs = new Map();
this.tabIndex = 0;
this.sortableSidebar = null;
}

async init(): Promise<void> {
Expand Down Expand Up @@ -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");
}
},
});
}
Expand Down
29 changes: 18 additions & 11 deletions app/renderer/js/utils/domain-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown>("/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();
}
}

Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 21cfd2c

Please sign in to comment.