- Refactor: decompose BatchPanel (515→289), ConverterWorkspace (314→206), and InputPanel (278→216) into pure utilities, leaf components, and hooks. Behavior-preserving; all 193 unit tests still pass. - Tooling: integrate knip for dead-code analysis (knip.json + npm script + CI step). Remove orphaned useLocalStorage.ts; declare the previously phantom `globals` devDependency. - Feature: scroll-to-top button on the About page (prefers-reduced-motion aware, i18n across all four locales). - Docs: bump to 1.5.0; update CHANGELOG, THIRD-PARTY, ROADMAP (Phase 4 + 5), CONTRIBUTING. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
53 lines
1.9 KiB
TypeScript
53 lines
1.9 KiB
TypeScript
import { useCallback } from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { toast } from '@/components/ui/sonner';
|
|
import type { Direction } from '@/components/converter/DirectionToggle';
|
|
import { getConverter } from '@/converters/registry';
|
|
import type { FormatId } from '@/converters/types';
|
|
import { filterByExtension, getAllowedExtensions } from '@/lib/file-filter';
|
|
import { useTauriDragDrop } from '@/hooks/useTauriDragDrop';
|
|
import { useBatchStore } from '@/stores/batchStore';
|
|
|
|
// Routes a multi-file drop into the batch queue (with format filtering and
|
|
// toasts) and wires the native Tauri drag-drop bridge to the same handler.
|
|
export function useBatchFileRouter(
|
|
format: FormatId,
|
|
direction: Direction,
|
|
onFilesAdded?: () => void,
|
|
): (files: File[]) => void {
|
|
const { t } = useTranslation();
|
|
const addBatchFiles = useBatchStore((s) => s.addFiles);
|
|
|
|
const handleMultiFileDrop = useCallback(
|
|
(files: File[]) => {
|
|
const allowed = getAllowedExtensions(
|
|
direction === 'reverse' ? 'reverse' : 'forward',
|
|
getConverter(format).meta.extension,
|
|
);
|
|
const { valid, wrongFormat } = filterByExtension(files, allowed);
|
|
if (wrongFormat > 0) {
|
|
toast.warning(t('batch.toast.wrong_format', { count: wrongFormat }));
|
|
}
|
|
if (valid.length === 0) return;
|
|
const result = addBatchFiles(valid);
|
|
if (result.added > 0) {
|
|
toast.success(t('batch.toast.added', { count: result.added }));
|
|
onFilesAdded?.();
|
|
}
|
|
if (result.skipped > 0) {
|
|
if (result.reason === 'duplicate') {
|
|
toast.warning(t('batch.toast.duplicate', { count: result.skipped }));
|
|
} else {
|
|
toast.warning(t('batch.toast.skipped', { count: result.skipped, max: 500 }));
|
|
}
|
|
}
|
|
},
|
|
[addBatchFiles, direction, format, t, onFilesAdded],
|
|
);
|
|
|
|
// Native OS drag-drop bridge (no-op outside Tauri).
|
|
useTauriDragDrop(handleMultiFileDrop);
|
|
|
|
return handleMultiFileDrop;
|
|
}
|