Add AttachmentsDialog into ContentBlockComponent

This commit is contained in:
hart_s3 2025-12-15 16:48:41 +01:00
parent 084e336f75
commit a3deec9e5c
7 changed files with 49 additions and 28 deletions

View File

@ -20,7 +20,8 @@
{ {
<MudTooltip Text="@T("Number of attachments")" Placement="Placement.Bottom"> <MudTooltip Text="@T("Number of attachments")" Placement="Placement.Bottom">
<MudBadge Content="@this.Content.FileAttachments.Count" Color="Color.Primary" Overlap="true" BadgeClass="sources-card-header"> <MudBadge Content="@this.Content.FileAttachments.Count" Color="Color.Primary" Overlap="true" BadgeClass="sources-card-header">
<MudIconButton Icon="@Icons.Material.Filled.AttachFile" /> <MudIconButton Icon="@Icons.Material.Filled.AttachFile"
OnClick="@this.OpenAttachmentsDialog"/>
</MudBadge> </MudBadge>
</MudTooltip> </MudTooltip>
} }

View File

@ -1,4 +1,5 @@
using AIStudio.Components; using AIStudio.Components;
using AIStudio.Dialogs;
using AIStudio.Tools.Services; using AIStudio.Tools.Services;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
@ -188,4 +189,9 @@ public partial class ContentBlockComponent : MSGComponentBase
await this.EditLastUserBlockFunc(this.Content); await this.EditLastUserBlockFunc(this.Content);
} }
private async Task OpenAttachmentsDialog()
{
var result = await ReviewAttachmentsDialog.OpenDialogAsync(this.DialogService, this.Content.FileAttachments.ToHashSet());
this.Content.FileAttachments = result.ToList();
}
} }

View File

@ -13,11 +13,11 @@
Content="@this.DocumentPaths.Count" Content="@this.DocumentPaths.Count"
Color="Color.Primary" Color="Color.Primary"
Overlap="true" Overlap="true"
OnClick="@OpenAttachmentsDialog"> OnClick="@this.OpenAttachmentsDialog">
<MudIconButton <MudIconButton
Icon="@Icons.Material.Filled.AttachFile" Icon="@Icons.Material.Filled.AttachFile"
Color="Color.Default" Color="Color.Default"
OnClick="@AddFilesManually"/> OnClick="@this.AddFilesManually"/>
</MudBadge> </MudBadge>
</MudTooltip> </MudTooltip>
} }
@ -27,7 +27,7 @@
<MudIconButton <MudIconButton
Icon="@Icons.Material.Filled.AttachFile" Icon="@Icons.Material.Filled.AttachFile"
Color="Color.Default" Color="Color.Default"
OnClick="@AddFilesManually"/> OnClick="@this.AddFilesManually"/>
</MudTooltip> </MudTooltip>
} }
</div> </div>

View File

@ -127,14 +127,7 @@ public partial class AttachDocuments : MSGComponentBase
private async Task OpenAttachmentsDialog() private async Task OpenAttachmentsDialog()
{ {
var dialogParameters = new DialogParameters<AttachmentsDialog> this.DocumentPaths = await ReviewAttachmentsDialog.OpenDialogAsync(this.DialogService, this.DocumentPaths);
{
{ "DocumentPaths", this.DocumentPaths }
};
var dialogReference = await this.DialogService.ShowAsync<AttachmentsDialog>("Your Files", dialogParameters, DialogOptions.FULLSCREEN);
var dialogResult = await dialogReference.Result;
if (dialogResult is null || dialogResult.Canceled)
return;
} }
private async Task<bool> IsFileExtensionValid(string selectedFile) private async Task<bool> IsFileExtensionValid(string selectedFile)

View File

@ -1,15 +0,0 @@
using Microsoft.AspNetCore.Components;
namespace AIStudio.Components;
public partial class AttachmentsDialog : MSGComponentBase
{
[CascadingParameter]
private IMudDialogInstance MudDialog { get; set; } = null!;
[Parameter]
public HashSet<string> DocumentPaths { get; set; } = new();
private void Cancel() => this.MudDialog.Cancel();
}

View File

@ -14,6 +14,6 @@
} }
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>
<MudButton OnClick="@this.Cancel">Cancel</MudButton> <MudButton OnClick="@this.Close">Close</MudButton>
</DialogActions> </DialogActions>
</MudDialog> </MudDialog>

View File

@ -0,0 +1,36 @@
using AIStudio.Components;
using Microsoft.AspNetCore.Components;
namespace AIStudio.Dialogs;
public partial class ReviewAttachmentsDialog : MSGComponentBase
{
[CascadingParameter]
private IMudDialogInstance MudDialog { get; set; } = null!;
[Parameter]
public HashSet<string> 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)
{
var dialogParameters = new DialogParameters<ReviewAttachmentsDialog>
{
{ x => x.DocumentPaths, documentPaths }
};
var dialogReference = await dialogService.ShowAsync<ReviewAttachmentsDialog>("Your attached documents", dialogParameters, DialogOptions.FULLSCREEN);
var dialogResult = await dialogReference.Result;
if (dialogResult is null || dialogResult.Canceled)
return documentPaths;
if (dialogResult.Data is null)
return documentPaths;
return dialogResult.Data as HashSet<string> ?? documentPaths;
}
}