mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-08-11 18:32:12 +00:00
Fixed the file preview showing an empty document while the file was still being read
This commit is contained in:
parent
0eebb164c2
commit
916d27dc22
@ -5302,6 +5302,9 @@ UI_TEXT_CONTENT["AISTUDIO::DIALOGS::DATASOURCELOCALFILEINFODIALOG::T3688254408"]
|
||||
-- Your security policy
|
||||
UI_TEXT_CONTENT["AISTUDIO::DIALOGS::DATASOURCELOCALFILEINFODIALOG::T4081226330"] = "Your security policy"
|
||||
|
||||
-- Please wait while we load the content of your file. Depending on the file type and size, this may take a moment.
|
||||
UI_TEXT_CONTENT["AISTUDIO::DIALOGS::DOCUMENTCHECKDIALOG::T1205126512"] = "Please wait while we load the content of your file. Depending on the file type and size, this may take a moment."
|
||||
|
||||
-- Markdown View
|
||||
UI_TEXT_CONTENT["AISTUDIO::DIALOGS::DOCUMENTCHECKDIALOG::T1373123357"] = "Markdown View"
|
||||
|
||||
|
||||
@ -33,6 +33,16 @@
|
||||
@T("The specified file could not be found. The file have been moved, deleted, renamed, or is otherwise inaccessible.")
|
||||
</MudAlert>
|
||||
}
|
||||
else if (this.isLoadingContent)
|
||||
{
|
||||
<MudJustifiedText Typo="Typo.body1" Class="my-3">
|
||||
@T("Please wait while we load the content of your file. Depending on the file type and size, this may take a moment.")
|
||||
</MudJustifiedText>
|
||||
<MudSkeleton Width="30%" Height="42px"/>
|
||||
<MudSkeleton Width="80%"/>
|
||||
<MudSkeleton Width="100%"/>
|
||||
<MudSkeleton Width="90%"/>
|
||||
}
|
||||
else if (this.loadFailureMessage is not null)
|
||||
{
|
||||
<MudAlert Severity="Severity.Error" Variant="Variant.Filled" Class="my-2">
|
||||
|
||||
@ -26,6 +26,12 @@ public partial class DocumentCheckDialog : MSGComponentBase
|
||||
/// </summary>
|
||||
private string? loadFailureMessage;
|
||||
|
||||
/// <summary>
|
||||
/// True while we extract the file content. Reading happens after the first render, so the
|
||||
/// dialog can tell the user that it is working instead of showing an empty document.
|
||||
/// </summary>
|
||||
private bool isLoadingContent;
|
||||
|
||||
[Inject]
|
||||
private RustService RustService { get; init; } = null!;
|
||||
|
||||
@ -35,13 +41,30 @@ public partial class DocumentCheckDialog : MSGComponentBase
|
||||
[Inject]
|
||||
private ILogger<DocumentCheckDialog> Logger { get; init; } = null!;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
//
|
||||
// Decide before the first render whether we have to read the file at all. Images are shown
|
||||
// as they are, a missing file shows its own message, and content a caller already handed
|
||||
// us is reused instead of being extracted a second time:
|
||||
//
|
||||
this.isLoadingContent =
|
||||
this.Document is not null &&
|
||||
!this.Document.IsImage &&
|
||||
this.Document.Exists &&
|
||||
string.IsNullOrWhiteSpace(this.FileContent);
|
||||
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender && this.Document is not null)
|
||||
{
|
||||
if (!this.isLoadingContent)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
if (!this.Document.IsImage)
|
||||
{
|
||||
var extraction = await UserFile.LoadFileData(this.Document.FilePath, this.RustService, this.DialogService);
|
||||
this.FileContent = extraction.Content;
|
||||
@ -53,16 +76,18 @@ public partial class DocumentCheckDialog : MSGComponentBase
|
||||
if (!extraction.HasUsableContent)
|
||||
this.loadFailureMessage = extraction.ToUserMessage(this.Document.FileName);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Logger.LogError(ex, "Failed to load file content from '{FilePath}'", this.Document);
|
||||
this.FileContent = string.Empty;
|
||||
this.loadFailureMessage = FileExtractionErrorCode.INTERNAL.ToUserMessage(this.Document.FileName);
|
||||
}
|
||||
|
||||
finally
|
||||
{
|
||||
this.isLoadingContent = false;
|
||||
this.StateHasChanged();
|
||||
}
|
||||
}
|
||||
else if (firstRender)
|
||||
this.Logger.LogWarning("Document check dialog opened without a valid file path.");
|
||||
}
|
||||
|
||||
@ -5304,6 +5304,9 @@ UI_TEXT_CONTENT["AISTUDIO::DIALOGS::DATASOURCELOCALFILEINFODIALOG::T3688254408"]
|
||||
-- Your security policy
|
||||
UI_TEXT_CONTENT["AISTUDIO::DIALOGS::DATASOURCELOCALFILEINFODIALOG::T4081226330"] = "Ihre Sicherheitsrichtlinie"
|
||||
|
||||
-- Please wait while we load the content of your file. Depending on the file type and size, this may take a moment.
|
||||
UI_TEXT_CONTENT["AISTUDIO::DIALOGS::DOCUMENTCHECKDIALOG::T1205126512"] = "Bitte warten Sie, während wir den Inhalt Ihrer Datei laden. Je nach Dateityp und -größe kann dies einen Moment dauern."
|
||||
|
||||
-- Markdown View
|
||||
UI_TEXT_CONTENT["AISTUDIO::DIALOGS::DOCUMENTCHECKDIALOG::T1373123357"] = "Markdown-Ansicht"
|
||||
|
||||
|
||||
@ -5304,6 +5304,9 @@ UI_TEXT_CONTENT["AISTUDIO::DIALOGS::DATASOURCELOCALFILEINFODIALOG::T3688254408"]
|
||||
-- Your security policy
|
||||
UI_TEXT_CONTENT["AISTUDIO::DIALOGS::DATASOURCELOCALFILEINFODIALOG::T4081226330"] = "Your security policy"
|
||||
|
||||
-- Please wait while we load the content of your file. Depending on the file type and size, this may take a moment.
|
||||
UI_TEXT_CONTENT["AISTUDIO::DIALOGS::DOCUMENTCHECKDIALOG::T1205126512"] = "Please wait while we load the content of your file. Depending on the file type and size, this may take a moment."
|
||||
|
||||
-- Markdown View
|
||||
UI_TEXT_CONTENT["AISTUDIO::DIALOGS::DOCUMENTCHECKDIALOG::T1373123357"] = "Markdown View"
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user