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

Make org tabs draggable in sidebar #617

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@
"node-json-db": "0.9.2",
"request": "2.85.0",
"semver": "5.4.1",
"sortablejs": "1.10.0-rc3",
"wurl": "2.5.0"
},
"optionalDependencies": {
"node-mac-notifier": "1.1.0"
}
}
}
42 changes: 34 additions & 8 deletions app/renderer/js/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

import { ipcRenderer, remote, clipboard, shell } from 'electron';
import Sortable from 'sortablejs';
import { feedbackHolder } from './feedback';

import path = require('path');
Expand Down Expand Up @@ -79,6 +80,7 @@ class ServerManagerView {
$settingsButton: HTMLButtonElement;
$webviewsContainer: Element;
$backButton: HTMLButtonElement;
$orgsList: HTMLElement;
$dndButton: HTMLButtonElement;
$addServerTooltip: HTMLElement;
$reloadTooltip: HTMLElement;
Expand All @@ -90,8 +92,10 @@ class ServerManagerView {
$sidebar: Element;
$fullscreenPopup: Element;
$fullscreenEscapeKey: string;
$sortableList: any;
loading: AnyObject;
activeTabIndex: number;
servers: Domain[];
tabs: ServerOrFunctionalTab[];
functionalTabs: AnyObject;
tabIndex: number;
Expand Down Expand Up @@ -123,6 +127,7 @@ class ServerManagerView {
this.$dndTooltip = $actionsContainer.querySelector('#dnd-tooltip');

this.$sidebar = document.querySelector('#sidebar');
this.$orgsList = document.querySelector('#tabs-container');

this.$fullscreenPopup = document.querySelector('#fullscreen-popup');
this.$fullscreenEscapeKey = process.platform === 'darwin' ? '^⌘F' : 'F11';
Expand All @@ -131,6 +136,7 @@ class ServerManagerView {
this.loading = {};
this.activeTabIndex = -1;
this.tabs = [];
this.servers = DomainUtil.getDomains();
this.presetOrgs = [];
this.functionalTabs = {};
this.tabIndex = 0;
Expand Down Expand Up @@ -237,9 +243,27 @@ class ServerManagerView {
}
}

onEnd(): void {
const newServers: Domain[] = [];
const tabElements = document.querySelectorAll('#tabs-container .tab');
tabElements.forEach((el, index) => {
const oldIndex = Number(el.getAttribute('data-tab-id')) % this.servers.length;
newServers.push(this.servers[oldIndex]);
// TODO: Change this to read data from in-memory store or DomainUtil.
el.setAttribute('data-tab-id', index.toString());
});
this.servers = newServers;
DomainUtil.batchUpdateDomain(this.servers);
this.reloadView(false);
}

initSidebar(): void {
const showSidebar = ConfigUtil.getConfigItem('showSidebar', true);
this.toggleSidebar(showSidebar);
this.$sortableList = Sortable.create(this.$orgsList, {
dataIdattr: 'data-sortable-id',
onEnd: this.onEnd.bind(this)
});
}

async queueDomain(domain: any): Promise<boolean> {
Expand Down Expand Up @@ -307,12 +331,14 @@ class ServerManagerView {
}
}

initTabs(): void {
const servers = DomainUtil.getDomains();
if (servers.length > 0) {
for (let i = 0; i < servers.length; i++) {
this.initServer(servers[i], i);
DomainUtil.updateSavedServer(servers[i].url, i);
initTabs(refresh: boolean = true): void {
if (refresh) {
this.servers = DomainUtil.getDomains();
}
if (this.servers.length > 0) {
for (let i = 0; i < this.servers.length; i++) {
this.initServer(this.servers[i], i);
DomainUtil.updateSavedServer(this.servers[i].url, i);
this.activateTab(i);
}
// Open last active tab
Expand Down Expand Up @@ -666,14 +692,14 @@ class ServerManagerView {
this.$webviewsContainer.innerHTML = '';
}

reloadView(): void {
reloadView(refresh: boolean = true): void {
// Save and remember the index of last active tab so that we can use it later
const lastActiveTab = this.tabs[this.activeTabIndex].props.index;
ConfigUtil.setConfigItem('lastActiveTab', lastActiveTab);

// Destroy the current view and re-initiate it
this.destroyView();
this.initTabs();
this.initTabs(refresh);
this.initServerActions();
}

Expand Down
7 changes: 7 additions & 0 deletions app/renderer/js/utils/domain-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ class DomainUtil {
this.db.push(`/domains[${index}]`, server, true);
}

batchUpdateDomain(servers: Domain[]): void {
this.db.delete('/domains');
for (const server of servers) {
this.db.push('/domains[]', server, true);
}
}

addDomain(server: any): Promise<void> {
const { ignoreCerts } = server;
return new Promise(resolve => {
Expand Down
8 changes: 8 additions & 0 deletions typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ declare module 'escape-html';
declare module 'fs-extra';
declare module 'wurl';
declare module 'i18n';
declare module 'sortablejs';

interface PageParamsObject {
realm_uri: string;
Expand Down Expand Up @@ -53,3 +54,10 @@ interface ZulipWebWindow extends Window {
$: any;
lightbox: any;
}

interface Domain {
icon: string;
url: string;
alias: string;
ignoreCerts: boolean;
}