From ebaa70c6881ea067b28abca1fa3c0afea106c175 Mon Sep 17 00:00:00 2001 From: "Robert (Jamie) Munro" Date: Thu, 5 Feb 2026 18:17:38 +0000 Subject: [PATCH] Allow drag and drop on home page --- client/src/scss/styles.scss | 13 ++++ client/src/views/InitialView.jsx | 101 ++++++++++++++++++++++++++++--- 2 files changed, 107 insertions(+), 7 deletions(-) diff --git a/client/src/scss/styles.scss b/client/src/scss/styles.scss index fb54b05..17f7b5e 100644 --- a/client/src/scss/styles.scss +++ b/client/src/scss/styles.scss @@ -108,13 +108,26 @@ body { align-items: center; height: 100vh; + transition: background-color 0.2s ease; + + &.dragging { + background-color: rgba(50, 150, 255, 0.1); + outline: 3px dashed rgba(50, 150, 255, 0.6); + outline-offset: -10px; + } + .initial-hero-content { text-align: center; color: #fff; + pointer-events: none; // Allow drag events to bubble through } a { color: #bbf; text-decoration: underline; + pointer-events: all; // Re-enable pointer events for links + } + button { + pointer-events: all; // Re-enable pointer events for buttons } } diff --git a/client/src/views/InitialView.jsx b/client/src/views/InitialView.jsx index 1fa9de9..572c8f5 100644 --- a/client/src/views/InitialView.jsx +++ b/client/src/views/InitialView.jsx @@ -6,8 +6,84 @@ import ografLogoUrl from '../assets/ograf_logo_colour_draft.svg' import { serviceWorkerHandler } from '../ServiceWorkerHandler' export function InitialView({ onGraphicsFolder }) { + const [isDragging, setIsDragging] = React.useState(false) + const [error, setError] = React.useState(null) + + const handleFolderSelect = React.useCallback( + async (dirHandle) => { + try { + fileHandler.dirHandle = dirHandle + onGraphicsFolder({ + graphicsList: await fileHandler.listGraphics(), + graphicsFolderName: fileHandler.dirHandle.name, + }) + } catch (err) { + console.error(err) + setError(err.message) + } + }, + [onGraphicsFolder] + ) + + const handleDragOver = React.useCallback((e) => { + e.preventDefault() + e.stopPropagation() + setIsDragging(true) + }, []) + + const handleDragEnter = React.useCallback((e) => { + e.preventDefault() + e.stopPropagation() + setIsDragging(true) + }, []) + + const handleDragLeave = React.useCallback((e) => { + e.preventDefault() + e.stopPropagation() + setIsDragging(false) + }, []) + + const handleDrop = React.useCallback( + async (e) => { + e.preventDefault() + e.stopPropagation() + setIsDragging(false) + setError(null) + + try { + // Get the first item from the drop + const items = e.dataTransfer.items + if (items && items.length > 0) { + const item = items[0] + + // Check if the browser supports getAsFileSystemHandle + if (item.getAsFileSystemHandle) { + const handle = await item.getAsFileSystemHandle() + if (handle.kind === 'directory') { + await handleFolderSelect(handle) + } else { + setError('Please drop a folder, not a file') + } + } else { + setError('Drag and drop folders is not supported in this browser. Please use the button instead.') + } + } + } catch (err) { + console.error(err) + setError(err.message || 'Failed to process dropped folder') + } + }, + [handleFolderSelect] + ) + return ( -
+

@@ -38,19 +114,30 @@ export function InitialView({ onGraphicsFolder }) {

-

Start the DevTool by selecting a folder that contains Ograf Graphics in any of its subfolders.

+

+ Start the DevTool by selecting a folder that contains Ograf Graphics in any of its subfolders. +

+

+ Drag and drop a folder here or click the button below: +

+ {error && ( +
+ {error} +
+ )}