feat(sql): add folder search and creation to save dialog

This commit is contained in:
lexmin0412 authored and GitHub committed 2026-07-17 17:12:32 +08:00
1 parent bb613b1712
commit 7165ec8911
10 files changed
+200 -18

No files matched your search

@@ -0,0 +1,50 @@
import { readonly, ref } from "vue";
export function useSaveSqlFolderSelection(initialSelection: string) {
const selection = ref(initialSelection);
const pending = ref(false);
let generation = 0;
function reset(value: string) {
generation++;
pending.value = false;
selection.value = value;
}
function invalidate() {
generation++;
pending.value = false;
}
async function select(value: string, create?: () => Promise<string>, onError?: (error: unknown) => void) {
if (pending.value) return;
if (!create) {
selection.value = value;
return;
}
const previousSelection = selection.value;
const requestGeneration = generation;
pending.value = true;
try {
const createdSelection = await create();
// A closed or reopened dialog owns a newer selection session.
if (requestGeneration !== generation) return;
selection.value = createdSelection;
} catch (error) {
if (requestGeneration !== generation) return;
selection.value = previousSelection;
onError?.(error);
} finally {
if (requestGeneration === generation) pending.value = false;
}
}
return {
selection,
pending: readonly(pending),
reset,
invalidate,
select,
};
}