Less agressive target switching

This commit is contained in:
Connor Yoh 2025-07-31 15:28:28 +01:00
parent cd87eb18e8
commit d427bfdb5d

View File

@ -164,19 +164,18 @@ export const useConvertParameters = (): ConvertParametersHook => {
const analyzeFileTypes = (files: Array<{name: string}>) => { const analyzeFileTypes = (files: Array<{name: string}>) => {
if (files.length === 0) { if (files.length === 0) {
// No files - reset to empty state // No files - only reset smart detection, keep user's format choices
setParameters(prev => ({ setParameters(prev => ({
...prev, ...prev,
isSmartDetection: false, isSmartDetection: false,
smartDetectionType: 'none', smartDetectionType: 'none'
fromExtension: '', // Don't reset fromExtension and toExtension - let user keep their choices
toExtension: ''
})); }));
return; return;
} }
if (files.length === 1) { if (files.length === 1) {
// Single file - use regular detection with auto-target selection // Single file - use regular detection with smart target selection
const detectedExt = detectFileExtensionUtil(files[0].name); const detectedExt = detectFileExtensionUtil(files[0].name);
let fromExt = detectedExt; let fromExt = detectedExt;
let availableTargets = detectedExt ? CONVERSION_MATRIX[detectedExt] || [] : []; let availableTargets = detectedExt ? CONVERSION_MATRIX[detectedExt] || [] : [];
@ -188,15 +187,28 @@ export const useConvertParameters = (): ConvertParametersHook => {
availableTargets = CONVERSION_MATRIX['any'] || []; availableTargets = CONVERSION_MATRIX['any'] || [];
} }
const autoTarget = availableTargets.length === 1 ? availableTargets[0] : ''; setParameters(prev => {
// Check if current toExtension is still valid for the new fromExtension
setParameters(prev => ({ const currentToExt = prev.toExtension;
...prev, const isCurrentToExtValid = availableTargets.includes(currentToExt);
isSmartDetection: false,
smartDetectionType: 'none', // Auto-select target only if:
fromExtension: fromExt, // 1. No current target is set, OR
toExtension: autoTarget // 2. Current target is invalid for new source type, OR
})); // 3. There's only one possible target (forced conversion)
let newToExtension = currentToExt;
if (!currentToExt || !isCurrentToExtValid) {
newToExtension = availableTargets.length === 1 ? availableTargets[0] : '';
}
return {
...prev,
isSmartDetection: false,
smartDetectionType: 'none',
fromExtension: fromExt,
toExtension: newToExtension
};
});
return; return;
} }
@ -205,7 +217,7 @@ export const useConvertParameters = (): ConvertParametersHook => {
const uniqueExtensions = [...new Set(extensions)]; const uniqueExtensions = [...new Set(extensions)];
if (uniqueExtensions.length === 1) { if (uniqueExtensions.length === 1) {
// All files are the same type - use regular detection with auto-target selection // All files are the same type - use regular detection with smart target selection
const detectedExt = uniqueExtensions[0]; const detectedExt = uniqueExtensions[0];
let fromExt = detectedExt; let fromExt = detectedExt;
let availableTargets = CONVERSION_MATRIX[detectedExt] || []; let availableTargets = CONVERSION_MATRIX[detectedExt] || [];
@ -216,15 +228,28 @@ export const useConvertParameters = (): ConvertParametersHook => {
availableTargets = CONVERSION_MATRIX['any'] || []; availableTargets = CONVERSION_MATRIX['any'] || [];
} }
const autoTarget = availableTargets.length === 1 ? availableTargets[0] : ''; setParameters(prev => {
// Check if current toExtension is still valid for the new fromExtension
setParameters(prev => ({ const currentToExt = prev.toExtension;
...prev, const isCurrentToExtValid = availableTargets.includes(currentToExt);
isSmartDetection: false,
smartDetectionType: 'none', // Auto-select target only if:
fromExtension: fromExt, // 1. No current target is set, OR
toExtension: autoTarget // 2. Current target is invalid for new source type, OR
})); // 3. There's only one possible target (forced conversion)
let newToExtension = currentToExt;
if (!currentToExt || !isCurrentToExtValid) {
newToExtension = availableTargets.length === 1 ? availableTargets[0] : '';
}
return {
...prev,
isSmartDetection: false,
smartDetectionType: 'none',
fromExtension: fromExt,
toExtension: newToExtension
};
});
} else { } else {
// Mixed file types // Mixed file types
const allImages = uniqueExtensions.every(ext => isImageFormat(ext)); const allImages = uniqueExtensions.every(ext => isImageFormat(ext));