2021-11-07 23:13:40 +00:00
|
|
|
import ElementsUtil from './require/elements-util';
|
|
|
|
import BaseElements from './require/base-elements';
|
2021-10-30 17:26:41 +00:00
|
|
|
import ClientController from '../client-controller';
|
|
|
|
import { Channel } from '../data-types';
|
2021-11-07 23:13:40 +00:00
|
|
|
import createModifyChannelOverlay from './overlay-modify-channel';
|
|
|
|
import UI from '../ui';
|
|
|
|
import Actions from '../actions';
|
|
|
|
import Q from '../q-module';
|
2021-11-07 16:50:30 +00:00
|
|
|
|
2021-11-21 18:29:42 +00:00
|
|
|
export default function createChannel(document: Document, q: Q, ui: UI, guild: CombinedGuild, channel: Channel) {
|
2021-11-07 16:50:30 +00:00
|
|
|
let element = q.create({ class: 'channel text', 'meta-id': channel.id, 'meta-server-id': server.id, content: [
|
|
|
|
// Scraped directly from discord (#)
|
|
|
|
{ class: 'icon', content: BaseElements.TEXT_CHANNEL_ICON },
|
|
|
|
{ class: 'name', content: channel.name },
|
|
|
|
{ class: 'modify', content: BaseElements.COG }
|
|
|
|
] }) as HTMLElement;
|
|
|
|
|
|
|
|
element.addEventListener('click', async () => {
|
|
|
|
if (element.classList.contains('active')) return;
|
|
|
|
await ui.setActiveChannel(server, channel);
|
2021-11-07 23:13:40 +00:00
|
|
|
await Actions.fetchAndUpdateMessagesRecent(q, ui, server, channel);
|
2021-11-07 16:50:30 +00:00
|
|
|
q.$('#text-input').focus();
|
|
|
|
});
|
|
|
|
|
|
|
|
let modifyContextElement = q.create({ class: 'context', content: {
|
|
|
|
class: 'above', content: [
|
|
|
|
{ class: 'content text', content: 'Modify Channel' },
|
|
|
|
{ class: 'tab', content: BaseElements.TAB_BELOW }
|
|
|
|
]
|
|
|
|
}}) as HTMLElement;
|
|
|
|
|
|
|
|
q.$$$(element, '.modify').addEventListener('click', async (e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
if (modifyContextElement.parentElement) {
|
|
|
|
modifyContextElement.parentElement.removeChild(modifyContextElement);
|
|
|
|
}
|
|
|
|
let modifyOverlay = createModifyChannelOverlay(document, q, server, channel);
|
|
|
|
document.body.appendChild(modifyOverlay);
|
|
|
|
q.$$$(modifyOverlay, '.text-input.channel-name').focus();
|
|
|
|
ElementsUtil.setCursorToEnd(q.$$$(modifyOverlay, '.text-input.channel-name'));
|
|
|
|
});
|
|
|
|
|
|
|
|
q.$$$(element, '.modify').addEventListener('mouseenter', () => {
|
|
|
|
document.body.appendChild(modifyContextElement);
|
|
|
|
ElementsUtil.alignContextElement(modifyContextElement, q.$$$(element, '.modify'), { bottom: 'top', centerX: 'centerX' });
|
|
|
|
});
|
|
|
|
|
|
|
|
q.$$$(element, '.modify').addEventListener('mouseleave', () => {
|
|
|
|
if (modifyContextElement.parentElement) {
|
|
|
|
modifyContextElement.parentElement.removeChild(modifyContextElement);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return element;
|
2021-10-30 17:26:41 +00:00
|
|
|
}
|