Skip to content

Commit

Permalink
When double-clicking on a file, the behavior is:
Browse files Browse the repository at this point in the history
First click: open the viewer
Second click: close the viewer

But the second click does not correctly close the Viewer, as the method used to cancel the requests does not work.

This PR use modern API to cancel the requests. The requests are now correctly aborted, and the `openFile` method exit because the request call throws an exception.

Fix #893

https://axios-http.com/docs/cancellation
https://developer.mozilla.org/en-US/docs/Web/API/AbortController

Signed-off-by: Louis Chemineau <louis@chmn.me>
Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
  • Loading branch information
artonge authored and backportbot-nextcloud[bot] committed May 17, 2022
1 parent 3fa859e commit 7dc28ea
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/utils/CancelableRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* @author Marco Ambrosini <marcoambrosini@pm.me>
* @author John Molakvoæ <skjnldsv@protonmail.com>
* @author Louis Chemineau <louis@chmn.me>
*
* @license GNU AGPL version 3 or any later version
*
Expand All @@ -21,20 +22,14 @@
*
*/

import axios from '@nextcloud/axios'

/**
* Creates a cancelable axios 'request object'.
*
* @param {function} request the axios promise request
* @returns {Object}
*/
const CancelableRequest = function(request) {
/**
* Generate an axios cancel token
*/
const CancelToken = axios.CancelToken
const source = CancelToken.source()
const controller = new AbortController()

/**
* Execute the request
Expand All @@ -45,12 +40,12 @@ const CancelableRequest = function(request) {
const fetch = async function(url, options) {
return request(
url,
Object.assign({ cancelToken: source.token }, { options })
{ ...options, signal: controller.signal }
)
}
return {
request: fetch,
cancel: source.cancel,
cancel: () => controller.abort(),
}
}

Expand Down

0 comments on commit 7dc28ea

Please sign in to comment.