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 { Channel } from '../data-types';
|
|
|
|
import BaseElements from './require/base-elements';
|
2021-11-07 16:50:30 +00:00
|
|
|
import Q from '../q-module';
|
|
|
|
import createUploadOverlayFromDataTransferItem from './overlay-upload-datatransfer';
|
2021-11-22 02:47:29 +00:00
|
|
|
import CombinedGuild from '../guild-combined';
|
2021-10-30 17:26:41 +00:00
|
|
|
|
2021-11-21 18:29:42 +00:00
|
|
|
export default function createUploadDropTarget(document: Document, q: Q, guild: CombinedGuild, channel: Channel): HTMLElement {
|
2021-11-07 16:50:30 +00:00
|
|
|
let element = BaseElements.createOverlay(document, { class: 'content drop-target', content: [
|
|
|
|
// TODO: icon?
|
|
|
|
{ class: 'message', content: 'Upload to #' + channel.name }
|
|
|
|
] });
|
|
|
|
element.addEventListener('dragover', (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
element.addEventListener('dragleave', (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
if (element.parentElement) {
|
|
|
|
element.parentElement.removeChild(element);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
element.addEventListener('drop', (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
element.parentElement?.removeChild(element);
|
|
|
|
let fileTransferItem: DataTransferItem | null = null;
|
|
|
|
for (let item of e.dataTransfer?.items ?? []) {
|
|
|
|
if (item.kind == 'file') {
|
|
|
|
e.preventDefault(); // don't continue the paste
|
|
|
|
fileTransferItem = item;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fileTransferItem) {
|
2021-11-22 02:47:29 +00:00
|
|
|
let element = createUploadOverlayFromDataTransferItem(document, guild, channel, fileTransferItem);
|
2021-11-07 16:50:30 +00:00
|
|
|
document.body.appendChild(element);
|
|
|
|
q.$$$(element, '.text-input').focus();
|
|
|
|
} else {
|
|
|
|
LOG.debug('dropped non-file');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return element;
|
2021-10-30 17:26:41 +00:00
|
|
|
}
|