mirror of
https://git.vectorsigma.ru/public/tubearchivist.git
synced 2026-08-05 01:19:29 +00:00
Add waiting for backend handling
This commit is contained in:
@@ -35,13 +35,21 @@ const router = createBrowserRouter(
|
|||||||
loader: async () => {
|
loader: async () => {
|
||||||
console.log('------------ after reload');
|
console.log('------------ after reload');
|
||||||
|
|
||||||
const auth = await loadAuth();
|
let authData = null;
|
||||||
if (auth.status === 403) {
|
|
||||||
|
try {
|
||||||
|
const auth = await loadAuth();
|
||||||
|
if (auth.status === 403) {
|
||||||
|
return redirect(Routes.Login);
|
||||||
|
}
|
||||||
|
|
||||||
|
authData = await auth.json();
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
|
||||||
return redirect(Routes.Login);
|
return redirect(Routes.Login);
|
||||||
}
|
}
|
||||||
|
|
||||||
const authData = await auth.json();
|
|
||||||
|
|
||||||
const userConfig = await loadUserMeConfig();
|
const userConfig = await loadUserMeConfig();
|
||||||
const userAccount = await loadUserAccount();
|
const userAccount = await loadUserAccount();
|
||||||
const appSettings = await loadAppsettingsConfig();
|
const appSettings = await loadAppsettingsConfig();
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import Routes from '../configuration/routes/RouteList';
|
import Routes from '../configuration/routes/RouteList';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import useColours from '../configuration/colours/useColours';
|
import useColours from '../configuration/colours/useColours';
|
||||||
import Button from '../components/Button';
|
import Button from '../components/Button';
|
||||||
import signIn from '../api/actions/signIn';
|
import signIn from '../api/actions/signIn';
|
||||||
|
import loadAuth from '../api/loader/loadAuth';
|
||||||
|
|
||||||
const Login = () => {
|
const Login = () => {
|
||||||
useColours();
|
useColours();
|
||||||
@@ -13,11 +14,16 @@ const Login = () => {
|
|||||||
const [username, setUsername] = useState('');
|
const [username, setUsername] = useState('');
|
||||||
const [password, setPassword] = useState('');
|
const [password, setPassword] = useState('');
|
||||||
const [saveLogin, setSaveLogin] = useState(false);
|
const [saveLogin, setSaveLogin] = useState(false);
|
||||||
|
const [waitingForBackend, setWaitingForBackend] = useState(false);
|
||||||
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
||||||
|
|
||||||
const handleSubmit = async (event: { preventDefault: () => void }) => {
|
const handleSubmit = async (event: { preventDefault: () => void }) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
|
if (waitingForBackend) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
setErrorMessage(null);
|
setErrorMessage(null);
|
||||||
|
|
||||||
const loginResponse = await signIn(username, password, saveLogin);
|
const loginResponse = await signIn(username, password, saveLogin);
|
||||||
@@ -33,6 +39,28 @@ const Login = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const backendCheckInterval = setInterval(async () => {
|
||||||
|
try {
|
||||||
|
const auth = await loadAuth();
|
||||||
|
|
||||||
|
const authData = await auth.json();
|
||||||
|
|
||||||
|
if (authData.response === 'pong') {
|
||||||
|
setWaitingForBackend(false);
|
||||||
|
clearInterval(backendCheckInterval);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log('Checking backend availability: ', error);
|
||||||
|
setWaitingForBackend(true);
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
clearInterval(backendCheckInterval);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<title>TA | Welcome</title>
|
<title>TA | Welcome</title>
|
||||||
@@ -92,7 +120,17 @@ const Login = () => {
|
|||||||
|
|
||||||
<input type="hidden" name="next" value={Routes.Home} />
|
<input type="hidden" name="next" value={Routes.Home} />
|
||||||
|
|
||||||
<Button label="Login" type="submit" />
|
{waitingForBackend && (
|
||||||
|
<>
|
||||||
|
<div className="lds-ring" style={{ color: 'var(--accent-font-dark)' }}>
|
||||||
|
<div />
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!waitingForBackend && (
|
||||||
|
<Button label="Login" type="submit" />
|
||||||
|
)}
|
||||||
</form>
|
</form>
|
||||||
<p className="login-links">
|
<p className="login-links">
|
||||||
<span>
|
<span>
|
||||||
|
|||||||
Reference in New Issue
Block a user