ui: simplify helper copy and center page loading feedback
This commit is contained in:
@@ -10,13 +10,12 @@ const error = document.querySelector('#auth-error');
|
||||
let busy = false;
|
||||
let leaving = false;
|
||||
|
||||
function setBusy(value, message = '') {
|
||||
function setBusy(value) {
|
||||
busy = value;
|
||||
input.disabled = value;
|
||||
button.disabled = value;
|
||||
form.setAttribute('aria-busy', String(value));
|
||||
status.textContent = message;
|
||||
status.hidden = !message;
|
||||
status.hidden = !value;
|
||||
}
|
||||
|
||||
function showError(message) {
|
||||
@@ -27,7 +26,7 @@ function showError(message) {
|
||||
function openWorkbench() {
|
||||
leaving = true;
|
||||
input.value = '';
|
||||
setBusy(true, '正在进入工作台…');
|
||||
setBusy(true);
|
||||
location.replace(webPath('/'));
|
||||
}
|
||||
|
||||
@@ -57,7 +56,7 @@ async function authRequest(path, body) {
|
||||
}
|
||||
|
||||
async function checkAuth() {
|
||||
setBusy(true, '正在检查登录状态…');
|
||||
setBusy(true);
|
||||
error.hidden = true;
|
||||
try {
|
||||
const auth = await authRequest('/api/auth/status');
|
||||
@@ -78,7 +77,7 @@ form.addEventListener('submit', async event => {
|
||||
const body = JSON.stringify({password: input.value});
|
||||
input.value = '';
|
||||
error.hidden = true;
|
||||
setBusy(true, '正在登录…');
|
||||
setBusy(true);
|
||||
try {
|
||||
const auth = await authRequest('/api/auth/login', body);
|
||||
if (!auth.required || auth.authenticated) openWorkbench();
|
||||
|
||||
Reference in New Issue
Block a user