From 15d071f4f81a0ad09f260de83cb6402875b4de27 Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Sun, 25 Feb 2024 01:08:51 +0200 Subject: [PATCH] Remove jQuery AJAX from repo collaborator mode dropdown (#29371) - Removed all jQuery AJAX calls and replaced with our fetch wrapper - Tested the repo collaborator mode dropdown functionality and it works as before # Demo using `fetch` instead of jQuery AJAX ![action](https://github.com/go-gitea/gitea/assets/20454870/04466629-19b2-4469-9231-38820ee13c36) --------- Signed-off-by: Yarden Shoham Co-authored-by: delvh Co-authored-by: Giteabot --- web_src/js/features/repo-settings.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/web_src/js/features/repo-settings.js b/web_src/js/features/repo-settings.js index 75e624a6a7..0418f3a14a 100644 --- a/web_src/js/features/repo-settings.js +++ b/web_src/js/features/repo-settings.js @@ -2,6 +2,7 @@ import $ from 'jquery'; import {minimatch} from 'minimatch'; import {createMonaco} from './codeeditor.js'; import {onInputDebounce, toggleElem} from '../utils/dom.js'; +import {POST} from '../modules/fetch.js'; const {appSubUrl, csrfToken} = window.config; @@ -11,18 +12,19 @@ export function initRepoSettingsCollaboration() { const $dropdown = $(e); const $text = $dropdown.find('> .text'); $dropdown.dropdown({ - action(_text, value) { + async action(_text, value) { const lastValue = $dropdown.attr('data-last-value'); - $.post($dropdown.attr('data-url'), { - _csrf: csrfToken, - uid: $dropdown.attr('data-uid'), - mode: value, - }).fail(() => { + try { + $dropdown.attr('data-last-value', value); + $dropdown.dropdown('hide'); + const data = new FormData(); + data.append('uid', $dropdown.attr('data-uid')); + data.append('mode', value); + await POST($dropdown.attr('data-url'), {data}); + } catch { $text.text('(error)'); // prevent from misleading users when error occurs $dropdown.attr('data-last-value', lastValue); - }); - $dropdown.attr('data-last-value', value); - $dropdown.dropdown('hide'); + } }, onChange(_value, text, _$choice) { $text.text(text); // update the text when using keyboard navigating