cordis/client/webapp/elements/context-menu-srv.ts
2021-11-21 12:29:42 -06:00

35 lines
1.1 KiB
TypeScript

import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../logger/logger';
const LOG = Logger.create(__filename, electronConsole);
import BaseElements from './require/base-elements.js';
import ClientController from '../client-controller.js';
import Q from '../q-module';
import UI from '../ui';
import Controller from '../controller';
export default function createServerContextMenu(document: Document, q: Q, ui: UI, controller: Controller, guild: CombinedGuild) {
let element = BaseElements.createContextMenu(document, {
class: 'server-context', content: [
{ class: 'item red leave-server', content: 'Leave Server' }
]
});
q.$$$(element, '.leave-server').addEventListener('click', async () => {
element.removeSelf();
await server.disconnect();
await controller.removeServer(server);
await ui.removeServer(server);
let firstServerElement = q.$_('#server-list .server');
if (firstServerElement) {
firstServerElement.click();
} else {
LOG.warn('no first server element to click on');
}
});
return element;
}