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

35 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-10-30 17:26:41 +00:00
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../logger/logger';
2021-11-02 04:29:24 +00:00
const LOG = Logger.create(__filename, electronConsole);
2021-10-30 17:26:41 +00:00
import BaseElements from './require/base-elements.js';
import Q from '../q-module';
import UI from '../ui';
2021-11-22 02:47:29 +00:00
import GuildsManager from '../guilds-manager';
import CombinedGuild from '../guild-combined';
2021-10-30 17:26:41 +00:00
2021-11-22 02:47:29 +00:00
export default function createServerContextMenu(document: Document, q: Q, ui: UI, guildsManager: GuildsManager, guild: CombinedGuild) {
let element = BaseElements.createContextMenu(document, {
class: 'server-context', content: [
{ class: 'item red leave-server', content: 'Leave Server' }
]
});
2021-10-30 17:26:41 +00:00
q.$$$(element, '.leave-server').addEventListener('click', async () => {
element.removeSelf();
2021-11-22 02:47:29 +00:00
guild.disconnect();
await guildsManager.removeServer(guild);
await ui.removeGuild(guild);
let firstServerElement = q.$_('#server-list .server');
if (firstServerElement) {
firstServerElement.click();
} else {
LOG.warn('no first server element to click on');
}
});
2021-10-30 17:26:41 +00:00
return element;
2021-10-30 17:26:41 +00:00
}