1
0
Fork 0
forked from forgejo/forgejo

Add toasts to UI (#25449)

Fixes https://github.com/go-gitea/gitea/issues/24353

In some case like async success/error, it is useful to show toasts in UI.
This commit is contained in:
silverwind 2023-06-27 04:45:24 +02:00 committed by GitHub
parent 72c60f94c1
commit c71e8abbc3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 220 additions and 20 deletions

View file

@ -9,6 +9,7 @@ import {hideElem, showElem, toggleElem} from '../utils/dom.js';
import {htmlEscape} from 'escape-goat';
import {createTippy} from '../modules/tippy.js';
import {confirmModal} from './comp/ConfirmModal.js';
import {showErrorToast} from '../modules/toast.js';
const {appUrl, appSubUrl, csrfToken, i18n} = window.config;
@ -439,7 +440,7 @@ export function initGlobalButtons() {
return;
}
// should never happen, otherwise there is a bug in code
alert('Nothing to hide');
showErrorToast('Nothing to hide');
});
initGlobalShowModal();

View file

@ -8,6 +8,7 @@ import {handleGlobalEnterQuickSubmit} from './QuickSubmit.js';
import {renderPreviewPanelContent} from '../repo-editor.js';
import {easyMDEToolbarActions} from './EasyMDEToolbarActions.js';
import {initTextExpander} from './TextExpander.js';
import {showErrorToast} from '../../modules/toast.js';
let elementIdCounter = 0;
@ -26,7 +27,7 @@ export function validateTextareaNonEmpty($textarea) {
$form[0]?.reportValidity();
} else {
// The alert won't hurt users too much, because we are dropping the EasyMDE and the check only occurs in a few places.
alert('Require non-empty content');
showErrorToast('Require non-empty content');
}
return false;
}

View file

@ -1,5 +1,6 @@
import $ from 'jquery';
import {svg} from '../svg.js';
import {showErrorToast} from '../modules/toast.js';
const {appSubUrl, csrfToken} = window.config;
let i18nTextEdited;
@ -39,12 +40,12 @@ function showContentHistoryDetail(issueBaseUrl, commentId, historyId, itemTitleH
if (resp.ok) {
$dialog.modal('hide');
} else {
alert(resp.message);
showErrorToast(resp.message);
}
});
}
} else { // required by eslint
window.alert(`unknown option item: ${optionItem}`);
showErrorToast(`unknown option item: ${optionItem}`);
}
},
onHide() {

View file

@ -4,6 +4,7 @@ import {toggleElem} from '../utils/dom.js';
import {htmlEscape} from 'escape-goat';
import {Sortable} from 'sortablejs';
import {confirmModal} from './comp/ConfirmModal.js';
import {showErrorToast} from '../modules/toast.js';
function initRepoIssueListCheckboxes() {
const $issueSelectAll = $('.issue-checkbox-all');
@ -75,7 +76,7 @@ function initRepoIssueListCheckboxes() {
).then(() => {
window.location.reload();
}).catch((reason) => {
window.alert(reason.responseJSON.error);
showErrorToast(reason.responseJSON.error);
});
});
}