refactor(dokploy): revert

This commit is contained in:
Mauricio Siu
2024-10-27 17:35:19 -06:00
parent ae5df82887
commit 5c85b82257
2 changed files with 17 additions and 44 deletions

View File

@@ -18,28 +18,24 @@ export const DockerLogsId: React.FC<Props> = ({
}) => {
const [term, setTerm] = React.useState<Terminal>();
const [lines, setLines] = React.useState<number>(40);
const wsRef = useRef<WebSocket | null>(null);
const wsRef = useRef<WebSocket | null>(null); // Ref to hold WebSocket instance
useEffect(() => {
if (containerId === "select-a-container") {
return;
}
if (
wsRef.current &&
(wsRef.current.readyState === WebSocket.OPEN ||
wsRef.current.readyState === WebSocket.CONNECTING)
) {
wsRef.current.close();
wsRef.current = null;
}
// if (containerId === "select-a-container") {
// return;
// }
const container = document.getElementById(id);
if (container) {
container.innerHTML = "";
}
// Crear nueva instancia de Terminal
if (wsRef.current) {
console.log(wsRef.current);
if (wsRef.current.readyState === WebSocket.OPEN) {
wsRef.current.close();
}
wsRef.current = null;
}
const termi = new Terminal({
cursorBlink: true,
cols: 80,
@@ -49,6 +45,7 @@ export const DockerLogsId: React.FC<Props> = ({
fontSize: 14,
fontFamily:
'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
convertEol: true,
theme: {
cursor: "transparent",
@@ -57,10 +54,10 @@ export const DockerLogsId: React.FC<Props> = ({
});
const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
const wsUrl = `${protocol}//${window.location.host}/docker-container-logs?containerId=${containerId}&tail=${lines}${serverId ? `&serverId=${serverId}` : ""}`;
const ws = new WebSocket(wsUrl);
wsRef.current = ws;
const fitAddon = new FitAddon();
termi.loadAddon(fitAddon);
// @ts-ignore
@@ -79,17 +76,17 @@ export const DockerLogsId: React.FC<Props> = ({
ws.onclose = (e) => {
console.log(e.reason);
termi.write(`Connection closed!\nReason: ${e.reason}\n`);
wsRef.current = null;
};
return () => {
if (wsRef.current?.readyState === WebSocket.OPEN) {
wsRef.current.close();
ws.close();
wsRef.current = null;
}
wsRef.current = null;
};
}, [containerId, lines]);
}, [lines, containerId]);
useEffect(() => {
term?.clear();