~emersion/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
3 3

[PATCH gamja 0/1] components/composer: handle drag and drop file upload

Details
Message ID
<172072727742.23379.4164621456049926293-0@git.sr.ht>
DKIM signature
missing
Download raw message
Not happy with handleDragOver: https://jsfiddle.net/760gLx1s/

xse (1):
  components/composer: handle drag and drop file upload

 components/composer.js | 51 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 44 insertions(+), 7 deletions(-)

-- 
2.43.4

[PATCH gamja 1/1] components/composer: handle drag and drop file upload

Details
Message ID
<172072727742.23379.4164621456049926293-1@git.sr.ht>
In-Reply-To
<172072727742.23379.4164621456049926293-0@git.sr.ht> (view parent)
DKIM signature
missing
Download raw message
Patch: +44 -7
From: xse <xse@krkrkr.org>

---
 components/composer.js | 51 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 44 insertions(+), 7 deletions(-)

diff --git a/components/composer.js b/components/composer.js
index eaa5659..7541903 100644
--- a/components/composer.js
+++ b/components/composer.js
@@ -24,7 +24,9 @@ export default class Composer extends Component {
		this.handleInput = this.handleInput.bind(this);
		this.handleSubmit = this.handleSubmit.bind(this);
		this.handleInputKeyDown = this.handleInputKeyDown.bind(this);
		this.handleFilesUpload = this.handleFilesUpload.bind(this);
		this.handleInputPaste = this.handleInputPaste.bind(this);
		this.handleDrop = this.handleDrop.bind(this);
		this.handleWindowKeyDown = this.handleWindowKeyDown.bind(this);
		this.handleWindowPaste = this.handleWindowPaste.bind(this);
	}
@@ -128,9 +130,9 @@ export default class Composer extends Component {
		this.setState({ text: autocomplete.text });
	}

	async handleInputPaste(event) {
	async handleFilesUpload(fileList) {
		let client = this.props.client;
		if (!event.clipboardData.files.length || !client || this.props.readOnly) {
		if (!client || this.props.readOnly) {
			return;
		}

@@ -139,11 +141,8 @@ export default class Composer extends Component {
			return;
		}

		event.preventDefault();
		event.stopImmediatePropagation();

		// TODO: support more than one file
		let file = event.clipboardData.files.item(0);
		let file = fileList.item(0);

		let auth;
		if (client.params.saslPlain) {
@@ -182,7 +181,43 @@ export default class Composer extends Component {
			throw new Error("filehost response missing Location header field");
		}

		let uploadURL = new URL(loc, endpoint);
		return new URL(loc, endpoint);
	}

	async handleInputPaste(event) {
		if (!event.clipboardData.files.length) {
			return;
		}

		event.preventDefault();
		event.stopImmediatePropagation();

		let uploadURL = await this.handleFilesUpload(event.clipboardData.files);

		this.setState((state) => {
			if (state.text) {
				return { text: state.text + " " + uploadURL.toString() };
			} else {
				return { text: uploadURL.toString() };
			}
		});
	}

	handleDragOver(event) {
		if (!([...event.dataTransfer.items].some(x=>x.type==='text/plain') && [...event.dataTransfer.items].some(x=>x.type==='text/html'))) {
			event.preventDefault();
		}
	}

	async handleDrop(event) {
		if (!event.dataTransfer.files.length) {
			return;
		}

		event.preventDefault();
		event.stopImmediatePropagation();

		let uploadURL = await this.handleFilesUpload(event.dataTransfer.files);

		this.setState((state) => {
			if (state.text) {
@@ -311,6 +346,8 @@ export default class Composer extends Component {
					enterkeyhint="send"
					onKeyDown=${this.handleInputKeyDown}
					onPaste=${this.handleInputPaste}
					onDragOver=${this.handleDragOver}
					onDrop=${this.handleDrop}
					maxlength=${this.props.maxLen}
				/>
			</form>
-- 
2.43.4

[gamja/patches/.build.yml] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<D2MYX5G82YDW.19H2HQMIQ3KMI@fra02>
In-Reply-To
<172072727742.23379.4164621456049926293-1@git.sr.ht> (view parent)
DKIM signature
missing
Download raw message
gamja/patches/.build.yml: SUCCESS in 22s

[components/composer: handle drag and drop file upload][0] from [~xse][1]

[0]: https://lists.sr.ht/~emersion/public-inbox/patches/53815
[1]: xse@krkrkr.org

✓ #1273942 SUCCESS gamja/patches/.build.yml https://builds.sr.ht/~emersion/job/1273942

Re: [PATCH gamja 0/1] components/composer: handle drag and drop file upload

Details
Message ID
<o800psMjJJYayxwqdgn1Dp8sfDWC2_fe7bZ-T9aeLCa5wenCJEF3Q9Rpimdu82H7HBfFrfTxDnZ2GAPEw8UJ5kTTAt-0Qm-d4F0ST4iJQpo=@emersion.fr>
In-Reply-To
<172072727742.23379.4164621456049926293-0@git.sr.ht> (view parent)
DKIM signature
pass
Download raw message
Is the issue about detecting whether the dropped object is a file?
Could we check DataTransfer.files [1] to figure that out?

Or is this about something else?

[1]: https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/files
Reply to thread Export thread (mbox)