do not enable input if websocket connection failed
This commit is contained in:
@@ -35,29 +35,54 @@ function UploadPage() {
|
|||||||
const startLogs = async () => {
|
const startLogs = async () => {
|
||||||
setLogs([formatLogMessage("Initializing freqsplit")]);
|
setLogs([formatLogMessage("Initializing freqsplit")]);
|
||||||
|
|
||||||
setTimeout(() => {
|
setLogs((prevLogs) => [
|
||||||
setLogs((prevLogs) => [...prevLogs, formatLogMessage("Connecting to server")]);
|
...prevLogs,
|
||||||
|
formatLogMessage("Connecting to server"),
|
||||||
|
]);
|
||||||
|
|
||||||
// Send GET request to /api/ping
|
axios
|
||||||
axios.get("/api/ping")
|
.get("/api/ping")
|
||||||
.then((ping_resp) => {
|
.then((ping_resp) => {
|
||||||
if (ping_resp.status === 200) {
|
if (ping_resp.status === 200) {
|
||||||
setTimeout(() => {
|
setLogs((prevLogs) => [
|
||||||
setLogs((prevLogs) => [...prevLogs, formatLogMessage("Connection established successfully")]);
|
...prevLogs,
|
||||||
|
formatLogMessage("Connection established successfully"),
|
||||||
|
]);
|
||||||
|
setLogs((prevLogs) => [
|
||||||
|
...prevLogs,
|
||||||
|
formatLogMessage("Waiting for WebSocket connection"),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const checkWebSocketConnection = () => {
|
||||||
|
if (isConnected) {
|
||||||
|
setLogs((prevLogs) => [
|
||||||
|
...prevLogs,
|
||||||
|
formatLogMessage("WebSocket connected"),
|
||||||
|
]);
|
||||||
setInputEnabled(true);
|
setInputEnabled(true);
|
||||||
}, 80);
|
|
||||||
} else {
|
} else {
|
||||||
setLogs((prevLogs) => [...prevLogs, formatLogMessage("Failed to connect to server")]);
|
setTimeout(checkWebSocketConnection, 100);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
checkWebSocketConnection();
|
||||||
|
} else {
|
||||||
|
setLogs((prevLogs) => [
|
||||||
|
...prevLogs,
|
||||||
|
formatLogMessage("Failed to connect to server"),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
setLogs((prevLogs) => [...prevLogs, formatLogMessage("Failed to connect to server")]);
|
setLogs((prevLogs) => [
|
||||||
|
...prevLogs,
|
||||||
|
formatLogMessage("Failed to connect to server"),
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
}, 90);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
startLogs();
|
startLogs();
|
||||||
}, []);
|
}, [isConnected]);
|
||||||
|
|
||||||
const handleDragOver = (e: React.DragEvent<HTMLDivElement>) => {
|
const handleDragOver = (e: React.DragEvent<HTMLDivElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|||||||
Reference in New Issue
Block a user