From 69c3e490d78cbde24e3211b37e1c396eb48179c7 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sun, 28 Dec 2025 15:54:50 +0100 Subject: [PATCH] Refactor ReviewAttachmentsDialog to use FileAttachment type for improved handling and deletion --- .../Dialogs/ReviewAttachmentsDialog.razor | 16 ++++++------- .../Dialogs/ReviewAttachmentsDialog.razor.cs | 23 ++++++++++--------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/app/MindWork AI Studio/Dialogs/ReviewAttachmentsDialog.razor b/app/MindWork AI Studio/Dialogs/ReviewAttachmentsDialog.razor index 9e8a19f2..3602adf0 100644 --- a/app/MindWork AI Studio/Dialogs/ReviewAttachmentsDialog.razor +++ b/app/MindWork AI Studio/Dialogs/ReviewAttachmentsDialog.razor @@ -18,9 +18,9 @@ @{ var currentFolder = string.Empty; - foreach (var filePath in this.DocumentPaths) + foreach (var fileAttachment in this.DocumentPaths) { - var folderPath = Path.GetDirectoryName(filePath); + var folderPath = Path.GetDirectoryName(fileAttachment.FilePath); if (folderPath != currentFolder) { currentFolder = folderPath; @@ -31,8 +31,8 @@ } - - @if (File.Exists(filePath)) + + @if (fileAttachment.Exists) {
@@ -40,7 +40,7 @@ - @Path.GetFileName(filePath) + @fileAttachment.FileName @@ -51,7 +51,7 @@ Color="Color.Error" Class="ml-2" Style="flex-shrink: 0;" - OnClick="@(() => this.DeleteAttachment(filePath))"/> + OnClick="@(() => this.DeleteAttachment(fileAttachment))"/> @@ -64,7 +64,7 @@ - @Path.GetFileName(filePath) + @fileAttachment.FileName @@ -75,7 +75,7 @@ Color="Color.Error" Class="ml-2" Style="flex-shrink: 0;" - OnClick="@(() => this.DeleteAttachment(filePath))"/> + OnClick="@(() => this.DeleteAttachment(fileAttachment))"/> } diff --git a/app/MindWork AI Studio/Dialogs/ReviewAttachmentsDialog.razor.cs b/app/MindWork AI Studio/Dialogs/ReviewAttachmentsDialog.razor.cs index 64e6bb10..21af5418 100644 --- a/app/MindWork AI Studio/Dialogs/ReviewAttachmentsDialog.razor.cs +++ b/app/MindWork AI Studio/Dialogs/ReviewAttachmentsDialog.razor.cs @@ -1,3 +1,4 @@ +using AIStudio.Chat; using AIStudio.Components; using AIStudio.Tools.PluginSystem; @@ -13,20 +14,20 @@ public partial class ReviewAttachmentsDialog : MSGComponentBase private IMudDialogInstance MudDialog { get; set; } = null!; [Parameter] - public HashSet DocumentPaths { get; set; } = new(); - + public HashSet DocumentPaths { get; set; } = new(); + [Inject] private IDialogService DialogService { get; set; } = null!; - + private void Close() => this.MudDialog.Close(DialogResult.Ok(this.DocumentPaths)); - - public static async Task> OpenDialogAsync(IDialogService dialogService, params HashSet documentPaths) + + public static async Task> OpenDialogAsync(IDialogService dialogService, params HashSet documentPaths) { var dialogParameters = new DialogParameters { - { x => x.DocumentPaths, documentPaths } + { x => x.DocumentPaths, documentPaths } }; - + var dialogReference = await dialogService.ShowAsync(TB("Your attached files"), dialogParameters, DialogOptions.FULLSCREEN); var dialogResult = await dialogReference.Result; if (dialogResult is null || dialogResult.Canceled) @@ -34,13 +35,13 @@ public partial class ReviewAttachmentsDialog : MSGComponentBase if (dialogResult.Data is null) return documentPaths; - - return dialogResult.Data as HashSet ?? documentPaths; + + return dialogResult.Data as HashSet ?? documentPaths; } - private void DeleteAttachment(string filePath) + private void DeleteAttachment(FileAttachment fileAttachment) { - if (this.DocumentPaths.Remove(filePath)) + if (this.DocumentPaths.Remove(fileAttachment)) { this.StateHasChanged(); }