35 lines
1.1 KiB
TypeScript
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 Q from '../q-module';
|
|
import UI from '../ui';
|
|
import GuildsManager from '../guilds-manager';
|
|
import CombinedGuild from '../guild-combined';
|
|
|
|
export default function createGuildContextMenu(document: Document, q: Q, ui: UI, guildsManager: GuildsManager, guild: CombinedGuild) {
|
|
let element = BaseElements.createContextMenu(document, {
|
|
class: 'guild-context', content: [
|
|
{ class: 'item red leave-guild', content: 'Leave Guild' }
|
|
]
|
|
});
|
|
|
|
q.$$$(element, '.leave-guild').addEventListener('click', async () => {
|
|
element.removeSelf();
|
|
guild.disconnect();
|
|
await guildsManager.removeGuild(guild);
|
|
await ui.removeGuild(guild);
|
|
let firstGuildElement = q.$_('#guild-list .guild');
|
|
if (firstGuildElement) {
|
|
firstGuildElement.click();
|
|
} else {
|
|
LOG.warn('no first guild element to click on');
|
|
}
|
|
});
|
|
|
|
return element;
|
|
}
|