mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-08-26 14:19:24 +00:00
Enforce at least two files selected for merge
This commit is contained in:
parent
47c9110139
commit
e69e489af9
@ -5,17 +5,19 @@ import { useTranslation } from "react-i18next";
|
|||||||
export interface FileStatusIndicatorProps {
|
export interface FileStatusIndicatorProps {
|
||||||
selectedFiles?: File[];
|
selectedFiles?: File[];
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
|
minFiles?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const FileStatusIndicator = ({
|
const FileStatusIndicator = ({
|
||||||
selectedFiles = [],
|
selectedFiles = [],
|
||||||
placeholder,
|
placeholder,
|
||||||
|
minFiles = 1,
|
||||||
}: FileStatusIndicatorProps) => {
|
}: FileStatusIndicatorProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const defaultPlaceholder = placeholder || t("files.placeholder", "Select a PDF file in the main view to get started");
|
const defaultPlaceholder = placeholder || t("files.placeholder", "Select a PDF file in the main view to get started");
|
||||||
|
|
||||||
// Only show content when no files are selected
|
// Only show content when no files are selected
|
||||||
if (selectedFiles.length === 0) {
|
if (selectedFiles.length < minFiles) {
|
||||||
return (
|
return (
|
||||||
<Text size="sm" c="dimmed">
|
<Text size="sm" c="dimmed">
|
||||||
{defaultPlaceholder}
|
{defaultPlaceholder}
|
||||||
|
@ -7,6 +7,7 @@ export interface FilesToolStepProps {
|
|||||||
isCollapsed?: boolean;
|
isCollapsed?: boolean;
|
||||||
onCollapsedClick?: () => void;
|
onCollapsedClick?: () => void;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
|
minFiles?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createFilesToolStep(
|
export function createFilesToolStep(
|
||||||
@ -23,6 +24,7 @@ export function createFilesToolStep(
|
|||||||
<FileStatusIndicator
|
<FileStatusIndicator
|
||||||
selectedFiles={props.selectedFiles}
|
selectedFiles={props.selectedFiles}
|
||||||
placeholder={props.placeholder || t("files.placeholder", "Select a PDF file in the main view to get started")}
|
placeholder={props.placeholder || t("files.placeholder", "Select a PDF file in the main view to get started")}
|
||||||
|
minFiles={props.minFiles}
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ export interface FilesStepConfig {
|
|||||||
selectedFiles: File[];
|
selectedFiles: File[];
|
||||||
isCollapsed?: boolean;
|
isCollapsed?: boolean;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
|
minFiles?: number;
|
||||||
onCollapsedClick?: () => void;
|
onCollapsedClick?: () => void;
|
||||||
isVisible?: boolean;
|
isVisible?: boolean;
|
||||||
}
|
}
|
||||||
@ -68,6 +69,7 @@ export function createToolFlow(config: ToolFlowConfig) {
|
|||||||
selectedFiles: config.files.selectedFiles,
|
selectedFiles: config.files.selectedFiles,
|
||||||
isCollapsed: config.files.isCollapsed,
|
isCollapsed: config.files.isCollapsed,
|
||||||
placeholder: config.files.placeholder,
|
placeholder: config.files.placeholder,
|
||||||
|
minFiles: config.files.minFiles,
|
||||||
onCollapsedClick: config.files.onCollapsedClick
|
onCollapsedClick: config.files.onCollapsedClick
|
||||||
})}
|
})}
|
||||||
|
|
||||||
|
@ -75,7 +75,8 @@ const Merge = ({ onPreviewFile, onComplete, onError }: BaseToolProps) => {
|
|||||||
}) as any /* FIX ME: Parameter type is wrong on setSelectedFiles */);
|
}) as any /* FIX ME: Parameter type is wrong on setSelectedFiles */);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const hasFiles = selectedFiles.length > 1; // Merge requires at least 2 files
|
const minFiles = 2; // Merging one file doesn't make sense
|
||||||
|
const hasFiles = selectedFiles.length >= minFiles;
|
||||||
const hasResults = mergeOperation.files.length > 0 || mergeOperation.downloadUrl !== null;
|
const hasResults = mergeOperation.files.length > 0 || mergeOperation.downloadUrl !== null;
|
||||||
const settingsCollapsed = !hasFiles || hasResults;
|
const settingsCollapsed = !hasFiles || hasResults;
|
||||||
|
|
||||||
@ -84,6 +85,7 @@ const Merge = ({ onPreviewFile, onComplete, onError }: BaseToolProps) => {
|
|||||||
selectedFiles,
|
selectedFiles,
|
||||||
isCollapsed: hasFiles && !hasResults,
|
isCollapsed: hasFiles && !hasResults,
|
||||||
placeholder: "Select multiple PDF files to merge",
|
placeholder: "Select multiple PDF files to merge",
|
||||||
|
minFiles: minFiles,
|
||||||
},
|
},
|
||||||
steps: [
|
steps: [
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user