Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/renderer/css/main.css
Original file line number Diff line number Diff line change
@@ -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 {
@@ -419,6 +419,10 @@ webview.focus {
left: -5px;
}

.sortable-chosen .server-tooltip {
display: none;
}

#collapse-button {
bottom: 30px;
left: 20px;
27 changes: 26 additions & 1 deletion app/renderer/js/main.ts
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;
constructor() {
this.$addServerButton = document.querySelector("#add-tab")!;
this.$tabsContainer = document.querySelector("#tabs-container")!;
@@ -235,6 +237,29 @@ 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
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);

// 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
20 changes: 20 additions & 0 deletions app/renderer/js/utils/domain-util.ts
Original file line number Diff line number Diff line change
@@ -72,6 +72,26 @@ export function updateDomain(index: number, server: ServerConf): void {
db.push(`/domains[${index}]`, server, true);
}

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);

for (const [index, domain] of domains.entries()) {
updateDomain(index, domain);
}
}
}

export async function addDomain(server: {
url: string;
alias: string;
12 changes: 12 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -155,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",
@@ -176,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",