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
|
// WebSocket
|
||||||
const wsRef = useRef<WebSocket | null>(null);
|
const wsRef = useRef<WebSocket | null>(null);
|
||||||
const connectionRef = useRef(connection);
|
const connectionRef = useRef(connection);
|
||||||
|
const localRef = useRef(local);
|
||||||
|
const remoteRef = useRef(remote);
|
||||||
|
|
||||||
// --- Helpers ---
|
// --- Helpers ---
|
||||||
const addLog = useCallback((type: LogEntry['type'], message: string) => {
|
const addLog = useCallback((type: LogEntry['type'], message: string) => {
|
||||||
@@ -101,7 +103,9 @@ const App: React.FC = () => {
|
|||||||
// Sync connection state to ref for WS callbacks
|
// Sync connection state to ref for WS callbacks
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
connectionRef.current = connection;
|
connectionRef.current = connection;
|
||||||
}, [connection]);
|
localRef.current = local;
|
||||||
|
remoteRef.current = remote;
|
||||||
|
}, [connection, local, remote]);
|
||||||
|
|
||||||
// --- WebSocket Setup ---
|
// --- WebSocket Setup ---
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -264,9 +268,9 @@ const App: React.FC = () => {
|
|||||||
case 'success':
|
case 'success':
|
||||||
addLog('success', data.message);
|
addLog('success', data.message);
|
||||||
if (connectionRef.current.connected) {
|
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;
|
break;
|
||||||
|
|
||||||
case 'sites_list':
|
case 'sites_list':
|
||||||
@@ -295,9 +299,9 @@ const App: React.FC = () => {
|
|||||||
addLog('success', data.message);
|
addLog('success', data.message);
|
||||||
// Refresh lists
|
// Refresh lists
|
||||||
if (data.path) {
|
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) {
|
if (connectionRef.current.connected) {
|
||||||
ws?.send(JSON.stringify({ command: 'LIST', path: remote.path }));
|
ws?.send(JSON.stringify({ command: 'LIST', path: remoteRef.current.path }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user