mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-23 08:31:49 +00:00
Decomposes the core SFTP state management hook and related UI components into smaller, domain-specific custom hooks and specialized sub-components. This refactoring aims to: - Break down the monolithic `useSftpState` hook into focused hooks like `useSftpConnections`, `useSftpTransfers`, and `useSftpPaneActions`. - Extract complex logic and rendering from `SFTPModal` and `SftpView` into dedicated presentational components and custom hooks. - Centralize SFTP-related types and utility functions into new `sftp/types.ts` and `sftp/utils.ts` modules. The changes enhance code organization, maintainability, and testability across the SFTP functionality.
28 lines
872 B
TypeScript
28 lines
872 B
TypeScript
import { useEffect } from "react";
|
|
import { netcattyBridge } from "../../infrastructure/services/netcattyBridge";
|
|
import type { FileWatchErrorEvent, FileWatchSyncedEvent, SftpStateOptions } from "./types";
|
|
|
|
export const useSftpFileWatch = (options?: SftpStateOptions) => {
|
|
useEffect(() => {
|
|
const bridge = netcattyBridge.get();
|
|
if (!bridge?.onFileWatchSynced || !bridge?.onFileWatchError) return;
|
|
|
|
const unsubscribeSynced = bridge.onFileWatchSynced((payload: FileWatchSyncedEvent) => {
|
|
options?.onFileWatchSynced?.(payload);
|
|
});
|
|
|
|
const unsubscribeError = bridge.onFileWatchError((payload: FileWatchErrorEvent) => {
|
|
options?.onFileWatchError?.(payload);
|
|
});
|
|
|
|
return () => {
|
|
try {
|
|
unsubscribeSynced?.();
|
|
unsubscribeError?.();
|
|
} catch {
|
|
// ignore cleanup errors
|
|
}
|
|
};
|
|
}, [options]);
|
|
};
|