mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-08-11 18:32:12 +00:00
added a file attachment badge to indicate successful loaded files
This commit is contained in:
parent
647d3ea4ef
commit
15d53b3bba
@ -4,7 +4,7 @@
|
||||
{
|
||||
<div @onmouseenter="@this.OnMouseEnter" @onmouseleave="@this.OnMouseLeave">
|
||||
<MudPaper Outlined="true" Class="@this.dragClass">
|
||||
<MudStack Row="true" AlignItems="AlignItems.Center" StretchItems="StretchItems.None" Wrap="Wrap.Wrap">
|
||||
<MudStack Row="true" AlignItems="AlignItems.Start" StretchItems="StretchItems.None" Wrap="Wrap.Wrap">
|
||||
<MudButton StartIcon="@Icons.Material.Filled.Description" OnClick="@(async () => await this.SelectFile())" Variant="Variant.Filled" Disabled="@this.IsUnavailable">
|
||||
@this.ButtonText
|
||||
</MudButton>
|
||||
@ -18,6 +18,15 @@
|
||||
@T("Drop one file here to load its content.")
|
||||
</MudText>
|
||||
}
|
||||
<MudSpacer/>
|
||||
@if (this.hasLoadedFileContent)
|
||||
{
|
||||
<MudTooltip Text="@this.FileLoadedTooltip()">
|
||||
<MudBadge Content="1" Color="Color.Success" Overlap="true">
|
||||
<MudIcon Icon="@Icons.Material.Filled.AttachFile" Color="Color.Default"/>
|
||||
</MudBadge>
|
||||
</MudTooltip>
|
||||
}
|
||||
</MudStack>
|
||||
</MudPaper>
|
||||
</div>
|
||||
@ -29,5 +38,13 @@ else
|
||||
@this.ButtonText
|
||||
</MudButton>
|
||||
<MediaTranscriptionStatus Owner="@this.EffectiveImportOwner" TargetId="@this.EffectiveMediaImportTarget.TargetId" Compact="true"/>
|
||||
@if (this.hasLoadedFileContent)
|
||||
{
|
||||
<MudTooltip Text="@this.FileLoadedTooltip()">
|
||||
<MudBadge Icon="@Icons.Material.Filled.Check" Color="Color.Success" Overlap="true" Class="mx-6 my-4">
|
||||
<MudIcon Icon="@Icons.Material.Filled.AttachFile" Color="Color.Default" />
|
||||
</MudBadge>
|
||||
</MudTooltip>
|
||||
}
|
||||
</MudStack>
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,6 +75,8 @@ public partial class ReadFileContent : MSGComponentBase
|
||||
private uint numDropAreasAboveThis;
|
||||
private bool isComponentHovered;
|
||||
private bool isFileDialogOpen;
|
||||
private bool hasLoadedFileContent;
|
||||
private string loadedFileName = string.Empty;
|
||||
private bool IsCurrentTargetBusy => this.MediaTranscriptionService.GetSnapshot(this.EffectiveImportOwner) is { IsBusy: true } snapshot
|
||||
&& snapshot.Target == this.EffectiveMediaImportTarget;
|
||||
private bool IsUnavailable => this.Disabled || this.isFileDialogOpen || this.MediaTranscriptionService.IsBusy(this.EffectiveImportOwner);
|
||||
@ -145,7 +147,11 @@ public partial class ReadFileContent : MSGComponentBase
|
||||
if (delivery is null || delivery.Text is not { } text)
|
||||
return;
|
||||
|
||||
await this.FileContentChanged.InvokeAsync(text);
|
||||
var fileName = this.MediaTranscriptionService.GetSnapshot(this.EffectiveImportOwner) is { Target: var target } snapshot
|
||||
&& target == this.EffectiveMediaImportTarget
|
||||
? snapshot.CurrentFileName
|
||||
: string.Empty;
|
||||
await this.ApplyFileContentAsync(text, fileName);
|
||||
this.MediaTranscriptionService.AcknowledgeDelivery(delivery);
|
||||
}
|
||||
|
||||
@ -294,7 +300,7 @@ public partial class ReadFileContent : MSGComponentBase
|
||||
try
|
||||
{
|
||||
var fileContent = await UserFile.LoadFileData(filePath, this.RustService, this.DialogService);
|
||||
await this.FileContentChanged.InvokeAsync(fileContent);
|
||||
await this.ApplyFileContentAsync(fileContent, filePath);
|
||||
this.Logger.LogInformation("Successfully loaded file content: {FilePath}", filePath);
|
||||
return true;
|
||||
}
|
||||
@ -306,6 +312,13 @@ public partial class ReadFileContent : MSGComponentBase
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ApplyFileContentAsync(string fileContent, string filePath)
|
||||
{
|
||||
await this.FileContentChanged.InvokeAsync(fileContent);
|
||||
this.loadedFileName = Path.GetFileName(filePath);
|
||||
this.hasLoadedFileContent = true;
|
||||
}
|
||||
|
||||
private async Task<bool> LoadMediaTranscriptAsync(string filePath)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(this.SettingsManager.ConfigurationData.App.UseTranscriptionProvider))
|
||||
@ -342,6 +355,14 @@ public partial class ReadFileContent : MSGComponentBase
|
||||
this.EffectiveMediaImportTarget);
|
||||
}
|
||||
|
||||
private string FileLoadedTooltip()
|
||||
{
|
||||
if (!this.hasLoadedFileContent || string.IsNullOrWhiteSpace(this.loadedFileName))
|
||||
return this.T("File content loaded");
|
||||
|
||||
return string.Format(this.T("Attached file '{0}'."), this.loadedFileName);
|
||||
}
|
||||
|
||||
private bool CanCatchDroppedFile() => this.numDropAreasAboveThis is 0 && (this.isComponentHovered || this.CatchAllDocuments);
|
||||
|
||||
private void SetDragClass() => this.dragClass = $"{DEFAULT_DRAG_CLASS} mud-border-primary border-2";
|
||||
@ -369,4 +390,4 @@ public partial class ReadFileContent : MSGComponentBase
|
||||
this.ClearDragClass();
|
||||
this.StateHasChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user