Files
NetMesh/components/sftp/copyToOtherPane.ts

27 lines
760 B
TypeScript
Raw Normal View History

export type SftpPaneSide = "left" | "right";
type CopyTargetState = {
getActivePane: (side: SftpPaneSide) => {
connection?: { status?: "connecting" | "connected" | "disconnected" | "error" } | null;
reconnecting?: boolean;
} | null | undefined;
};
export const canCopyToOtherPane = (
state: CopyTargetState,
targetSide: SftpPaneSide,
): boolean => {
const targetPane = state.getActivePane(targetSide);
return targetPane?.connection?.status === "connected" && targetPane.reconnecting !== true;
};
export const requireCopyToOtherPaneTarget = (
state: CopyTargetState,
targetSide: SftpPaneSide,
onUnavailable: () => void,
): boolean => {
if (canCopyToOtherPane(state, targetSide)) return true;
onUnavailable();
return false;
};