From 2c834eb42bf3b93366d1b124e0a60d130972fc9f Mon Sep 17 00:00:00 2001 From: 409 <409dev@protonmail.com> Date: Tue, 29 Jul 2025 22:14:45 +0200 Subject: [PATCH] drag `DirectoryEntry` onto directory to move --- frontend/components/DirectoryEntry.vue | 38 ++++++++++++++++++++- frontend/lib/api/warrens.ts | 46 ++++++++++++++++++++++++++ frontend/pages/warrens/files.vue | 5 ++- 3 files changed, 87 insertions(+), 2 deletions(-) diff --git a/frontend/components/DirectoryEntry.vue b/frontend/components/DirectoryEntry.vue index f222001..a3b27ae 100644 --- a/frontend/components/DirectoryEntry.vue +++ b/frontend/components/DirectoryEntry.vue @@ -10,6 +10,7 @@ import { deleteWarrenDirectory, deleteWarrenFile, fetchFile, + moveFile, } from '~/lib/api/warrens'; import type { DirectoryEntry } from '#shared/types'; @@ -78,6 +79,38 @@ async function onClick() { } } } + +function onDragStart(e: DragEvent) { + if (e.dataTransfer == null) { + return; + } + + e.dataTransfer.setData('application/warren', entry.name); + e.dataTransfer.dropEffect = 'move'; +} + +async function onDrop(e: DragEvent) { + if (e.dataTransfer == null || warrenStore.current == null) { + return; + } + + if (entry.fileType !== 'directory') { + return; + } + + const fileName = e.dataTransfer.getData('application/warren'); + + if (entry.name === fileName) { + return; + } + + await moveFile( + warrenStore.current.warrenId, + warrenStore.current.path, + fileName, + `${warrenStore.current.path}/${entry.name}` + ); +}