persist request/folder uids after request/folder resequencing and ui updates (#4611)

* move file/folder uids to new paths

* drag file/folder preview ui updates, can item be dropped ui hint check

---------

Co-authored-by: lohit <lohit@usebruno.com>
This commit is contained in:
lohit
2025-05-06 22:20:59 +05:30
committed by GitHub
parent 38c307d6f1
commit 2ee7ce5829
12 changed files with 152 additions and 33 deletions

View File

@@ -341,7 +341,8 @@ const addDirectory = async (win, pathname, collectionUid, collectionPath) => {
collectionUid,
pathname,
name,
seq
seq,
uid: getRequestUid(pathname)
}
};

View File

@@ -25,7 +25,8 @@ const {
sizeInMB,
safeWriteFileSync,
copyPath,
removePath
removePath,
getPaths
} = require('../utils/filesystem');
const { openCollectionDialog } = require('../app/collections');
const { generateUidBasedOnHash, stringifyJson, safeParseJSON, safeStringifyJSON } = require('../utils/common');
@@ -799,8 +800,15 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
ipcMain.handle('renderer:move-item', async (event, { targetDirname, sourcePathname }) => {
try {
if (fs.existsSync(targetDirname)) {
const sourceDirname = path.dirname(sourcePathname);
const pathnamesBefore = await getPaths(sourcePathname);
const pathnamesAfter = pathnamesBefore?.map(p => p?.replace(sourceDirname, targetDirname));
await copyPath(sourcePathname, targetDirname);
await removePath(sourcePathname);
// move the request uids of the previous file/folders to the new file/folder items
pathnamesAfter?.forEach((_, index) => {
moveRequestUid(pathnamesBefore[index], pathnamesAfter[index]);
});
}
} catch (error) {
return Promise.reject(error);

View File

@@ -324,6 +324,25 @@ const removePath = async (source) => {
}
}
// Recursively gets paths.
const getPaths = async (source) => {
let paths = [];
const _getPaths = async (source) => {
const stat = await fsPromises.lstat(source);
paths.push(source);
if (stat.isDirectory()) {
const entries = await fsPromises.readdir(source);
for (const entry of entries) {
const entryPath = path.join(source, entry);
await _getPaths(entryPath);
}
}
}
await _getPaths(source);
return paths;
}
module.exports = {
isValidPathname,
exists,
@@ -352,5 +371,6 @@ module.exports = {
safeWriteFile,
safeWriteFileSync,
copyPath,
removePath
removePath,
getPaths
};