From 0450ec54c77a5e8791d7ad6069ddfe38c8403791 Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Sat, 24 Feb 2024 18:11:32 +0000 Subject: [PATCH 1/2] Remove jQuery AJAX from the archive download links - Removed all jQuery AJAX calls and replaced with our fetch wrapper - Tested the repo collaborator mode dropdown functionality and it works as before Signed-off-by: Yarden Shoham --- web_src/js/features/repo-common.js | 54 +++++++++++++----------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/web_src/js/features/repo-common.js b/web_src/js/features/repo-common.js index 3573e4d50bea..b9e0fed1750d 100644 --- a/web_src/js/features/repo-common.js +++ b/web_src/js/features/repo-common.js @@ -1,38 +1,30 @@ import $ from 'jquery'; import {hideElem, showElem} from '../utils/dom.js'; +import {POST} from '../modules/fetch.js'; -const {csrfToken} = window.config; +async function getArchive($target, url, first) { + const response = await POST(url); + if (response.status === 200) { + const data = await response.json(); + if (!data) { + // XXX Shouldn't happen? + $target.closest('.dropdown').children('i').removeClass('loading'); + return; + } -function getArchive($target, url, first) { - $.ajax({ - url, - type: 'POST', - data: { - _csrf: csrfToken, - }, - complete(xhr) { - if (xhr.status === 200) { - if (!xhr.responseJSON) { - // XXX Shouldn't happen? - $target.closest('.dropdown').children('i').removeClass('loading'); - return; - } - - if (!xhr.responseJSON.complete) { - $target.closest('.dropdown').children('i').addClass('loading'); - // Wait for only three quarters of a second initially, in case it's - // quickly archived. - setTimeout(() => { - getArchive($target, url, false); - }, first ? 750 : 2000); - } else { - // We don't need to continue checking. - $target.closest('.dropdown').children('i').removeClass('loading'); - window.location.href = url; - } - } - }, - }); + if (!data.complete) { + $target.closest('.dropdown').children('i').addClass('loading'); + // Wait for only three quarters of a second initially, in case it's + // quickly archived. + setTimeout(() => { + getArchive($target, url, false); + }, first ? 750 : 2000); + } else { + // We don't need to continue checking. + $target.closest('.dropdown').children('i').removeClass('loading'); + window.location.href = url; + } + } } export function initRepoArchiveLinks() { From ab9232407aafb49962511e86f57043aea7797006 Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Sun, 25 Feb 2024 06:13:18 +0000 Subject: [PATCH 2/2] Add catch --- web_src/js/features/repo-common.js | 42 ++++++++++++++++-------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/web_src/js/features/repo-common.js b/web_src/js/features/repo-common.js index b9e0fed1750d..a8221bbea87e 100644 --- a/web_src/js/features/repo-common.js +++ b/web_src/js/features/repo-common.js @@ -3,27 +3,31 @@ import {hideElem, showElem} from '../utils/dom.js'; import {POST} from '../modules/fetch.js'; async function getArchive($target, url, first) { - const response = await POST(url); - if (response.status === 200) { - const data = await response.json(); - if (!data) { - // XXX Shouldn't happen? - $target.closest('.dropdown').children('i').removeClass('loading'); - return; - } + try { + const response = await POST(url); + if (response.status === 200) { + const data = await response.json(); + if (!data) { + // XXX Shouldn't happen? + $target.closest('.dropdown').children('i').removeClass('loading'); + return; + } - if (!data.complete) { - $target.closest('.dropdown').children('i').addClass('loading'); - // Wait for only three quarters of a second initially, in case it's - // quickly archived. - setTimeout(() => { - getArchive($target, url, false); - }, first ? 750 : 2000); - } else { - // We don't need to continue checking. - $target.closest('.dropdown').children('i').removeClass('loading'); - window.location.href = url; + if (!data.complete) { + $target.closest('.dropdown').children('i').addClass('loading'); + // Wait for only three quarters of a second initially, in case it's + // quickly archived. + setTimeout(() => { + getArchive($target, url, false); + }, first ? 750 : 2000); + } else { + // We don't need to continue checking. + $target.closest('.dropdown').children('i').removeClass('loading'); + window.location.href = url; + } } + } catch { + $target.closest('.dropdown').children('i').removeClass('loading'); } }