From 1f82155b130f5b2d42fe9d68cb79349c4b667a41 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Tue, 28 Oct 2025 09:41:07 +0100 Subject: [PATCH] Enhance drag-and-drop with hover detection and logging --- .../DocumentAnalysisAssistant.razor | 2 +- .../Components/AttachDocuments.razor | 26 +++++------ .../Components/AttachDocuments.razor.cs | 46 ++++++++++++++++--- app/MindWork AI Studio/Tools/EventHandlers.cs | 14 ++++++ 4 files changed, 68 insertions(+), 20 deletions(-) create mode 100644 app/MindWork AI Studio/Tools/EventHandlers.cs diff --git a/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor b/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor index 829dcba2..67bbfaee 100644 --- a/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor +++ b/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor @@ -71,6 +71,6 @@ else - + \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/AttachDocuments.razor b/app/MindWork AI Studio/Components/AttachDocuments.razor index f86d4aa8..f49f38a3 100644 --- a/app/MindWork AI Studio/Components/AttachDocuments.razor +++ b/app/MindWork AI Studio/Components/AttachDocuments.razor @@ -1,15 +1,15 @@ @inherits MSGComponentBase - - - - Drag and drop files here or click to attach documents. - - @foreach (var fileInfo in this.DocumentPaths.Select(file => new FileInfo(file))) - { - - } - - \ No newline at end of file +
+ + + + @T("Drag and drop files here or click to attach documents.") + + @foreach (var fileInfo in this.DocumentPaths.Select(file => new FileInfo(file))) + { + + } + + +
\ No newline at end of file diff --git a/app/MindWork AI Studio/Components/AttachDocuments.razor.cs b/app/MindWork AI Studio/Components/AttachDocuments.razor.cs index 9b446ca9..f8fb79a0 100644 --- a/app/MindWork AI Studio/Components/AttachDocuments.razor.cs +++ b/app/MindWork AI Studio/Components/AttachDocuments.razor.cs @@ -7,6 +7,9 @@ namespace AIStudio.Components; public partial class AttachDocuments : MSGComponentBase { + [Parameter] + public string Name { get; set; } = string.Empty; + [Parameter] public HashSet DocumentPaths { get; set; } = []; @@ -16,6 +19,9 @@ public partial class AttachDocuments : MSGComponentBase [Parameter] public Func, Task> OnChange { get; set; } = _ => Task.CompletedTask; + [Inject] + private ILogger Logger { get; set; } = null!; + [Inject] private RustService RustService { get; init; } = null!; @@ -32,19 +38,29 @@ public partial class AttachDocuments : MSGComponentBase switch (triggeredEvent) { case Event.TAURI_EVENT_RECEIVED when data is TauriEvent { EventType: TauriEventType.FILE_DROP_HOVERED }: + if(!this.isComponentHovered) + { + this.Logger.LogDebug("Attach documents component '{Name}' is not hovered, ignoring file drop hovered event.", this.Name); + return; + } + this.SetDragClass(); + this.StateHasChanged(); break; case Event.TAURI_EVENT_RECEIVED when data is TauriEvent { EventType: TauriEventType.FILE_DROP_DROPPED, Payload: var paths }: - this.ClearDragClass(); + if(!this.isComponentHovered) + { + this.Logger.LogDebug("Attach documents component '{Name}' is not hovered, ignoring file drop dropped event.", this.Name); + return; + } + + #warning Filter unsupported files foreach (var path in paths) this.DocumentPaths.Add(path); await this.DocumentPathsChanged.InvokeAsync(this.DocumentPaths); await this.OnChange(this.DocumentPaths); - break; - - case Event.TAURI_EVENT_RECEIVED when data is TauriEvent { EventType: TauriEventType.FILE_DROP_CANCELED }: - this.ClearDragClass(); + this.StateHasChanged(); break; } } @@ -54,6 +70,8 @@ public partial class AttachDocuments : MSGComponentBase private const string DEFAULT_DRAG_CLASS = "relative rounded-lg border-2 border-dashed pa-4 mt-4 mud-width-full mud-height-full"; private string dragClass = DEFAULT_DRAG_CLASS; + + private bool isComponentHovered; private async Task AddFilesManually() { @@ -82,7 +100,23 @@ public partial class AttachDocuments : MSGComponentBase await this.OnChange(this.DocumentPaths); } - private void SetDragClass() => this.dragClass = $"{DEFAULT_DRAG_CLASS} mud-border-primary"; + private void SetDragClass() => this.dragClass = $"{DEFAULT_DRAG_CLASS} mud-border-primary border-4"; private void ClearDragClass() => this.dragClass = DEFAULT_DRAG_CLASS; + + private void OnMouseEnter(EventArgs _) + { + this.Logger.LogDebug("Attach documents component '{Name}' is hovered.", this.Name); + this.isComponentHovered = true; + this.SetDragClass(); + this.StateHasChanged(); + } + + private void OnMouseLeave(EventArgs _) + { + this.Logger.LogDebug("Attach documents component '{Name}' is no longer hovered.", this.Name); + this.isComponentHovered = false; + this.ClearDragClass(); + this.StateHasChanged(); + } } \ No newline at end of file diff --git a/app/MindWork AI Studio/Tools/EventHandlers.cs b/app/MindWork AI Studio/Tools/EventHandlers.cs new file mode 100644 index 00000000..bc68af6c --- /dev/null +++ b/app/MindWork AI Studio/Tools/EventHandlers.cs @@ -0,0 +1,14 @@ +using Microsoft.AspNetCore.Components; + +namespace AIStudio.Tools; + +/// +/// Add handling for more DOM events to Blazor components. +/// +/// +/// See https://learn.microsoft.com/en-us/aspnet/core/blazor/components/event-handling. It is important +/// that this class is named EventHandlers. +/// +[EventHandler("onmouseenter", typeof(EventArgs), enableStopPropagation: true, enablePreventDefault: true)] +[EventHandler("onmouseleave", typeof(EventArgs), enableStopPropagation: true, enablePreventDefault: true)] +public static class EventHandlers; \ No newline at end of file