From 2ccefebb44cddd9d578b90a09c5e2f67d0b0665a Mon Sep 17 00:00:00 2001 From: Thomas Steiner Date: Fri, 11 Feb 2022 22:20:36 +0100 Subject: [PATCH] Fix drag and drop example (#357) * Fix drag and drop example Fixes #356 * Update index.bs --- index.bs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/index.bs b/index.bs index a020bec..5955496 100644 --- a/index.bs +++ b/index.bs @@ -1796,20 +1796,19 @@ elem.addEventListener('dragover', (e) => { // Prevent navigation. e.preventDefault(); }); + elem.addEventListener('drop', async (e) => { - // Prevent navigation. e.preventDefault(); - // Process all of the items. - for (const item of e.dataTransfer.items) { - // kind will be 'file' for file/directory entries. - if (item.kind === 'file') { - const entry = await item.getAsFileSystemHandle(); - if (entry.kind === 'file') { - handleFileEntry(entry); - } else if (entry.kind === 'directory') { - handleDirectoryEntry(entry); - } + const fileHandlesPromises = [...e.dataTransfer.items] + .filter(item => item.kind === 'file') + .map(item => item.getAsFileSystemHandle()); + + for await (const handle of fileHandlesPromises) { + if (handle.kind === 'directory') { + console.log(`Directory: ${handle.name}`); + } else { + console.log(`File: ${handle.name}`); } } });