mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-08-11 17:32:11 +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
|
-- Your security policy
|
||||||
UI_TEXT_CONTENT["AISTUDIO::DIALOGS::DATASOURCELOCALFILEINFODIALOG::T4081226330"] = "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
|
-- Markdown View
|
||||||
UI_TEXT_CONTENT["AISTUDIO::DIALOGS::DOCUMENTCHECKDIALOG::T1373123357"] = "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.")
|
@T("The specified file could not be found. The file have been moved, deleted, renamed, or is otherwise inaccessible.")
|
||||||
</MudAlert>
|
</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)
|
else if (this.loadFailureMessage is not null)
|
||||||
{
|
{
|
||||||
<MudAlert Severity="Severity.Error" Variant="Variant.Filled" Class="my-2">
|
<MudAlert Severity="Severity.Error" Variant="Variant.Filled" Class="my-2">
|
||||||
|
|||||||
@ -25,7 +25,13 @@ public partial class DocumentCheckDialog : MSGComponentBase
|
|||||||
/// Set when reading the file failed, so the dialog shows the reason instead of empty content.
|
/// Set when reading the file failed, so the dialog shows the reason instead of empty content.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private string? loadFailureMessage;
|
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]
|
[Inject]
|
||||||
private RustService RustService { get; init; } = null!;
|
private RustService RustService { get; init; } = null!;
|
||||||
|
|
||||||
@ -35,24 +41,40 @@ public partial class DocumentCheckDialog : MSGComponentBase
|
|||||||
[Inject]
|
[Inject]
|
||||||
private ILogger<DocumentCheckDialog> Logger { get; init; } = null!;
|
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)
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||||
{
|
{
|
||||||
if (firstRender && this.Document is not null)
|
if (firstRender && this.Document is not null)
|
||||||
{
|
{
|
||||||
|
if (!this.isLoadingContent)
|
||||||
|
return;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!this.Document.IsImage)
|
var extraction = await UserFile.LoadFileData(this.Document.FilePath, this.RustService, this.DialogService);
|
||||||
{
|
this.FileContent = extraction.Content;
|
||||||
var extraction = await UserFile.LoadFileData(this.Document.FilePath, this.RustService, this.DialogService);
|
|
||||||
this.FileContent = extraction.Content;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// This dialog exists so the user can check what we hand to the AI. Showing an
|
// This dialog exists so the user can check what we hand to the AI. Showing an
|
||||||
// empty document when reading the file failed would answer that question wrong.
|
// empty document when reading the file failed would answer that question wrong.
|
||||||
//
|
//
|
||||||
if (!extraction.HasUsableContent)
|
if (!extraction.HasUsableContent)
|
||||||
this.loadFailureMessage = extraction.ToUserMessage(this.Document.FileName);
|
this.loadFailureMessage = extraction.ToUserMessage(this.Document.FileName);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -60,8 +82,11 @@ public partial class DocumentCheckDialog : MSGComponentBase
|
|||||||
this.FileContent = string.Empty;
|
this.FileContent = string.Empty;
|
||||||
this.loadFailureMessage = FileExtractionErrorCode.INTERNAL.ToUserMessage(this.Document.FileName);
|
this.loadFailureMessage = FileExtractionErrorCode.INTERNAL.ToUserMessage(this.Document.FileName);
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
this.StateHasChanged();
|
{
|
||||||
|
this.isLoadingContent = false;
|
||||||
|
this.StateHasChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (firstRender)
|
else if (firstRender)
|
||||||
this.Logger.LogWarning("Document check dialog opened without a valid file path.");
|
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
|
-- Your security policy
|
||||||
UI_TEXT_CONTENT["AISTUDIO::DIALOGS::DATASOURCELOCALFILEINFODIALOG::T4081226330"] = "Ihre Sicherheitsrichtlinie"
|
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
|
-- Markdown View
|
||||||
UI_TEXT_CONTENT["AISTUDIO::DIALOGS::DOCUMENTCHECKDIALOG::T1373123357"] = "Markdown-Ansicht"
|
UI_TEXT_CONTENT["AISTUDIO::DIALOGS::DOCUMENTCHECKDIALOG::T1373123357"] = "Markdown-Ansicht"
|
||||||
|
|
||||||
|
|||||||
@ -5304,6 +5304,9 @@ UI_TEXT_CONTENT["AISTUDIO::DIALOGS::DATASOURCELOCALFILEINFODIALOG::T3688254408"]
|
|||||||
-- Your security policy
|
-- Your security policy
|
||||||
UI_TEXT_CONTENT["AISTUDIO::DIALOGS::DATASOURCELOCALFILEINFODIALOG::T4081226330"] = "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
|
-- Markdown View
|
||||||
UI_TEXT_CONTENT["AISTUDIO::DIALOGS::DOCUMENTCHECKDIALOG::T1373123357"] = "Markdown View"
|
UI_TEXT_CONTENT["AISTUDIO::DIALOGS::DOCUMENTCHECKDIALOG::T1373123357"] = "Markdown View"
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user