mirror of
https://github.com/spacedriveapp/spacedrive
synced 2024-07-08 12:54:05 +00:00
* Backend side * Rust fmt * Removing uneeded duplicate files rspc route * Create folder for ephemeral files * Ephemeral delete files * First draft on copy, cut and delete, still buggy * Fixing copy function and updating async-channel dep * Rename and some fixes
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import { useKey, useKeys } from 'rooks';
|
|
import { useItemsAsEphemeralPaths, useItemsAsFilePaths, type ExplorerItem } from '@sd/client';
|
|
import { dialogManager } from '@sd/ui';
|
|
import DeleteDialog from '~/app/$libraryId/Explorer/FilePath/DeleteDialog';
|
|
import { isNonEmpty } from '~/util';
|
|
|
|
import { useOperatingSystem } from './useOperatingSystem';
|
|
|
|
export const useKeyDeleteFile = (selectedItems: Set<ExplorerItem>, locationId?: number | null) => {
|
|
const os = useOperatingSystem();
|
|
|
|
const filePaths = useItemsAsFilePaths([...selectedItems]);
|
|
const ephemeralPaths = useItemsAsEphemeralPaths([...selectedItems]);
|
|
|
|
const deleteHandler = (e: KeyboardEvent) => {
|
|
e.preventDefault();
|
|
|
|
if ((locationId == null || !isNonEmpty(filePaths)) && !isNonEmpty(ephemeralPaths)) return;
|
|
|
|
const indexedArgs =
|
|
locationId != null && isNonEmpty(filePaths)
|
|
? { locationId, pathIds: filePaths.map((p) => p.id) }
|
|
: undefined;
|
|
const ephemeralArgs = isNonEmpty(ephemeralPaths)
|
|
? { paths: ephemeralPaths.map((p) => p.path) }
|
|
: undefined;
|
|
|
|
let dirCount = 0;
|
|
let fileCount = 0;
|
|
|
|
for (const entry of [...filePaths, ...ephemeralPaths]) {
|
|
dirCount += entry.is_dir ? 1 : 0;
|
|
fileCount += entry.is_dir ? 0 : 1;
|
|
}
|
|
|
|
dialogManager.create((dp) => (
|
|
<DeleteDialog
|
|
{...dp}
|
|
indexedArgs={indexedArgs}
|
|
ephemeralArgs={ephemeralArgs}
|
|
dirCount={dirCount}
|
|
fileCount={fileCount}
|
|
/>
|
|
));
|
|
};
|
|
|
|
useKeys(['Meta', 'Backspace'], (e) => {
|
|
if (os !== 'macOS') return;
|
|
deleteHandler(e);
|
|
});
|
|
|
|
useKey('Delete', (e) => {
|
|
if (os === 'macOS') return;
|
|
deleteHandler(e);
|
|
});
|
|
};
|