cordis/client/webapp/elements/context-menu-server.ts

37 lines
1.3 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 { $, $$, $$$, $$$$, $_ } from './require/q-module';
import IState from './require/elements-state';
import ClientController from '../client-controller.js';
export default function createServerContextMenu(state: IState, server: ClientController) {
const { document, controller, ui } = state;
$.setDocument(document);
let element = BaseElements.createContextMenu(document, {
class: 'server-context', content: [
{ class: 'item red leave-server', content: 'Leave Server' }
]
});
$$$(element, '.leave-server').addEventListener('click', async () => {
element.removeSelf();
await server.disconnect();
await controller.removeServer(server);
await ui.removeServer(server);
let firstServerElement = $_('#server-list .server');
if (firstServerElement) {
firstServerElement.click();
} else {
LOG.warn('no first server element to click on');
}
});
return element;
}