-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drag & Drop into/out of Spacedrive (#2849)
* Better drag & drop into the os * Update drag.rs * Drag & Drop into Spacedrive from OS * Re-enable Supertokes & change Drag-rs pointer * Autoformat
- Loading branch information
1 parent
b225dcd
commit 645b412
Showing
16 changed files
with
153 additions
and
58 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.