Skip to content

Commit bb71cee

Browse files
authored
Improve async/await usage, and sort init calls in index.js (#17386)
* clean up async/await, and sort init calls in `index.js * use `const _promise` to indicate that we do not need await an async function
1 parent 3a693bd commit bb71cee

21 files changed

+214
-202
lines changed

web_src/js/features/common-global.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ export function initGlobalCommon() {
135135
});
136136
}
137137

138-
export async function initGlobalDropzone() {
138+
export function initGlobalDropzone() {
139139
// Dropzone
140140
for (const el of document.querySelectorAll('.dropzone')) {
141141
const $dropzone = $(el);
142-
await createDropzone(el, {
142+
const _promise = createDropzone(el, {
143143
url: $dropzone.data('upload-url'),
144144
headers: {'X-Csrf-Token': csrfToken},
145145
maxFiles: $dropzone.data('max-file'),

web_src/js/features/comp/SearchUserBox.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {htmlEscape} from 'escape-goat';
22

33
const {appSubUrl} = window.config;
44

5-
export function initSearchUserBox() {
5+
export function initCompSearchUserBox() {
66
const $searchUserBox = $('#search-user-box');
77
$searchUserBox.search({
88
minCharacters: 2,

web_src/js/features/comp/WebHookEditor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const {csrfToken} = window.config;
22

3-
export function initWebHookEditor() {
3+
export function initCompWebHookEditor() {
44
if ($('.new.webhook').length === 0) {
55
return;
66
}

web_src/js/features/diff.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

web_src/js/features/dropzone.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ export default async function createDropzone(el, opts) {
33
import(/* webpackChunkName: "dropzone" */'dropzone'),
44
import(/* webpackChunkName: "dropzone" */'dropzone/dist/dropzone.css'),
55
]);
6-
76
Dropzone.autoDiscover = false;
87
return new Dropzone(el, opts);
98
}

web_src/js/features/heatmap.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Vue from 'vue';
22

33
import ActivityHeatmap from '../components/ActivityHeatmap.vue';
44

5-
export default async function initHeatmap() {
5+
export default function initHeatmap() {
66
const el = document.getElementById('user-heatmap');
77
if (!el) return;
88

@@ -24,7 +24,7 @@ export default async function initHeatmap() {
2424

2525
new View().$mount(el);
2626
} catch (err) {
27-
console.error(err);
27+
console.error('Heatmap failed to load', err);
2828
el.textContent = 'Heatmap failed to load';
2929
}
3030
}

web_src/js/features/imagediff.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function getDefaultSvgBoundsIfUndefined(svgXml, src) {
2929
}
3030
}
3131

32-
export default async function initImageDiff() {
32+
export default function initImageDiff() {
3333
function createContext(image1, image2) {
3434
const size1 = {
3535
width: image1 && image1.width || 0,

web_src/js/features/lastcommitloader.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

web_src/js/features/notification.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async function receiveUpdateCount(event) {
4040
}
4141
}
4242

43-
export async function initNotificationCount() {
43+
export function initNotificationCount() {
4444
const notificationCount = $('.notification_count');
4545

4646
if (!notificationCount.length) {
@@ -66,7 +66,7 @@ export async function initNotificationCount() {
6666
return;
6767
}
6868
if (event.data.type === 'notification-count') {
69-
receiveUpdateCount(event.data);
69+
const _promise = receiveUpdateCount(event.data);
7070
} else if (event.data.type === 'error') {
7171
console.error(event.data);
7272
} else if (event.data.type === 'logout') {

web_src/js/features/repo-commit.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,47 @@
1+
const {csrfToken} = window.config;
2+
13
export function initRepoCommitButton() {
24
$('.commit-button').on('click', function (e) {
35
e.preventDefault();
46
$(this).parent().find('.commit-body').toggle();
57
});
68
}
9+
10+
export function initRepoCommitLastCommitLoader() {
11+
const entryMap = {};
12+
13+
const entries = $('table#repo-files-table tr.notready')
14+
.map((_, v) => {
15+
entryMap[$(v).attr('data-entryname')] = $(v);
16+
return $(v).attr('data-entryname');
17+
})
18+
.get();
19+
20+
if (entries.length === 0) {
21+
return;
22+
}
23+
24+
const lastCommitLoaderURL = $('table#repo-files-table').data('lastCommitLoaderUrl');
25+
26+
if (entries.length > 200) {
27+
$.post(lastCommitLoaderURL, {
28+
_csrf: csrfToken,
29+
}, (data) => {
30+
$('table#repo-files-table').replaceWith(data);
31+
});
32+
return;
33+
}
34+
35+
$.post(lastCommitLoaderURL, {
36+
_csrf: csrfToken,
37+
'f': entries,
38+
}, (data) => {
39+
$(data).find('tr').each((_, row) => {
40+
if (row.className === 'commit-list') {
41+
$('table#repo-files-table .commit-list').replaceWith(row);
42+
return;
43+
}
44+
entryMap[$(row).attr('data-entryname')].replaceWith(row);
45+
});
46+
});
47+
}

0 commit comments

Comments
 (0)