MCPcopy Create free account
hub / github.com/error311/FileRise / handleDropOnFolder

Function handleDropOnFolder

public/js/folderManager.js:2257–2454  ·  view source on GitHub ↗
(event, dropFolder)

Source from the content-addressed store, hash-verified

2255 Handle drop (files or folders)
2256----------------------*/
2257function handleDropOnFolder(event, dropFolder) {
2258 event.preventDefault();
2259 event.currentTarget?.classList?.remove("drop-hover");
2260
2261 let dragData = null;
2262 try {
2263 const jsonStr = event.dataTransfer.getData("application/json") || "";
2264 if (jsonStr) dragData = JSON.parse(jsonStr);
2265 } catch (e) {
2266 dragData = null;
2267 }
2268
2269 // --- NEW: folder drag coming from the inline file list (JSON payload) ---
2270 if (dragData && dragData.dragType === 'folder' && dragData.folder) {
2271 const sourceFolder = String(dragData.folder || "").trim();
2272 if (!sourceFolder || sourceFolder === "root") return;
2273 const sourceId = String(dragData.sourceId || dragData.sourceSourceId || '').trim();
2274 const destSourceId = getActiveSourceId();
2275 const crossSource = sourceId && destSourceId && sourceId !== destSourceId;
2276
2277 // prevent moving into self/descendant
2278 if (!crossSource && (dropFolder === sourceFolder || (dropFolder + "/").startsWith(sourceFolder + "/"))) {
2279 showToast(t('invalid_destination'), 4000, 'warning');
2280 return;
2281 }
2282
2283 runTransferJob({
2284 kind: 'folder_move',
2285 payload: {
2286 source: sourceFolder,
2287 destination: dropFolder,
2288 sourceId,
2289 destSourceId
2290 },
2291 progress: {
2292 action: 'Moving',
2293 itemCount: 1,
2294 itemLabel: 'folder',
2295 bytesKnown: false,
2296 indeterminate: true,
2297 source: sourceFolder,
2298 destination: dropFolder
2299 }
2300 })
2301 .then(async () => {
2302 showToast(buildMoveFolderSuccessToast(sourceFolder, dropFolder), 'success');
2303 if (crossSource) {
2304 try {
2305 if (sourceFolder) {
2306 const srcParent = getParentFolder(sourceFolder);
2307 window.dispatchEvent(new CustomEvent('folderStatsInvalidated', {
2308 detail: { folders: [srcParent], sourceId }
2309 }));
2310 }
2311 if (dropFolder) {
2312 window.dispatchEvent(new CustomEvent('folderStatsInvalidated', {
2313 detail: { folders: [dropFolder], sourceId: destSourceId }
2314 }));

Callers 3

breadcrumbDropHandlerFunction · 0.85
makeChildLiFunction · 0.85
loadFolderTreeFunction · 0.85

Calls 9

tFunction · 0.85
runTransferJobFunction · 0.85
getParentFolderFunction · 0.85
loadFileListFunction · 0.85
syncTreeAfterFolderMoveFunction · 0.85
refreshFolderIconFunction · 0.85
getActiveSourceIdFunction · 0.70
showToastFunction · 0.70

Tested by

no test coverage detected