mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-02-20 15:43:58 -05:00
* Better drag & drop into the os * Update drag.rs * Drag & Drop into Spacedrive from OS * Re-enable Supertokes & change Drag-rs pointer * Autoformat
45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import { useEffect } from 'react';
|
|
import { useLocation, useNavigate } from 'react-router';
|
|
import { libraryClient } from '@sd/client';
|
|
import { getPathIdsPerLocation, useExplorerSearchParams } from '~/app/$libraryId/Explorer/util';
|
|
import { isNonEmptyObject } from '~/util';
|
|
import { FileDropEvent } from '~/util/events';
|
|
|
|
import { useQuickRescan } from './useQuickRescan';
|
|
|
|
export const useFileDropEventHandler = (libraryId?: string) => {
|
|
const navigate = useNavigate();
|
|
const rescan = useQuickRescan();
|
|
const regex = new RegExp(
|
|
'/[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}/location/'
|
|
);
|
|
const id = parseInt(useLocation().pathname.replace(regex, ''));
|
|
const [{ path }] = useExplorerSearchParams();
|
|
|
|
useEffect(() => {
|
|
const handler = async (e: FileDropEvent) => {
|
|
e.preventDefault();
|
|
const paths = e.detail.paths;
|
|
|
|
if (libraryId && path) {
|
|
libraryClient.mutation([
|
|
'ephemeralFiles.cutFiles',
|
|
{ sources: paths, target_dir: path! }
|
|
]);
|
|
} else if (libraryId) {
|
|
// Get Materialized Path using the location id
|
|
const locationId = id;
|
|
const location = await libraryClient.query(['locations.get', locationId]);
|
|
const locationPath = location!.path;
|
|
libraryClient.mutation([
|
|
'ephemeralFiles.cutFiles',
|
|
{ sources: paths, target_dir: locationPath! }
|
|
]);
|
|
}
|
|
};
|
|
|
|
document.addEventListener('filedrop', handler);
|
|
return () => document.removeEventListener('filedrop', handler);
|
|
}, [navigate, libraryId, rescan, id, path]);
|
|
};
|