cordis/client/webapp/elements/channel.ts

56 lines
2.2 KiB
TypeScript
Raw Normal View History

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 { 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-22 02:47:29 +00:00
import CombinedGuild from '../guild-combined';
2021-11-21 18:29:42 +00:00
export default function createChannel(document: Document, q: Q, ui: UI, guild: CombinedGuild, channel: Channel) {
2021-11-22 02:47:29 +00:00
let element = q.create({ class: 'channel text', 'meta-id': channel.id, 'meta-server-id': guild.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;
2021-11-22 02:47:29 +00:00
await ui.setActiveChannel(guild, channel);
await Actions.fetchAndUpdateMessagesRecent(q, ui, guild, channel);
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);
}
2021-11-22 02:47:29 +00:00
let modifyOverlay = createModifyChannelOverlay(document, q, guild, 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
}