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>
  • Loading branch information
artonge committed May 16, 2022
1 parent 267fd25 commit 5cd3f21
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
4 changes: 2 additions & 2 deletions js/viewer-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/viewer-main.js.map

Large diffs are not rendered by default.

16 changes: 5 additions & 11 deletions src/utils/CancelableRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,30 @@
*
*/

import axios from '@nextcloud/axios'

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

/**
* Execute the request
*
* @param {string} url the url to send the request to
* @param {object} [options] optional config for the request
*/
const fetch = async function(url, options) {
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 5cd3f21

Please sign in to comment.