Skip to content

Commit ed3892d

Browse files
authored
Remove jQuery AJAX from the archive download links (#29380)
- Removed all jQuery AJAX calls and replaced with our fetch wrapper - Tested the repo archive download links dropdown functionality and it works as before # Demo using `fetch` instead of jQuery AJAX ![action](https://github.com/go-gitea/gitea/assets/20454870/db791249-bca1-4d22-ac5e-623f68023e15) --------- Signed-off-by: Yarden Shoham <[email protected]>
1 parent f4b9257 commit ed3892d

File tree

1 file changed

+26
-30
lines changed

1 file changed

+26
-30
lines changed

web_src/js/features/repo-common.js

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,34 @@
11
import $ from 'jquery';
22
import {hideElem, showElem} from '../utils/dom.js';
3+
import {POST} from '../modules/fetch.js';
34

4-
const {csrfToken} = window.config;
5-
6-
function getArchive($target, url, first) {
7-
$.ajax({
8-
url,
9-
type: 'POST',
10-
data: {
11-
_csrf: csrfToken,
12-
},
13-
complete(xhr) {
14-
if (xhr.status === 200) {
15-
if (!xhr.responseJSON) {
16-
// XXX Shouldn't happen?
17-
$target.closest('.dropdown').children('i').removeClass('loading');
18-
return;
19-
}
5+
async function getArchive($target, url, first) {
6+
try {
7+
const response = await POST(url);
8+
if (response.status === 200) {
9+
const data = await response.json();
10+
if (!data) {
11+
// XXX Shouldn't happen?
12+
$target.closest('.dropdown').children('i').removeClass('loading');
13+
return;
14+
}
2015

21-
if (!xhr.responseJSON.complete) {
22-
$target.closest('.dropdown').children('i').addClass('loading');
23-
// Wait for only three quarters of a second initially, in case it's
24-
// quickly archived.
25-
setTimeout(() => {
26-
getArchive($target, url, false);
27-
}, first ? 750 : 2000);
28-
} else {
29-
// We don't need to continue checking.
30-
$target.closest('.dropdown').children('i').removeClass('loading');
31-
window.location.href = url;
32-
}
16+
if (!data.complete) {
17+
$target.closest('.dropdown').children('i').addClass('loading');
18+
// Wait for only three quarters of a second initially, in case it's
19+
// quickly archived.
20+
setTimeout(() => {
21+
getArchive($target, url, false);
22+
}, first ? 750 : 2000);
23+
} else {
24+
// We don't need to continue checking.
25+
$target.closest('.dropdown').children('i').removeClass('loading');
26+
window.location.href = url;
3327
}
34-
},
35-
});
28+
}
29+
} catch {
30+
$target.closest('.dropdown').children('i').removeClass('loading');
31+
}
3632
}
3733

3834
export function initRepoArchiveLinks() {

0 commit comments

Comments
 (0)