Files
Termix/src/ui/Apps/Host Manager/HostManager.tsx
T

103 lines
3.9 KiB
TypeScript
Raw Normal View History

2025-08-07 02:20:27 -05:00
import React, {useState} from "react";
2025-08-31 19:26:38 -05:00
import {HostManagerHostViewer} from "@/ui/Apps/Host Manager/HostManagerHostViewer.tsx"
2025-08-07 02:20:27 -05:00
import {Tabs, TabsContent, TabsList, TabsTrigger} from "@/components/ui/tabs.tsx";
import {Separator} from "@/components/ui/separator.tsx";
2025-08-31 19:26:38 -05:00
import {HostManagerHostEditor} from "@/ui/Apps/Host Manager/HostManagerHostEditor.tsx";
2025-08-14 01:24:05 -05:00
import {useSidebar} from "@/components/ui/sidebar.tsx";
2025-09-03 00:14:49 -05:00
import {useTranslation} from "react-i18next";
2025-08-07 02:20:27 -05:00
2025-08-17 19:23:33 -05:00
interface HostManagerProps {
2025-08-18 00:13:21 -05:00
onSelectView: (view: string) => void;
isTopbarOpen?: boolean;
2025-08-07 02:20:27 -05:00
}
interface SSHHost {
2025-08-18 00:13:21 -05:00
id: number;
name: string;
ip: string;
port: number;
username: string;
folder: string;
tags: string[];
pin: boolean;
authType: string;
password?: string;
key?: string;
keyPassword?: string;
keyType?: string;
enableTerminal: boolean;
enableTunnel: boolean;
enableFileManager: boolean;
defaultPath: string;
tunnelConnections: any[];
createdAt: string;
updatedAt: string;
2025-08-07 02:20:27 -05:00
}
2025-08-17 19:23:33 -05:00
export function HostManager({onSelectView, isTopbarOpen}: HostManagerProps): React.ReactElement {
2025-09-03 00:14:49 -05:00
const {t} = useTranslation();
2025-08-18 00:13:21 -05:00
const [activeTab, setActiveTab] = useState("host_viewer");
const [editingHost, setEditingHost] = useState<SSHHost | null>(null);
const {state: sidebarState} = useSidebar();
2025-08-07 02:20:27 -05:00
2025-08-18 00:13:21 -05:00
const handleEditHost = (host: SSHHost) => {
setEditingHost(host);
setActiveTab("add_host");
};
2025-08-07 02:20:27 -05:00
2025-08-18 00:13:21 -05:00
const handleFormSubmit = () => {
setEditingHost(null);
setActiveTab("host_viewer");
};
2025-08-07 02:20:27 -05:00
2025-08-18 00:13:21 -05:00
const handleTabChange = (value: string) => {
setActiveTab(value);
if (value === "host_viewer") {
setEditingHost(null);
}
};
2025-08-07 02:20:27 -05:00
2025-08-18 00:13:21 -05:00
const topMarginPx = isTopbarOpen ? 74 : 26;
const leftMarginPx = sidebarState === 'collapsed' ? 26 : 8;
const bottomMarginPx = 8;
2025-08-18 00:13:21 -05:00
return (
<div>
<div className="w-full">
<div
className="bg-[#18181b] text-white p-4 pt-0 rounded-lg border-2 border-[#303032] flex flex-col min-h-0 overflow-hidden"
style={{
marginLeft: leftMarginPx,
marginRight: 17,
marginTop: topMarginPx,
marginBottom: bottomMarginPx,
height: `calc(100vh - ${topMarginPx + bottomMarginPx}px)`
}}
>
<Tabs value={activeTab} onValueChange={handleTabChange}
className="flex-1 flex flex-col h-full min-h-0">
<TabsList className="bg-[#18181b] border-2 border-[#303032] mt-1.5">
2025-09-03 00:14:49 -05:00
<TabsTrigger value="host_viewer">{t('hosts.hostViewer')}</TabsTrigger>
2025-08-18 00:13:21 -05:00
<TabsTrigger value="add_host">
2025-09-03 00:14:49 -05:00
{editingHost ? t('hosts.editHost') : t('hosts.addHost')}
2025-08-18 00:13:21 -05:00
</TabsTrigger>
</TabsList>
<TabsContent value="host_viewer" className="flex-1 flex flex-col h-full min-h-0">
<Separator className="p-0.25 -mt-0.5 mb-1"/>
<HostManagerHostViewer onEditHost={handleEditHost}/>
</TabsContent>
<TabsContent value="add_host" className="flex-1 flex flex-col h-full min-h-0">
<Separator className="p-0.25 -mt-0.5 mb-1"/>
<div className="flex flex-col h-full min-h-0">
<HostManagerHostEditor
editingHost={editingHost}
onFormSubmit={handleFormSubmit}
/>
</div>
</TabsContent>
</Tabs>
</div>
</div>
</div>
)
2025-08-07 02:20:27 -05:00
}