feat(sql-library): add move to folder action

This commit is contained in:
t8y2 committed 2026-07-04 00:37:23 +08:00
1 parent 69f880fdf1
commit 614daa5b19
11 files changed
+234 -6

No files matched your search

+37
View File
@@ -453,6 +453,42 @@ export const useSavedSqlStore = defineStore("savedSql", () => {
await persistFiles([...untouched, ...nextSource, ...nextDestination]);
}
async function moveFilesToFolder(fileIds: string[], folderId?: string) {
const uniqueIds = [...new Set(fileIds)];
if (uniqueIds.length === 0) return;
const targetFolderId = folderId || undefined;
const movingFiles = uniqueIds.map((id) => files.value.find((file) => file.id === id)).filter((file): file is SavedSqlFile => Boolean(file));
const filesToMove = movingFiles.filter((file) => (file.folderId || undefined) !== targetFolderId);
if (filesToMove.length === 0) return;
const moveIdSet = new Set(filesToMove.map((file) => file.id));
const timestamp = nowIso();
const affectedFolderIds = new Set<string>(filesToMove.map((file) => file.folderId || ""));
affectedFolderIds.add(targetFolderId || "");
const movedFiles = filesToMove.map((file) => ({
...file,
folderId: targetFolderId,
updatedAt: timestamp,
}));
// Reindex each touched folder separately so moving a batch out of one
// folder never rewrites unrelated siblings into the destination folder.
const nextAffectedFiles = Array.from(affectedFolderIds).flatMap((groupId) => {
const normalizedGroupId = groupId || undefined;
const remaining = sortFilesByOrder(files.value.filter((file) => (file.folderId || "") === groupId && !moveIdSet.has(file.id)));
const group = groupId === (targetFolderId || "") ? [...remaining, ...movedFiles] : remaining;
return reindexFiles(group, normalizedGroupId).map((file) => ({
...file,
updatedAt: timestamp,
}));
});
const untouched = files.value.filter((file) => !affectedFolderIds.has(file.folderId || "") && !moveIdSet.has(file.id));
await persistFiles([...untouched, ...nextAffectedFiles]);
}
async function reorderFiles(draggedId: string, targetId: string, position: "before" | "after") {
const dragged = files.value.find((file) => file.id === draggedId);
const target = files.value.find((file) => file.id === targetId);
@@ -531,6 +567,7 @@ export const useSavedSqlStore = defineStore("savedSql", () => {
moveFolderToFolder,
reorderFiles,
moveFileToFolder,
moveFilesToFolder,
syncToLocalDirectory,
allFolders,
allFoldersTreeOrder,