added a file attachment badge to indicate successful loaded files

This commit is contained in:
krut_ni 2026-07-20 14:03:42 +02:00
parent 647d3ea4ef
commit 15d53b3bba
No known key found for this signature in database
GPG Key ID: A5C0151B4DDB172C
2 changed files with 43 additions and 5 deletions

View File

@ -4,7 +4,7 @@
{ {
<div @onmouseenter="@this.OnMouseEnter" @onmouseleave="@this.OnMouseLeave"> <div @onmouseenter="@this.OnMouseEnter" @onmouseleave="@this.OnMouseLeave">
<MudPaper Outlined="true" Class="@this.dragClass"> <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"> <MudButton StartIcon="@Icons.Material.Filled.Description" OnClick="@(async () => await this.SelectFile())" Variant="Variant.Filled" Disabled="@this.IsUnavailable">
@this.ButtonText @this.ButtonText
</MudButton> </MudButton>
@ -18,6 +18,15 @@
@T("Drop one file here to load its content.") @T("Drop one file here to load its content.")
</MudText> </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> </MudStack>
</MudPaper> </MudPaper>
</div> </div>
@ -29,5 +38,13 @@ else
@this.ButtonText @this.ButtonText
</MudButton> </MudButton>
<MediaTranscriptionStatus Owner="@this.EffectiveImportOwner" TargetId="@this.EffectiveMediaImportTarget.TargetId" Compact="true"/> <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> </MudStack>
} }

View File

@ -75,6 +75,8 @@ public partial class ReadFileContent : MSGComponentBase
private uint numDropAreasAboveThis; private uint numDropAreasAboveThis;
private bool isComponentHovered; private bool isComponentHovered;
private bool isFileDialogOpen; private bool isFileDialogOpen;
private bool hasLoadedFileContent;
private string loadedFileName = string.Empty;
private bool IsCurrentTargetBusy => this.MediaTranscriptionService.GetSnapshot(this.EffectiveImportOwner) is { IsBusy: true } snapshot private bool IsCurrentTargetBusy => this.MediaTranscriptionService.GetSnapshot(this.EffectiveImportOwner) is { IsBusy: true } snapshot
&& snapshot.Target == this.EffectiveMediaImportTarget; && snapshot.Target == this.EffectiveMediaImportTarget;
private bool IsUnavailable => this.Disabled || this.isFileDialogOpen || this.MediaTranscriptionService.IsBusy(this.EffectiveImportOwner); 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) if (delivery is null || delivery.Text is not { } text)
return; 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); this.MediaTranscriptionService.AcknowledgeDelivery(delivery);
} }
@ -294,7 +300,7 @@ public partial class ReadFileContent : MSGComponentBase
try try
{ {
var fileContent = await UserFile.LoadFileData(filePath, this.RustService, this.DialogService); 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); this.Logger.LogInformation("Successfully loaded file content: {FilePath}", filePath);
return true; 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) private async Task<bool> LoadMediaTranscriptAsync(string filePath)
{ {
if (string.IsNullOrWhiteSpace(this.SettingsManager.ConfigurationData.App.UseTranscriptionProvider)) if (string.IsNullOrWhiteSpace(this.SettingsManager.ConfigurationData.App.UseTranscriptionProvider))
@ -342,6 +355,14 @@ public partial class ReadFileContent : MSGComponentBase
this.EffectiveMediaImportTarget); 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 bool CanCatchDroppedFile() => this.numDropAreasAboveThis is 0 && (this.isComponentHovered || this.CatchAllDocuments);
private void SetDragClass() => this.dragClass = $"{DEFAULT_DRAG_CLASS} mud-border-primary border-2"; 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.ClearDragClass();
this.StateHasChanged(); this.StateHasChanged();
} }
} }