summaryrefslogtreecommitdiffstats
path: root/web_src/js/features
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2021-11-12 20:37:45 +0800
committerGitHub <noreply@github.com>2021-11-12 20:37:45 +0800
commit7f802631c54d2e91301158380b273b872d62bd80 (patch)
treed2c138ae0c01fa557a0601829436bae06ac7861c /web_src/js/features
parent0db7a32b9233d2c0039df4e89356ef0cbcef6dae (diff)
downloadgitea-7f802631c54d2e91301158380b273b872d62bd80.tar.gz
gitea-7f802631c54d2e91301158380b273b872d62bd80.zip
Fix some incorrect async functions, improve frontend document. (#17597)
Diffstat (limited to 'web_src/js/features')
-rw-r--r--web_src/js/features/clipboard.js22
-rw-r--r--web_src/js/features/notification.js35
-rw-r--r--web_src/js/features/repo-graph.js19
-rw-r--r--web_src/js/features/repo-legacy.js2
-rw-r--r--web_src/js/features/repo-projects.js4
-rw-r--r--web_src/js/features/stopwatch.js10
6 files changed, 48 insertions, 44 deletions
diff --git a/web_src/js/features/clipboard.js b/web_src/js/features/clipboard.js
index 8d28b4e281..89aface93a 100644
--- a/web_src/js/features/clipboard.js
+++ b/web_src/js/features/clipboard.js
@@ -46,7 +46,7 @@ function fallbackCopyToClipboard(text) {
}
export default function initGlobalCopyToClipboardListener() {
- document.addEventListener('click', async (e) => {
+ document.addEventListener('click', (e) => {
let target = e.target;
// in case <button data-clipboard-text><svg></button>, so we just search up to 3 levels for performance.
for (let i = 0; i < 3 && target; i++) {
@@ -58,16 +58,20 @@ export default function initGlobalCopyToClipboardListener() {
}
if (text) {
e.preventDefault();
- try {
- await navigator.clipboard.writeText(text);
- onSuccess(target);
- } catch {
- if (fallbackCopyToClipboard(text)) {
+
+ (async() => {
+ try {
+ await navigator.clipboard.writeText(text);
onSuccess(target);
- } else {
- onError(target);
+ } catch {
+ if (fallbackCopyToClipboard(text)) {
+ onSuccess(target);
+ } else {
+ onError(target);
+ }
}
- }
+ })();
+
break;
}
target = target.parentElement;
diff --git a/web_src/js/features/notification.js b/web_src/js/features/notification.js
index f4c31c5ede..1e483b16c8 100644
--- a/web_src/js/features/notification.js
+++ b/web_src/js/features/notification.js
@@ -3,21 +3,22 @@ const {appSubUrl, csrfToken, notificationSettings} = window.config;
let notificationSequenceNumber = 0;
export function initNotificationsTable() {
- $('#notification_table .button').on('click', async function () {
- const data = await updateNotification(
- $(this).data('url'),
- $(this).data('status'),
- $(this).data('page'),
- $(this).data('q'),
- $(this).data('notification-id'),
- );
-
- if ($(data).data('sequence-number') === notificationSequenceNumber) {
- $('#notification_div').replaceWith(data);
- initNotificationsTable();
- }
- await updateNotificationCount();
-
+ $('#notification_table .button').on('click', function () {
+ (async () => {
+ const data = await updateNotification(
+ $(this).data('url'),
+ $(this).data('status'),
+ $(this).data('page'),
+ $(this).data('q'),
+ $(this).data('notification-id'),
+ );
+
+ if ($(data).data('sequence-number') === notificationSequenceNumber) {
+ $('#notification_div').replaceWith(data);
+ initNotificationsTable();
+ }
+ await updateNotificationCount();
+ })();
return false;
});
}
@@ -104,8 +105,8 @@ export function initNotificationCount() {
}
const fn = (timeout, lastCount) => {
- setTimeout(async () => {
- await updateNotificationCountWithCallback(fn, timeout, lastCount);
+ setTimeout(() => {
+ const _promise = updateNotificationCountWithCallback(fn, timeout, lastCount);
}, timeout);
};
diff --git a/web_src/js/features/repo-graph.js b/web_src/js/features/repo-graph.js
index 007cf9b38d..73bde5facd 100644
--- a/web_src/js/features/repo-graph.js
+++ b/web_src/js/features/repo-graph.js
@@ -48,7 +48,7 @@ export default function initRepoGraphGit() {
});
const url = new URL(window.location);
const params = url.searchParams;
- const updateGraph = async () => {
+ const updateGraph = () => {
const queryString = params.toString();
const ajaxUrl = new URL(url);
ajaxUrl.searchParams.set('div-only', 'true');
@@ -57,14 +57,15 @@ export default function initRepoGraphGit() {
$('#rel-container').addClass('hide');
$('#rev-container').addClass('hide');
$('#loading-indicator').removeClass('hide');
-
- const div = $(await $.ajax(String(ajaxUrl)));
- $('#pagination').html(div.find('#pagination').html());
- $('#rel-container').html(div.find('#rel-container').html());
- $('#rev-container').html(div.find('#rev-container').html());
- $('#loading-indicator').addClass('hide');
- $('#rel-container').removeClass('hide');
- $('#rev-container').removeClass('hide');
+ (async () => {
+ const div = $(await $.ajax(String(ajaxUrl)));
+ $('#pagination').html(div.find('#pagination').html());
+ $('#rel-container').html(div.find('#rel-container').html());
+ $('#rev-container').html(div.find('#rev-container').html());
+ $('#loading-indicator').addClass('hide');
+ $('#rel-container').removeClass('hide');
+ $('#rev-container').removeClass('hide');
+ })();
};
const dropdownSelected = params.getAll('branch');
if (params.has('hide-pr-refs') && params.get('hide-pr-refs') === 'true') {
diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js
index f4a8c0cf3e..8945360cd5 100644
--- a/web_src/js/features/repo-legacy.js
+++ b/web_src/js/features/repo-legacy.js
@@ -351,6 +351,7 @@ export function initRepository() {
// Edit issue or comment content
$(document).on('click', '.edit-content', async function (event) {
+ event.preventDefault();
$(this).closest('.dropdown').find('.menu').toggle('visible');
const $segment = $(this).closest('.header').next();
const $editContentZone = $segment.find('.edit-content-zone');
@@ -511,7 +512,6 @@ export function initRepository() {
$textarea.focus();
$simplemde.codemirror.focus();
});
- event.preventDefault();
});
initRepoIssueCommentDelete();
diff --git a/web_src/js/features/repo-projects.js b/web_src/js/features/repo-projects.js
index 995b971be5..270d546713 100644
--- a/web_src/js/features/repo-projects.js
+++ b/web_src/js/features/repo-projects.js
@@ -63,9 +63,7 @@ export default function initRepoProject() {
return;
}
- (async () => {
- await initRepoProjectSortable();
- })();
+ const _promise = initRepoProjectSortable();
$('.edit-project-board').each(function () {
const projectHeader = $(this).closest('.board-column-header');
diff --git a/web_src/js/features/stopwatch.js b/web_src/js/features/stopwatch.js
index ff3edaf8cc..f6185f7ff7 100644
--- a/web_src/js/features/stopwatch.js
+++ b/web_src/js/features/stopwatch.js
@@ -82,8 +82,8 @@ export function initStopwatch() {
}
const fn = (timeout) => {
- setTimeout(async () => {
- await updateStopwatchWithCallback(fn, timeout);
+ setTimeout(() => {
+ const _promise = updateStopwatchWithCallback(fn, timeout);
}, timeout);
};
@@ -122,7 +122,7 @@ async function updateStopwatch() {
return updateStopwatchData(data);
}
-async function updateStopwatchData(data) {
+function updateStopwatchData(data) {
const watch = data[0];
const btnEl = $('.active-stopwatch-trigger');
if (!watch) {
@@ -135,14 +135,14 @@ async function updateStopwatchData(data) {
$('.stopwatch-cancel').attr('action', `${issueUrl}/times/stopwatch/cancel`);
$('.stopwatch-issue').text(`${repo_owner_name}/${repo_name}#${issue_index}`);
$('.stopwatch-time').text(prettyMilliseconds(seconds * 1000));
- await updateStopwatchTime(seconds);
+ updateStopwatchTime(seconds);
btnEl.removeClass('hidden');
}
return !!data.length;
}
-async function updateStopwatchTime(seconds) {
+function updateStopwatchTime(seconds) {
const secs = parseInt(seconds);
if (!Number.isFinite(secs)) return;