mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-02-13 06:01:37 +00:00
Add AttachmentsDialog component
This commit is contained in:
parent
cd9ecacec5
commit
084e336f75
@ -8,15 +8,18 @@
|
||||
}
|
||||
@if (fileInfos.Any())
|
||||
{
|
||||
<MudBadge
|
||||
Content="@this.DocumentPaths.Count"
|
||||
Color="Color.Primary"
|
||||
Overlap="true">
|
||||
<MudIconButton
|
||||
Icon="@Icons.Material.Filled.AttachFile"
|
||||
Color="Color.Default"
|
||||
OnClick="@AddFilesManually"/>
|
||||
</MudBadge>
|
||||
<MudTooltip Text="@T("Click to see your attached files")" Placement="@TOOLBAR_TOOLTIP_PLACEMENT">
|
||||
<MudBadge
|
||||
Content="@this.DocumentPaths.Count"
|
||||
Color="Color.Primary"
|
||||
Overlap="true"
|
||||
OnClick="@OpenAttachmentsDialog">
|
||||
<MudIconButton
|
||||
Icon="@Icons.Material.Filled.AttachFile"
|
||||
Color="Color.Default"
|
||||
OnClick="@AddFilesManually"/>
|
||||
</MudBadge>
|
||||
</MudTooltip>
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using AIStudio.Dialogs;
|
||||
using AIStudio.Tools.PluginSystem;
|
||||
using AIStudio.Tools.Rust;
|
||||
using AIStudio.Tools.Services;
|
||||
|
||||
@ -10,12 +11,24 @@ using DialogOptions = Dialogs.DialogOptions;
|
||||
|
||||
public partial class AttachDocuments : MSGComponentBase
|
||||
{
|
||||
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(ProfileSelection).Namespace, nameof(ProfileSelection));
|
||||
|
||||
[Parameter]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
[Parameter]
|
||||
public bool Disabled { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public string DisabledText { get; set; } = string.Empty;
|
||||
|
||||
private readonly string defaultToolTipText = TB("You can edit your files here");
|
||||
|
||||
[Parameter]
|
||||
public HashSet<string> DocumentPaths { get; set; } = [];
|
||||
|
||||
private string ToolTipText => this.Disabled ? this.DisabledText : this.defaultToolTipText;
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<HashSet<string>> DocumentPathsChanged { get; set; }
|
||||
|
||||
@ -111,6 +124,18 @@ public partial class AttachDocuments : MSGComponentBase
|
||||
await this.DocumentPathsChanged.InvokeAsync(this.DocumentPaths);
|
||||
await this.OnChange(this.DocumentPaths);
|
||||
}
|
||||
|
||||
private async Task OpenAttachmentsDialog()
|
||||
{
|
||||
var dialogParameters = new DialogParameters<AttachmentsDialog>
|
||||
{
|
||||
{ "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)
|
||||
{
|
||||
|
||||
19
app/MindWork AI Studio/Components/AttachmentsDialog.razor
Normal file
19
app/MindWork AI Studio/Components/AttachmentsDialog.razor
Normal file
@ -0,0 +1,19 @@
|
||||
@inherits MSGComponentBase
|
||||
|
||||
<MudDialog>
|
||||
<TitleContent>
|
||||
Your attached files
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
@foreach (var filePath in this.DocumentPaths)
|
||||
{
|
||||
<MudMenuItem
|
||||
Icon="@Icons.Material.Filled.AttachFile"
|
||||
Label="@Path.GetFileName(filePath)">
|
||||
</MudMenuItem>
|
||||
}
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="@this.Cancel">Cancel</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
15
app/MindWork AI Studio/Components/AttachmentsDialog.razor.cs
Normal file
15
app/MindWork AI Studio/Components/AttachmentsDialog.razor.cs
Normal file
@ -0,0 +1,15 @@
|
||||
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();
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user