localRef와 remoteRef를 도입하여 WebSocket 명령이 항상 최신 local 및 remote 상태를 사용하도록 합니다.
This commit is contained in:
14
App.tsx
14
App.tsx
@@ -62,6 +62,8 @@ const App: React.FC = () => {
|
||||
// WebSocket
|
||||
const wsRef = useRef<WebSocket | null>(null);
|
||||
const connectionRef = useRef(connection);
|
||||
const localRef = useRef(local);
|
||||
const remoteRef = useRef(remote);
|
||||
|
||||
// --- Helpers ---
|
||||
const addLog = useCallback((type: LogEntry['type'], message: string) => {
|
||||
@@ -101,7 +103,9 @@ const App: React.FC = () => {
|
||||
// Sync connection state to ref for WS callbacks
|
||||
useEffect(() => {
|
||||
connectionRef.current = connection;
|
||||
}, [connection]);
|
||||
localRef.current = local;
|
||||
remoteRef.current = remote;
|
||||
}, [connection, local, remote]);
|
||||
|
||||
// --- WebSocket Setup ---
|
||||
useEffect(() => {
|
||||
@@ -264,9 +268,9 @@ const App: React.FC = () => {
|
||||
case 'success':
|
||||
addLog('success', data.message);
|
||||
if (connectionRef.current.connected) {
|
||||
ws?.send(JSON.stringify({ command: 'LIST', path: remote.path }));
|
||||
ws?.send(JSON.stringify({ command: 'LIST', path: remoteRef.current.path }));
|
||||
}
|
||||
ws?.send(JSON.stringify({ command: 'LOCAL_LIST', path: local.path }));
|
||||
ws?.send(JSON.stringify({ command: 'LOCAL_LIST', path: localRef.current.path }));
|
||||
break;
|
||||
|
||||
case 'sites_list':
|
||||
@@ -295,9 +299,9 @@ const App: React.FC = () => {
|
||||
addLog('success', data.message);
|
||||
// Refresh lists
|
||||
if (data.path) {
|
||||
ws?.send(JSON.stringify({ command: 'LOCAL_LIST', path: local.path }));
|
||||
ws?.send(JSON.stringify({ command: 'LOCAL_LIST', path: localRef.current.path }));
|
||||
if (connectionRef.current.connected) {
|
||||
ws?.send(JSON.stringify({ command: 'LIST', path: remote.path }));
|
||||
ws?.send(JSON.stringify({ command: 'LIST', path: remoteRef.current.path }));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user