Refactor ReviewAttachmentsDialog to use FileAttachment type for improved handling and deletion

This commit is contained in:
Thorsten Sommer 2025-12-28 15:54:50 +01:00
parent aeed61d635
commit 69c3e490d7
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
2 changed files with 20 additions and 19 deletions

View File

@ -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 @@
</MudText>
</MudStack>
}
@if (File.Exists(filePath))
@if (fileAttachment.Exists)
{
<MudStack Row Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center" Class="ms-3 mb-2">
<div style="min-width: 0; flex: 1; overflow: hidden;">
@ -40,7 +40,7 @@
<span class="d-inline-flex align-items-center" style="overflow: hidden; width: 100%;">
<MudIcon Icon="@Icons.Material.Filled.AttachFile" Class="mr-2" Style="flex-shrink: 0;"/>
<MudText Style="white-space: nowrap;">
@Path.GetFileName(filePath)
@fileAttachment.FileName
</MudText>
</span>
</MudTooltip>
@ -51,7 +51,7 @@
Color="Color.Error"
Class="ml-2"
Style="flex-shrink: 0;"
OnClick="@(() => this.DeleteAttachment(filePath))"/>
OnClick="@(() => this.DeleteAttachment(fileAttachment))"/>
</MudTooltip>
</MudStack>
@ -64,7 +64,7 @@
<span class="d-inline-flex align-items-center" style="overflow: hidden; width: 100%;">
<MudIcon Icon="@Icons.Material.Filled.Report" Color="Color.Error" Class="mr-2" Style="flex-shrink: 0;"/>
<MudText Style="white-space: nowrap;">
<s>@Path.GetFileName(filePath)</s>
<s>@fileAttachment.FileName</s>
</MudText>
</span>
</MudTooltip>
@ -75,7 +75,7 @@
Color="Color.Error"
Class="ml-2"
Style="flex-shrink: 0;"
OnClick="@(() => this.DeleteAttachment(filePath))"/>
OnClick="@(() => this.DeleteAttachment(fileAttachment))"/>
</MudTooltip>
</MudStack>
}

View File

@ -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<string> DocumentPaths { get; set; } = new();
public HashSet<FileAttachment> 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<HashSet<string>> OpenDialogAsync(IDialogService dialogService, params HashSet<string> documentPaths)
public static async Task<HashSet<FileAttachment>> OpenDialogAsync(IDialogService dialogService, params HashSet<FileAttachment> documentPaths)
{
var dialogParameters = new DialogParameters<ReviewAttachmentsDialog>
{
{ x => x.DocumentPaths, documentPaths }
{ x => x.DocumentPaths, documentPaths }
};
var dialogReference = await dialogService.ShowAsync<ReviewAttachmentsDialog>(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<string> ?? documentPaths;
return dialogResult.Data as HashSet<FileAttachment> ?? documentPaths;
}
private void DeleteAttachment(string filePath)
private void DeleteAttachment(FileAttachment fileAttachment)
{
if (this.DocumentPaths.Remove(filePath))
if (this.DocumentPaths.Remove(fileAttachment))
{
this.StateHasChanged();
}