From fdb3b308e1ae3d6465c4d17d59f1ce26ec784c46 Mon Sep 17 00:00:00 2001 From: Zack Rauen Date: Thu, 9 Aug 2018 16:33:31 -0400 Subject: [PATCH] add bd file check for upload drop area --- client/src/modules/reactcomponents.js | 28 ++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/client/src/modules/reactcomponents.js b/client/src/modules/reactcomponents.js index 0b9e5bbe..e8d97cef 100644 --- a/client/src/modules/reactcomponents.js +++ b/client/src/modules/reactcomponents.js @@ -10,7 +10,7 @@ * LICENSE file in the root directory of this source tree. */ -import { DOM, Reflection } from 'ui'; +import { DOM, Reflection, Modals } from 'ui'; import { Utils, Filters, ClientLogger as Logger } from 'common'; import { MonkeyPatch } from './patcher'; import { WebpackModules } from './webpackmodules'; @@ -501,4 +501,30 @@ export class ReactAutoPatcher { this.UserPopout.forceUpdateAll(); } + + static async patchUploadArea() { + const selector = '.' + WebpackModules.getClassName('uploadArea'); + this.UploadArea = await ReactComponents.getComponent('UploadArea', {selector}); + + const reflect = Reflection(selector); + const stateNode = reflect.getComponentStateNode(this.UploadArea); + const callback = function(e) { + if (!e.dataTransfer.files.length || !e.dataTransfer.files[0].name.endsWith('.bd')) return; + e.preventDefault(); + e.stopPropagation(); + e.stopImmediatePropagation(); + stateNode.clearDragging(); + Modals.confirm("Function not ready", `You tried to install "${e.dataTransfer.files[0].path}", but installing .bd files isn't ready yet.`) + // Possibly something like Events.emit('install-file', e.dataTransfer.files[0]); + }; + + // Remove their handler, add ours, then readd theirs to give ours priority to stop theirs when we get a .bd file. + reflect.element.removeEventListener('drop', stateNode.handleDrop); + reflect.element.addEventListener('drop', callback); + reflect.element.addEventListener('drop', stateNode.handleDrop); + + this.unpatchUploadArea = function() { + reflect.element.removeEventListener('drop', callback); + }; + } }