mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-08-11 19:26:56 +00:00
e8f271f5f6
* feat(ui): make the core stack flow usable on mobile Below the md breakpoint the app collapses to a single full-width column: the stack list is full-screen, tapping a stack opens a full-screen detail with a Health / Logs / Compose segmented control (Logs first) and a back button, and a bottom tab bar switches Stacks, Fleet, Schedules, and Settings. Compose is read-only on a phone with a prompt to edit on desktop. Desktop (md and up) is unchanged: the mobile shell is gated behind a useIsMobile hook plus max-md/md variants, and the stack-detail blocks are shared with the desktop two-pane view so it renders identically. Also generalizes the unsaved-changes guard so leaving a dirty editor (back, tab bar, hamburger) prompts before discarding; adds 44px touch targets on list rows, filter chips, and actions; makes log and shell modals full-screen on mobile; and offsets toasts and the deploy pill above the bottom tab bar. * fix(ui): keep mobile nav in sync when opening views from outside the bottom bar On a phone the sidebar activity actions, the node switcher's Manage Nodes, the profile Settings entry, and the dashboard configuration links set the active view without flipping the mobile surface to content, so the user stayed on the stack list and never saw the destination. Route these through the mobile-aware navigation and settings helpers (a no-op on desktop).
93 lines
3.3 KiB
TypeScript
93 lines
3.3 KiB
TypeScript
import { useEffect, useState, useRef } from 'react';
|
|
import { Modal, ModalHeader } from "@/components/ui/modal";
|
|
import { Loader2, Terminal } from "lucide-react";
|
|
|
|
interface LogViewerProps {
|
|
containerId: string | null;
|
|
containerName: string;
|
|
isOpen: boolean;
|
|
onClose: () => void;
|
|
}
|
|
|
|
export function LogViewer({ containerId, containerName, isOpen, onClose }: LogViewerProps) {
|
|
const [logs, setLogs] = useState<string[]>([]);
|
|
const [isConnected, setIsConnected] = useState(false);
|
|
const scrollRef = useRef<HTMLDivElement>(null);
|
|
|
|
// Auto-scroll to bottom when new logs arrive
|
|
useEffect(() => {
|
|
if (scrollRef.current) {
|
|
scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
|
|
}
|
|
}, [logs]);
|
|
|
|
useEffect(() => {
|
|
if (!isOpen || !containerId) return;
|
|
|
|
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
setLogs([]);
|
|
setIsConnected(false);
|
|
|
|
const activeNodeId = localStorage.getItem('sencho-active-node') || '';
|
|
const eventSource = new EventSource(`/api/containers/${containerId}/logs?nodeId=${activeNodeId}`);
|
|
|
|
eventSource.onopen = () => setIsConnected(true);
|
|
|
|
eventSource.onmessage = (event) => {
|
|
try {
|
|
const newLog = JSON.parse(event.data);
|
|
setLogs(prev => {
|
|
const updated = [...prev, newLog];
|
|
return updated.length > 1000 ? updated.slice(updated.length - 1000) : updated;
|
|
});
|
|
} catch (err) {
|
|
console.error("Failed to parse log line", err);
|
|
}
|
|
};
|
|
|
|
eventSource.onerror = () => {
|
|
setIsConnected(false);
|
|
eventSource.close();
|
|
};
|
|
|
|
return () => {
|
|
eventSource.close();
|
|
};
|
|
}, [isOpen, containerId]);
|
|
|
|
return (
|
|
<Modal open={isOpen} onOpenChange={(open) => !open && onClose()} mobileFullScreen className="max-w-4xl h-[80vh] flex flex-col">
|
|
<ModalHeader
|
|
kicker={`LOGS · ${containerName.toUpperCase()}`}
|
|
title={
|
|
<span className="flex items-center gap-2">
|
|
<Terminal className="w-5 h-5" strokeWidth={1.5} />
|
|
Container logs
|
|
{isConnected ? (
|
|
<span className="text-success text-xs ml-2">(connected)</span>
|
|
) : (
|
|
<Loader2 className="inline w-4 h-4 ml-2 animate-spin" />
|
|
)}
|
|
</span>
|
|
}
|
|
description={`Live log stream for ${containerName}`}
|
|
/>
|
|
|
|
<div
|
|
ref={scrollRef}
|
|
className="flex-1 w-full bg-[var(--terminal-bg)] text-success p-4 overflow-y-auto font-mono text-xs mx-6 mb-6 rounded-md"
|
|
>
|
|
{logs.length === 0 && !isConnected ? (
|
|
<div className="text-muted-foreground">Connecting to container stream...</div>
|
|
) : (
|
|
logs.map((log, i) => (
|
|
<div key={i} className="break-all whitespace-pre-wrap leading-tight mb-1">
|
|
{log}
|
|
</div>
|
|
))
|
|
)}
|
|
</div>
|
|
</Modal>
|
|
);
|
|
}
|