fix: improve web drop handler error handling and preventDefault placement

This commit is contained in:
t8y2 2026-06-11 01:27:16 +08:00
parent 7d2c17559f
commit c8fb749ef6
1 changed files with 4 additions and 2 deletions

View File

@ -108,14 +108,16 @@ export function useFileDrop() {
document.addEventListener("drop", (event: DragEvent) => {
const files = event.dataTransfer?.files;
if (!files || files.length === 0) return;
event.preventDefault();
for (let i = 0; i < files.length; i++) {
const file = files[i];
if (!isSqlFilePath(file.name)) continue;
event.preventDefault();
const reader = new FileReader();
reader.onload = () => {
if (typeof reader.result === "string") {
void openDroppedSqlFile(file.name, reader.result);
openDroppedSqlFile(file.name, reader.result).catch((e: any) => {
toast(t("toolbar.sqlOpenFailed", { message: e?.message || String(e) }), 5000);
});
}
};
reader.readAsText(file);