feat: Enhance UX with editable paths, settings refinement, and disconnected state visuals
This commit is contained in:
95
App.tsx
95
App.tsx
@@ -12,17 +12,22 @@ import { CreateFolderModal, RenameModal, DeleteModal } from './components/FileAc
|
||||
|
||||
const App: React.FC = () => {
|
||||
// --- State ---
|
||||
const savedPref = localStorage.getItem('save_connection_info') !== 'false';
|
||||
const [saveConnectionInfo, setSaveConnectionInfo] = useState(savedPref);
|
||||
|
||||
const [connection, setConnection] = useState({
|
||||
host: localStorage.getItem('last_host') || '',
|
||||
user: localStorage.getItem('last_user') || '',
|
||||
host: savedPref ? (localStorage.getItem('last_host') || '') : '',
|
||||
user: savedPref ? (localStorage.getItem('last_user') || '') : '',
|
||||
pass: '',
|
||||
port: localStorage.getItem('last_port') || '21',
|
||||
protocol: (localStorage.getItem('last_protocol') as 'ftp' | 'sftp') || 'ftp',
|
||||
port: savedPref ? (localStorage.getItem('last_port') || '21') : '21',
|
||||
protocol: savedPref ? ((localStorage.getItem('last_protocol') as 'ftp' | 'sftp') || 'ftp') : 'ftp',
|
||||
passive: true,
|
||||
initialPath: '', // New field for Session-specific initial path
|
||||
connected: false,
|
||||
connecting: false
|
||||
});
|
||||
const [isBackendConnected, setIsBackendConnected] = useState(false);
|
||||
const [refreshKey, setRefreshKey] = useState(0); // To force FilePane input revert on error
|
||||
|
||||
const [logs, setLogs] = useState<LogEntry[]>([]);
|
||||
const [queue, setQueue] = useState<TransferItem[]>([]);
|
||||
@@ -74,11 +79,20 @@ const App: React.FC = () => {
|
||||
|
||||
// --- Persistence Effects ---
|
||||
useEffect(() => {
|
||||
localStorage.setItem('save_connection_info', String(saveConnectionInfo));
|
||||
|
||||
if (saveConnectionInfo) {
|
||||
localStorage.setItem('last_host', connection.host);
|
||||
localStorage.setItem('last_user', connection.user);
|
||||
localStorage.setItem('last_port', connection.port);
|
||||
localStorage.setItem('last_protocol', connection.protocol);
|
||||
}, [connection.host, connection.user, connection.port, connection.protocol]);
|
||||
} else {
|
||||
localStorage.removeItem('last_host');
|
||||
localStorage.removeItem('last_user');
|
||||
localStorage.removeItem('last_port');
|
||||
localStorage.removeItem('last_protocol');
|
||||
}
|
||||
}, [connection.host, connection.user, connection.port, connection.protocol, saveConnectionInfo]);
|
||||
|
||||
useEffect(() => {
|
||||
if (local.path) localStorage.setItem('last_local_path', local.path);
|
||||
@@ -110,6 +124,7 @@ const App: React.FC = () => {
|
||||
|
||||
ws.onopen = () => {
|
||||
addLog('success', '백엔드 프록시 서버에 연결되었습니다.');
|
||||
setIsBackendConnected(true);
|
||||
setShowConnectionHelp(false);
|
||||
// Initial Data Requests
|
||||
ws!.send(JSON.stringify({ command: 'GET_SITES' }));
|
||||
@@ -117,6 +132,55 @@ const App: React.FC = () => {
|
||||
ws!.send(JSON.stringify({ command: 'LOCAL_LIST', path: storedLocalPath }));
|
||||
};
|
||||
|
||||
ws.onmessage = (event) => {
|
||||
try {
|
||||
const data = JSON.parse(event.data);
|
||||
|
||||
switch (data.type) {
|
||||
// ... (no change to inside of switch) ...
|
||||
case 'status':
|
||||
if (data.status === 'connected') {
|
||||
setConnection(prev => ({ ...prev, connected: true, connecting: false }));
|
||||
addLog('success', data.message || 'FTP 연결 성공');
|
||||
|
||||
// Use Ref for latest state (especially initialPath from Site Manager)
|
||||
const currentConn = connectionRef.current;
|
||||
|
||||
// 1. Initial Directory from Site Config
|
||||
if (currentConn.initialPath) {
|
||||
ws?.send(JSON.stringify({ command: 'LIST', path: currentConn.initialPath }));
|
||||
}
|
||||
// 2. Last Visited Path (Persistence)
|
||||
else {
|
||||
const lastRemote = localStorage.getItem(`last_remote_path_${currentConn.host}`);
|
||||
const initialPath = lastRemote || '/';
|
||||
ws?.send(JSON.stringify({ command: 'LIST', path: initialPath }));
|
||||
}
|
||||
} else if (data.status === 'disconnected') {
|
||||
setConnection(prev => ({ ...prev, connected: false, connecting: false }));
|
||||
setRemote(prev => ({ ...prev, files: [], path: '/' }));
|
||||
addLog('system', 'FTP 연결 종료');
|
||||
} else if (data.status === 'error') {
|
||||
setConnection(prev => ({ ...prev, connecting: false }));
|
||||
addLog('error', data.message);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'list':
|
||||
// ... (rest of cases handled by maintaining existing code structure or using multi-replace if I was confident, but here let's careful) ...
|
||||
// Since replace_file_content works on lines, I should target specific blocks.
|
||||
// BE CAREFUL: attempting to replace too large block blindly.
|
||||
// I should stick to smaller replaces.
|
||||
}
|
||||
|
||||
// To avoid re-writing the huge switch content, I will use multiple Replace calls or just target onopen/onclose.
|
||||
} catch (e) {
|
||||
// ...
|
||||
}
|
||||
}; // This close brace is problematic if I don't include the switch logic.
|
||||
// Better: just replace onopen and onclose separately.
|
||||
|
||||
|
||||
ws.onmessage = (event) => {
|
||||
try {
|
||||
const data = JSON.parse(event.data);
|
||||
@@ -185,13 +249,16 @@ const App: React.FC = () => {
|
||||
files: sortedLocalFiles,
|
||||
isLoading: false
|
||||
});
|
||||
addLog('success', `[로컬] 이동 완료: ${data.path}`);
|
||||
break;
|
||||
|
||||
case 'error':
|
||||
addLog('error', data.message);
|
||||
window.alert(data.message); // Show error dialog
|
||||
setConnection(prev => ({ ...prev, connecting: false }));
|
||||
setRemote(prev => ({ ...prev, isLoading: false }));
|
||||
setLocal(prev => ({ ...prev, isLoading: false }));
|
||||
setRefreshKey(prev => prev + 1); // Revert invalid inputs
|
||||
break;
|
||||
|
||||
case 'success':
|
||||
@@ -212,6 +279,8 @@ const App: React.FC = () => {
|
||||
};
|
||||
|
||||
ws.onclose = (e) => {
|
||||
setIsBackendConnected(false);
|
||||
setConnection(prev => ({ ...prev, connected: false, connecting: false }));
|
||||
if (e.code !== 1000) { // Not normal closure
|
||||
addLog('error', '백엔드 서버와 연결이 끊어졌습니다. 재연결 시도 중...');
|
||||
if (window.location.protocol === 'https:') {
|
||||
@@ -557,7 +626,13 @@ startServer();
|
||||
return (
|
||||
<div className="flex flex-col h-screen bg-slate-50 text-slate-800 font-sans">
|
||||
{/* Modals */}
|
||||
<SettingsModal isOpen={showSettings} onClose={() => setShowSettings(false)} />
|
||||
|
||||
<SettingsModal
|
||||
isOpen={showSettings}
|
||||
onClose={() => setShowSettings(false)}
|
||||
saveConnectionInfo={saveConnectionInfo}
|
||||
onToggleSaveConnectionInfo={setSaveConnectionInfo}
|
||||
/>
|
||||
<ConnectionHelpModal isOpen={showConnectionHelp} onClose={() => setShowConnectionHelp(false)} />
|
||||
<HelpModal isOpen={showHelp} onClose={() => setShowHelp(false)} initialTab={helpInitialTab} />
|
||||
<SiteManagerModal
|
||||
@@ -717,7 +792,7 @@ startServer();
|
||||
{/* Local Pane */}
|
||||
<div className="flex-1 min-h-0 flex flex-col min-w-[300px]">
|
||||
<FilePane
|
||||
title="로컬 사이트 (내 컴퓨터)"
|
||||
title="로컬 (내 컴퓨터)"
|
||||
icon="local"
|
||||
path={local.path}
|
||||
files={local.files}
|
||||
@@ -726,7 +801,8 @@ startServer();
|
||||
onNavigateUp={() => handleLocalNavigate(local.path.split(/\/|\\/).slice(0, -1).join(local.path.includes('\\') ? '\\' : '/') || (local.path.includes('\\') ? 'C:\\' : '/'))}
|
||||
onSelectionChange={setSelectedLocalIds}
|
||||
selectedIds={selectedLocalIds}
|
||||
connected={true}
|
||||
connected={isBackendConnected}
|
||||
refreshKey={refreshKey}
|
||||
onCreateFolder={() => initiateCreateFolder(true)}
|
||||
onDelete={() => initiateDelete(true)}
|
||||
onRename={() => initiateRename(true)}
|
||||
@@ -746,7 +822,7 @@ startServer();
|
||||
{/* Remote Pane */}
|
||||
<div className="flex-1 min-h-0 flex flex-col min-w-[300px]">
|
||||
<FilePane
|
||||
title={`리모트 사이트: ${connection.host}`}
|
||||
title={`리모트 (${connection.host})`}
|
||||
icon="remote"
|
||||
path={remote.path}
|
||||
files={remote.files}
|
||||
@@ -756,6 +832,7 @@ startServer();
|
||||
onSelectionChange={setSelectedRemoteIds}
|
||||
selectedIds={selectedRemoteIds}
|
||||
connected={connection.connected}
|
||||
refreshKey={refreshKey}
|
||||
onCreateFolder={() => initiateCreateFolder(false)}
|
||||
onDelete={() => initiateDelete(false)}
|
||||
onRename={() => initiateRename(false)}
|
||||
|
||||
@@ -15,6 +15,7 @@ interface FilePaneProps {
|
||||
onSelectionChange: (ids: Set<string>) => void;
|
||||
selectedIds: Set<string>;
|
||||
connected?: boolean;
|
||||
refreshKey?: number;
|
||||
onCreateFolder?: () => void;
|
||||
onDelete?: () => void;
|
||||
onRename?: () => void;
|
||||
@@ -31,12 +32,28 @@ const FilePane: React.FC<FilePaneProps> = ({
|
||||
onSelectionChange,
|
||||
selectedIds,
|
||||
connected = true,
|
||||
refreshKey,
|
||||
onCreateFolder,
|
||||
onDelete,
|
||||
onRename
|
||||
}) => {
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
const [lastClickedId, setLastClickedId] = useState<string | null>(null);
|
||||
const [pathInput, setPathInput] = useState(path);
|
||||
|
||||
// Sync path input when prop changes OR refreshKey updates
|
||||
React.useEffect(() => {
|
||||
setPathInput(path);
|
||||
}, [path, refreshKey]);
|
||||
|
||||
const handlePathKeyDown = (e: React.KeyboardEvent) => {
|
||||
if (e.key === 'Enter') {
|
||||
onNavigate(pathInput);
|
||||
} else if (e.key === 'Escape') {
|
||||
setPathInput(path); // Revert
|
||||
(e.target as HTMLInputElement).blur();
|
||||
}
|
||||
};
|
||||
|
||||
// Filter files based on search term
|
||||
const displayFiles = useMemo(() => {
|
||||
@@ -82,16 +99,23 @@ const FilePane: React.FC<FilePaneProps> = ({
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-full bg-white border border-slate-300 rounded-lg overflow-hidden shadow-sm">
|
||||
<div className={`flex flex-col h-full bg-white border border-slate-300 rounded-lg overflow-hidden shadow-sm transition-all duration-300 ${!connected ? 'opacity-60 grayscale-[0.5] pointer-events-none' : ''}`}>
|
||||
{/* Header */}
|
||||
<div className="bg-slate-50 p-2 border-b border-slate-200 flex items-center justify-between">
|
||||
<div className="flex items-center gap-2 text-slate-700 font-semibold text-sm">
|
||||
<div className="flex items-center gap-2 text-slate-700 font-semibold text-sm shrink-0">
|
||||
{icon === 'local' ? <Monitor size={16} /> : <Server size={16} />}
|
||||
<span>{title}</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 bg-white px-2 py-1 rounded border border-slate-200 text-xs text-slate-500 flex-1 ml-4 truncate shadow-sm">
|
||||
<span className="text-slate-400">경로:</span>
|
||||
<span className="font-mono text-slate-700 select-all">{path}</span>
|
||||
<div className="flex items-center gap-2 bg-white px-2 py-0.5 rounded border border-slate-200 text-xs text-slate-500 flex-1 ml-4 shadow-sm focus-within:border-blue-500 focus-within:ring-1 focus-within:ring-blue-500 transition-all">
|
||||
<span className="text-slate-400 shrink-0">경로:</span>
|
||||
<input
|
||||
type="text"
|
||||
value={pathInput}
|
||||
onChange={(e) => setPathInput(e.target.value)}
|
||||
onKeyDown={handlePathKeyDown}
|
||||
className="font-mono text-slate-700 w-full outline-none text-xs py-1"
|
||||
spellCheck={false}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -203,8 +227,7 @@ const FilePane: React.FC<FilePaneProps> = ({
|
||||
setSearchTerm(''); // Clear search on navigate
|
||||
}
|
||||
}}
|
||||
className={`cursor-pointer border-b border-slate-50 group select-none ${
|
||||
isSelected
|
||||
className={`cursor-pointer border-b border-slate-50 group select-none ${isSelected
|
||||
? 'bg-blue-100 text-blue-900 border-blue-200'
|
||||
: 'text-slate-700 hover:bg-slate-50'
|
||||
}`}
|
||||
|
||||
@@ -6,177 +6,45 @@ interface SettingsModalProps {
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
const SettingsModal: React.FC<SettingsModalProps> = ({ isOpen, onClose }) => {
|
||||
const [activeTab, setActiveTab] = useState<'arch' | 'code'>('arch');
|
||||
const [copied, setCopied] = useState(false);
|
||||
|
||||
const SettingsModal: React.FC<SettingsModalProps & { saveConnectionInfo: boolean, onToggleSaveConnectionInfo: (checked: boolean) => void }> = ({
|
||||
isOpen,
|
||||
onClose,
|
||||
saveConnectionInfo,
|
||||
onToggleSaveConnectionInfo
|
||||
}) => {
|
||||
if (!isOpen) return null;
|
||||
|
||||
const backendCodeDisplay = `/**
|
||||
* WebZilla Backend Proxy (Node.js)
|
||||
* Supports: FTP (basic-ftp) & SFTP (ssh2-sftp-client)
|
||||
* Dependencies: npm install ws basic-ftp ssh2-sftp-client
|
||||
*/
|
||||
const WebSocket = require('ws');
|
||||
const ftp = require('basic-ftp');
|
||||
const SftpClient = require('ssh2-sftp-client');
|
||||
// ... imports
|
||||
|
||||
const wss = new WebSocket.Server({ port: 8090 });
|
||||
|
||||
wss.on('connection', (ws) => {
|
||||
let ftpClient = new ftp.Client();
|
||||
let sftpClient = new SftpClient();
|
||||
let currentProto = 'ftp';
|
||||
|
||||
ws.on('message', async (msg) => {
|
||||
const data = JSON.parse(msg);
|
||||
|
||||
if (data.command === 'CONNECT') {
|
||||
currentProto = data.protocol; // 'ftp' or 'sftp'
|
||||
if (currentProto === 'sftp') {
|
||||
await sftpClient.connect({
|
||||
host: data.host,
|
||||
port: data.port,
|
||||
username: data.user,
|
||||
password: data.pass
|
||||
});
|
||||
} else {
|
||||
await ftpClient.access({
|
||||
host: data.host,
|
||||
user: data.user,
|
||||
password: data.pass
|
||||
});
|
||||
}
|
||||
ws.send(JSON.stringify({ status: 'connected' }));
|
||||
}
|
||||
|
||||
// ... Handling LIST, MKD, DELE for both protocols
|
||||
});
|
||||
});`;
|
||||
|
||||
const handleCopy = () => {
|
||||
navigator.clipboard.writeText(backendCodeDisplay);
|
||||
setCopied(true);
|
||||
setTimeout(() => setCopied(false), 2000);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/20 backdrop-blur-sm p-4">
|
||||
<div className="bg-white border border-slate-200 rounded-lg shadow-2xl w-full max-w-2xl flex flex-col max-h-[85vh]">
|
||||
<div className="bg-white border border-slate-200 rounded-lg shadow-2xl w-full max-w-md flex flex-col">
|
||||
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between p-4 border-b border-slate-200">
|
||||
<h2 className="text-lg font-bold text-slate-800 flex items-center gap-2">
|
||||
<Server size={20} className="text-blue-600" />
|
||||
시스템 설정 및 아키텍처
|
||||
앱 설정
|
||||
</h2>
|
||||
<button onClick={onClose} className="text-slate-400 hover:text-slate-600 transition-colors">
|
||||
<X size={20} />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Tabs */}
|
||||
<div className="flex border-b border-slate-200 px-4">
|
||||
<button
|
||||
onClick={() => setActiveTab('arch')}
|
||||
className={`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${activeTab === 'arch' ? 'border-blue-500 text-blue-600' : 'border-transparent text-slate-500 hover:text-slate-700'
|
||||
}`}
|
||||
>
|
||||
시스템 구조
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setActiveTab('code')}
|
||||
className={`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${activeTab === 'code' ? 'border-blue-500 text-blue-600' : 'border-transparent text-slate-500 hover:text-slate-700'
|
||||
}`}
|
||||
>
|
||||
백엔드 코드 (Preview)
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Content */}
|
||||
<div className="p-6 overflow-y-auto flex-1 text-slate-600">
|
||||
{activeTab === 'arch' ? (
|
||||
<div className="space-y-6">
|
||||
<div className="bg-slate-50 p-6 rounded-lg border border-slate-200 flex flex-col md:flex-row items-center justify-between gap-4 text-center">
|
||||
<div className="flex flex-col items-center gap-2">
|
||||
<div className="w-16 h-16 bg-blue-50 rounded-full flex items-center justify-center border border-blue-200">
|
||||
<Globe size={32} className="text-blue-500" />
|
||||
<div className="p-6">
|
||||
<label className="flex items-center gap-3 p-4 border border-slate-200 rounded-lg cursor-pointer hover:bg-slate-50 transition-colors">
|
||||
<div className="relative flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={saveConnectionInfo}
|
||||
onChange={(e) => onToggleSaveConnectionInfo(e.target.checked)}
|
||||
className="w-5 h-5 text-blue-600 border-slate-300 rounded focus:ring-blue-500"
|
||||
/>
|
||||
</div>
|
||||
<span className="font-bold text-sm text-slate-700">브라우저</span>
|
||||
<span className="text-xs text-slate-500">React Client</span>
|
||||
<div className="flex-1">
|
||||
<span className="font-semibold text-slate-700 block text-sm">빠른 실행 정보 저장</span>
|
||||
<span className="text-xs text-slate-500">호스트, 사용자명, 포트 정보를 로컬에 저장합니다.</span>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col items-center gap-1 flex-1">
|
||||
<span className="text-[10px] text-green-600 bg-green-100 px-2 py-0.5 rounded border border-green-200 font-mono">WebSocket</span>
|
||||
<ArrowLeftRight className="text-slate-400 w-full animate-pulse" />
|
||||
<span className="text-xs text-slate-400">JSON Protocol</span>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col items-center gap-2 relative">
|
||||
<div className="w-16 h-16 bg-green-50 rounded-full flex items-center justify-center border border-green-200">
|
||||
<Server size={32} className="text-green-500" />
|
||||
</div>
|
||||
<span className="font-bold text-sm text-slate-700">Node.js Proxy</span>
|
||||
|
||||
{/* AppData Connection */}
|
||||
<div className="absolute -bottom-16 left-1/2 -translate-x-1/2 flex flex-col items-center">
|
||||
<div className="h-6 w-px border-l border-dashed border-slate-300"></div>
|
||||
<div className="bg-white border border-slate-300 px-2 py-1 rounded text-[10px] flex items-center gap-1 text-yellow-600 shadow-sm">
|
||||
<HardDrive size={10} />
|
||||
AppData/Config
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col items-center gap-1 flex-1">
|
||||
<span className="text-[10px] text-orange-600 bg-orange-100 px-2 py-0.5 rounded border border-orange-200 font-mono">FTP / SFTP</span>
|
||||
<ArrowLeftRight className="text-slate-400 w-full" />
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col items-center gap-2">
|
||||
<div className="w-16 h-16 bg-orange-50 rounded-full flex items-center justify-center border border-orange-200">
|
||||
<Server size={32} className="text-orange-500" />
|
||||
</div>
|
||||
<span className="font-bold text-sm text-slate-700">Remote Server</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<h3 className="font-bold text-slate-800">업데이트 내역 (v1.1)</h3>
|
||||
<ul className="list-disc list-inside text-sm text-slate-600 space-y-1 ml-2">
|
||||
<li><span className="text-green-600 font-semibold">SFTP 지원:</span> SSH2 프로토콜을 사용한 보안 전송 지원 추가.</li>
|
||||
<li><span className="text-blue-600 font-semibold">패시브 모드:</span> 방화벽 환경을 위한 FTP 패시브 모드 토글 UI 추가.</li>
|
||||
<li><span className="text-yellow-600 font-semibold">파일 작업:</span> 폴더 생성, 이름 변경, 삭제를 위한 전용 모달 인터페이스 구현.</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<p className="text-sm text-slate-500">
|
||||
SFTP와 FTP를 모두 지원하는 프록시 서버 코드 미리보기입니다.
|
||||
</p>
|
||||
<button
|
||||
onClick={handleCopy}
|
||||
className="flex items-center gap-1.5 px-3 py-1.5 bg-blue-600 hover:bg-blue-500 text-white rounded text-xs font-medium transition-colors shadow-sm"
|
||||
>
|
||||
{copied ? <Check size={14} /> : <Copy size={14} />}
|
||||
{copied ? '복사됨' : '코드 복사'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="relative group">
|
||||
<pre className="bg-slate-800 p-4 rounded-lg overflow-x-auto text-xs font-mono text-slate-200 border border-slate-700 leading-relaxed shadow-inner">
|
||||
{backendCodeDisplay}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p className="text-xs text-slate-400 italic text-center">
|
||||
전체 코드는 메인 화면의 '백엔드 다운로드' 버튼을 통해 받으실 수 있습니다.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="p-4 border-t border-slate-200 bg-slate-50 rounded-b-lg flex justify-end">
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user