-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Improve async/await usage, and sort init calls in index.js
#17386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4f5b236
1048169
1f1ab48
6fec338
d959688
dc34b80
30a30f9
c461672
6bc2071
35894fa
bc2ad39
eb1e836
ef89e15
cc82cce
762582a
e559e2c
bc67462
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,47 @@ | ||
const {csrfToken} = window.config; | ||
|
||
export function initRepoCommitButton() { | ||
$('.commit-button').on('click', function (e) { | ||
e.preventDefault(); | ||
$(this).parent().find('.commit-body').toggle(); | ||
}); | ||
} | ||
|
||
export function initRepoCommitLastCommitLoader() { | ||
wxiaoguang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const entryMap = {}; | ||
|
||
const entries = $('table#repo-files-table tr.notready') | ||
.map((_, v) => { | ||
entryMap[$(v).attr('data-entryname')] = $(v); | ||
return $(v).attr('data-entryname'); | ||
}) | ||
.get(); | ||
|
||
if (entries.length === 0) { | ||
return; | ||
} | ||
|
||
const lastCommitLoaderURL = $('table#repo-files-table').data('lastCommitLoaderUrl'); | ||
|
||
if (entries.length > 200) { | ||
$.post(lastCommitLoaderURL, { | ||
_csrf: csrfToken, | ||
}, (data) => { | ||
$('table#repo-files-table').replaceWith(data); | ||
}); | ||
return; | ||
} | ||
|
||
$.post(lastCommitLoaderURL, { | ||
_csrf: csrfToken, | ||
'f': entries, | ||
}, (data) => { | ||
$(data).find('tr').each((_, row) => { | ||
if (row.className === 'commit-list') { | ||
$('table#repo-files-table .commit-list').replaceWith(row); | ||
return; | ||
} | ||
entryMap[$(row).attr('data-entryname')].replaceWith(row); | ||
}); | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ function initEditPreviewTab($form) { | |
_csrf: csrfToken, | ||
mode, | ||
context, | ||
text: $form.find(`.tab[data-tab="${$tabMenu.data('write')}"] textarea`).val() | ||
text: $form.find(`.tab[data-tab="${$tabMenu.data('write')}"] textarea`).val(), | ||
wxiaoguang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, (data) => { | ||
const $previewPanel = $form.find(`.tab[data-tab="${$tabMenu.data('preview')}"]`); | ||
$previewPanel.html(data); | ||
|
@@ -42,7 +42,7 @@ function initEditDiffTab($form) { | |
$.post($this.data('url'), { | ||
_csrf: csrfToken, | ||
context: $this.data('context'), | ||
content: $form.find(`.tab[data-tab="${$tabMenu.data('write')}"] textarea`).val() | ||
content: $form.find(`.tab[data-tab="${$tabMenu.data('write')}"] textarea`).val(), | ||
}, (data) => { | ||
const $diffPreviewPanel = $form.find(`.tab[data-tab="${$tabMenu.data('diff')}"]`); | ||
$diffPreviewPanel.html(data); | ||
|
@@ -75,7 +75,7 @@ function getCursorPosition($e) { | |
return pos; | ||
} | ||
|
||
export async function initRepoEditor() { | ||
export function initRepoEditor() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, function will return before editor is initialized, I don't like it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need the real reasons why it doesn't work. There should be no dependency between modules. Most modules (features) should be able to be initialized at any order. If there was a dependency, we should make it clear now. I can not bear the noodle-like logic. |
||
initEditorForm(); | ||
|
||
$('.js-quick-pull-choice-option').on('change', function () { | ||
|
@@ -134,47 +134,49 @@ export async function initRepoEditor() { | |
const $editArea = $('.repository.editor textarea#edit_area'); | ||
if (!$editArea.length) return; | ||
|
||
const editor = await createCodeEditor($editArea[0], $editFilename[0], previewFileModes); | ||
(async () => { | ||
const editor = await createCodeEditor($editArea[0], $editFilename[0], previewFileModes); | ||
wxiaoguang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Using events from https://github.com/codedance/jquery.AreYouSure#advanced-usage | ||
// to enable or disable the commit button | ||
const $commitButton = $('#commit-button'); | ||
const $editForm = $('.ui.edit.form'); | ||
const dirtyFileClass = 'dirty-file'; | ||
// Using events from https://github.com/codedance/jquery.AreYouSure#advanced-usage | ||
// to enable or disable the commit button | ||
const $commitButton = $('#commit-button'); | ||
const $editForm = $('.ui.edit.form'); | ||
const dirtyFileClass = 'dirty-file'; | ||
|
||
// Disabling the button at the start | ||
if ($('input[name="page_has_posted"]').val() !== 'true') { | ||
$commitButton.prop('disabled', true); | ||
} | ||
|
||
// Registering a custom listener for the file path and the file content | ||
$editForm.areYouSure({ | ||
silent: true, | ||
dirtyClass: dirtyFileClass, | ||
fieldSelector: ':input:not(.commit-form-wrapper :input)', | ||
change() { | ||
const dirty = $(this).hasClass(dirtyFileClass); | ||
$commitButton.prop('disabled', !dirty); | ||
// Disabling the button at the start | ||
if ($('input[name="page_has_posted"]').val() !== 'true') { | ||
$commitButton.prop('disabled', true); | ||
} | ||
}); | ||
|
||
// Update the editor from query params, if available, | ||
// only after the dirtyFileClass initialization | ||
const params = new URLSearchParams(window.location.search); | ||
const value = params.get('value'); | ||
if (value) { | ||
editor.setValue(value); | ||
} | ||
// Registering a custom listener for the file path and the file content | ||
$editForm.areYouSure({ | ||
silent: true, | ||
dirtyClass: dirtyFileClass, | ||
fieldSelector: ':input:not(.commit-form-wrapper :input)', | ||
change() { | ||
const dirty = $(this).hasClass(dirtyFileClass); | ||
$commitButton.prop('disabled', !dirty); | ||
}, | ||
}); | ||
|
||
$commitButton.on('click', (event) => { | ||
// A modal which asks if an empty file should be committed | ||
if ($editArea.val().length === 0) { | ||
$('#edit-empty-content-modal').modal({ | ||
onApprove() { | ||
$('.edit.form').trigger('submit'); | ||
} | ||
}).modal('show'); | ||
event.preventDefault(); | ||
// Update the editor from query params, if available, | ||
// only after the dirtyFileClass initialization | ||
const params = new URLSearchParams(window.location.search); | ||
const value = params.get('value'); | ||
if (value) { | ||
editor.setValue(value); | ||
} | ||
}); | ||
|
||
$commitButton.on('click', (event) => { | ||
// A modal which asks if an empty file should be committed | ||
if ($editArea.val().length === 0) { | ||
$('#edit-empty-content-modal').modal({ | ||
onApprove() { | ||
$('.edit.form').trigger('submit'); | ||
}, | ||
}).modal('show'); | ||
event.preventDefault(); | ||
} | ||
}); | ||
})(); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.